Skip to content

Commit f342034

Browse files
committed
Revert "test: avoid data race"
This reverts commit f372969.
1 parent f372969 commit f342034

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

modules/globallock/locker_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ func TestLocker(t *testing.T) {
2929
oldExpiry := redisLockExpiry
3030
redisLockExpiry = 5 * time.Second // make it shorter for testing
3131
defer func() {
32+
// Avoid data race.
33+
// The startExtend goroutine may still be running and reading redisLockExpiry.
34+
// Wait for a while since it will be stopped soon after Close is called.
35+
time.Sleep(time.Second)
36+
3237
redisLockExpiry = oldExpiry
3338
}()
3439

modules/globallock/redis_locker.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ var redisLockExpiry = 30 * time.Second
2626
type redisLocker struct {
2727
rs *redsync.Redsync
2828

29-
mutexM sync.Map
30-
closed atomic.Bool
31-
extendWg sync.WaitGroup
29+
mutexM sync.Map
30+
closed atomic.Bool
3231
}
3332

3433
var _ Locker = &redisLocker{}
@@ -41,8 +40,6 @@ func NewRedisLocker(connection string) Locker {
4140
),
4241
),
4342
}
44-
45-
l.extendWg.Add(1)
4643
l.startExtend()
4744

4845
return l
@@ -71,7 +68,6 @@ func (l *redisLocker) TryLock(ctx context.Context, key string) (bool, context.Co
7168
// But it's useful in tests to release resources.
7269
func (l *redisLocker) Close() error {
7370
l.closed.Store(true)
74-
l.extendWg.Wait()
7571
return nil
7672
}
7773

@@ -123,7 +119,6 @@ func (l *redisLocker) lock(ctx context.Context, key string, tries int) (context.
123119

124120
func (l *redisLocker) startExtend() {
125121
if l.closed.Load() {
126-
l.extendWg.Done()
127122
return
128123
}
129124

0 commit comments

Comments
 (0)