move to go1.24 (#21114)

This commit is contained in:
Harshavardhana
2025-04-09 07:28:39 -07:00
committed by GitHub
parent a6258668a6
commit 2b34e5b9ae
74 changed files with 434 additions and 458 deletions
+18 -18
View File
@@ -33,14 +33,14 @@ const (
func testSimpleWriteLock(t *testing.T, duration time.Duration) (locked bool) {
drwm1 := NewDRWMutex(ds, "simplelock")
ctx1, cancel1 := context.WithCancel(context.Background())
ctx1, cancel1 := context.WithCancel(t.Context())
if !drwm1.GetRLock(ctx1, cancel1, id, source, Options{Timeout: time.Second}) {
panic("Failed to acquire read lock")
}
// fmt.Println("1st read lock acquired, waiting...")
drwm2 := NewDRWMutex(ds, "simplelock")
ctx2, cancel2 := context.WithCancel(context.Background())
ctx2, cancel2 := context.WithCancel(t.Context())
if !drwm2.GetRLock(ctx2, cancel2, id, source, Options{Timeout: time.Second}) {
panic("Failed to acquire read lock")
}
@@ -48,25 +48,25 @@ func testSimpleWriteLock(t *testing.T, duration time.Duration) (locked bool) {
go func() {
time.Sleep(2 * testDrwMutexAcquireTimeout)
drwm1.RUnlock(context.Background())
drwm1.RUnlock(t.Context())
// fmt.Println("1st read lock released, waiting...")
}()
go func() {
time.Sleep(3 * testDrwMutexAcquireTimeout)
drwm2.RUnlock(context.Background())
drwm2.RUnlock(t.Context())
// fmt.Println("2nd read lock released, waiting...")
}()
drwm3 := NewDRWMutex(ds, "simplelock")
// fmt.Println("Trying to acquire write lock, waiting...")
ctx3, cancel3 := context.WithCancel(context.Background())
ctx3, cancel3 := context.WithCancel(t.Context())
locked = drwm3.GetLock(ctx3, cancel3, id, source, Options{Timeout: duration})
if locked {
// fmt.Println("Write lock acquired, waiting...")
time.Sleep(testDrwMutexAcquireTimeout)
drwm3.Unlock(context.Background())
drwm3.Unlock(t.Context())
}
// fmt.Println("Write lock failed due to timeout")
return
@@ -94,26 +94,26 @@ func testDualWriteLock(t *testing.T, duration time.Duration) (locked bool) {
drwm1 := NewDRWMutex(ds, "duallock")
// fmt.Println("Getting initial write lock")
ctx1, cancel1 := context.WithCancel(context.Background())
ctx1, cancel1 := context.WithCancel(t.Context())
if !drwm1.GetLock(ctx1, cancel1, id, source, Options{Timeout: time.Second}) {
panic("Failed to acquire initial write lock")
}
go func() {
time.Sleep(3 * testDrwMutexAcquireTimeout)
drwm1.Unlock(context.Background())
drwm1.Unlock(t.Context())
// fmt.Println("Initial write lock released, waiting...")
}()
// fmt.Println("Trying to acquire 2nd write lock, waiting...")
drwm2 := NewDRWMutex(ds, "duallock")
ctx2, cancel2 := context.WithCancel(context.Background())
ctx2, cancel2 := context.WithCancel(t.Context())
locked = drwm2.GetLock(ctx2, cancel2, id, source, Options{Timeout: duration})
if locked {
// fmt.Println("2nd write lock acquired, waiting...")
time.Sleep(testDrwMutexAcquireTimeout)
drwm2.Unlock(context.Background())
drwm2.Unlock(t.Context())
}
// fmt.Println("2nd write lock failed due to timeout")
return
@@ -268,7 +268,7 @@ func TestUnlockPanic(t *testing.T) {
}
}()
mu := NewDRWMutex(ds, "test")
mu.Unlock(context.Background())
mu.Unlock(t.Context())
}
// Borrowed from rwmutex_test.go
@@ -278,10 +278,10 @@ func TestUnlockPanic2(t *testing.T) {
if recover() == nil {
t.Fatalf("unlock of unlocked RWMutex did not panic")
}
mu.RUnlock(context.Background()) // Unlock, so -test.count > 1 works
mu.RUnlock(t.Context()) // Unlock, so -test.count > 1 works
}()
mu.RLock(id, source)
mu.Unlock(context.Background())
mu.Unlock(t.Context())
}
// Borrowed from rwmutex_test.go
@@ -292,7 +292,7 @@ func TestRUnlockPanic(t *testing.T) {
}
}()
mu := NewDRWMutex(ds, "test")
mu.RUnlock(context.Background())
mu.RUnlock(t.Context())
}
// Borrowed from rwmutex_test.go
@@ -302,10 +302,10 @@ func TestRUnlockPanic2(t *testing.T) {
if recover() == nil {
t.Fatalf("read unlock of unlocked RWMutex did not panic")
}
mu.Unlock(context.Background()) // Unlock, so -test.count > 1 works
mu.Unlock(t.Context()) // Unlock, so -test.count > 1 works
}()
mu.Lock(id, source)
mu.RUnlock(context.Background())
mu.RUnlock(t.Context())
}
// Borrowed from rwmutex_test.go
@@ -320,14 +320,14 @@ func benchmarkRWMutex(b *testing.B, localWork, writeRatio int) {
foo++
if foo%writeRatio == 0 {
rwm.Lock(id, source)
rwm.Unlock(context.Background())
rwm.Unlock(b.Context())
} else {
rwm.RLock(id, source)
for i := 0; i != localWork; i++ {
foo *= 2
foo /= 2
}
rwm.RUnlock(context.Background())
rwm.RUnlock(b.Context())
}
}
_ = foo