Skip to content

Commit 452f3b7

Browse files
committed
Fix race condition in test
1 parent a54816b commit 452f3b7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

memstore/memstore_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,21 @@ func TestDelete(t *testing.T) {
111111
func TestCleanupInterval(t *testing.T) {
112112
m := NewWithCleanupInterval(100 * time.Millisecond)
113113
defer m.StopCleanup()
114+
m.mu.Lock()
114115
m.items["session_token"] = item{object: []byte("encoded_data"), expiration: time.Now().Add(500 * time.Millisecond).UnixNano()}
116+
m.mu.Unlock()
115117

118+
m.mu.Lock()
116119
_, ok := m.items["session_token"]
120+
m.mu.Unlock()
117121
if !ok {
118122
t.Fatalf("got %v: expected %v", ok, true)
119123
}
120124

121125
time.Sleep(time.Second)
126+
m.mu.Lock()
122127
_, ok = m.items["session_token"]
128+
m.mu.Unlock()
123129
if ok {
124130
t.Fatalf("got %v: expected %v", ok, false)
125131
}

0 commit comments

Comments
 (0)