Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

Commit

Permalink
spanner: fix races in tests
Browse files Browse the repository at this point in the history
Some reads of sessionPool state were not protected by a mutex.

Change-Id: I82881dd2cd01e6af40ba85a380f2720453ed76b1
Reviewed-on: https://code-review.googlesource.com/15350
Reviewed-by: kokoro <[email protected]>
Reviewed-by: Sarah Adams <[email protected]>
  • Loading branch information
jba committed Aug 1, 2017
1 parent 5d5065e commit 2aa3b3d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spanner/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ func TestStressSessionPool(t *testing.T) {
}
idleSessions[s.getID()] = true
}
sp.mu.Lock()
if int(sp.numOpened) != len(idleSessions) {
t.Errorf("%v: number of opened sessions (%v) != number of idle sessions (%v)", ti, sp.numOpened, len(idleSessions))
}
Expand All @@ -819,6 +820,8 @@ func TestStressSessionPool(t *testing.T) {
}
hcSessions[s.getID()] = true
}
sp.mu.Unlock()

// Verify that idleSessions == hcSessions == mockSessions.
if !reflect.DeepEqual(idleSessions, hcSessions) {
t.Errorf("%v: sessions in idle list (%v) != sessions in healthcheck queue (%v)", ti, idleSessions, hcSessions)
Expand Down Expand Up @@ -853,9 +856,11 @@ func TestMaintainer(t *testing.T) {
defer cancel()

<-time.After(sampleInterval * 1)
sp.mu.Lock()
if sp.numOpened != 5 {
t.Errorf("Replenish. Expect %d open, got %d", sp.MinOpened, sp.numOpened)
}
sp.mu.Unlock()

// To save test time, we are not creating many sessions, because the time to create sessions will have impact on the decision on sessionsToKeep. We also parallelize the take and recycle process.
shs := make([]*sessionHandle, 10)
Expand Down

0 comments on commit 2aa3b3d

Please sign in to comment.