aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2023-06-09 14:33:07 +0200
committerJakob Unterwurzacher2023-06-09 14:33:07 +0200
commit5ae35e904ab7b536a8c8c8a05cd8c69953b3b093 (patch)
treee6dc12765bffc359b18581ddbc44794657c00590
parent1b4dc795bd0060bd64992f1355cbf197e0a20172 (diff)
tests/cluster: add TestPoCTornWriteLocked
-rw-r--r--tests/cluster/poc_test.go25
1 files changed, 23 insertions, 2 deletions
diff --git a/tests/cluster/poc_test.go b/tests/cluster/poc_test.go
index 811ffea..a275aa9 100644
--- a/tests/cluster/poc_test.go
+++ b/tests/cluster/poc_test.go
@@ -147,12 +147,20 @@ func TestPoCHeaderCreation(t *testing.T) {
//
// Passes on XFS.
func TestPoCTornWrite(t *testing.T) {
- if os.Getenv("ENABLE_CLUSTER_TEST") != "1" {
+ if os.Getenv("ASSUME_XFS") != "1" {
t.Skipf("This test is disabled by default because it fails unless on XFS.\n" +
- "Run it like this: ENABLE_CLUSTER_TEST=1 go test\n" +
+ "Run it like this: ASSUME_XFS=1 go test -run TestPoCTornWrite\n" +
"Choose a backing directory by setting TMPDIR.")
}
+ doTestPoCTornWrite(t, false)
+}
+
+// Same as TestPoCTornWrite but uses fcntl byte range locks
+func TestPoCTornWriteLocked(t *testing.T) {
+ doTestPoCTornWrite(t, true)
+}
+func doTestPoCTornWrite(t *testing.T, locking bool) {
path := test_helpers.TmpDir + "/" + t.Name()
var wg sync.WaitGroup
const loops = 10000
@@ -172,6 +180,19 @@ func TestPoCTornWrite(t *testing.T) {
// Write
blockData := bytes.Repeat([]byte{byte(i)}, 42)
+ if locking {
+ lk := unix.Flock_t{
+ Type: unix.F_WRLCK,
+ Whence: unix.SEEK_SET,
+ Start: 0,
+ Len: int64(len(blockData)),
+ }
+ if err := unix.FcntlFlock(uintptr(f.Fd()), unix.F_OFD_SETLKW, &lk); err != nil {
+ t.Error(err)
+ return
+ }
+ // No need to unlock, lock is implicitely dropped on fd close
+ }
if _, err = f.WriteAt(blockData, 0); err != nil {
t.Errorf("iteration %d: WriteAt: %v", i, err)
return