Skip to content

Commit

Permalink
test(spanner): fix flaky TestMaintainer test (#3237)
Browse files Browse the repository at this point in the history
* test(spanner): fix flaky TestMaintainer test

Fixes #3230

* docs: clearify comment
  • Loading branch information
olavloite committed Nov 20, 2020
1 parent fa77efa commit cf30830
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions spanner/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ func TestMaintainer(t *testing.T) {
waitFor(t, func() error {
sp.mu.Lock()
defer sp.mu.Unlock()
if sp.numOpened != 5 {
if sp.numOpened != minOpened {
return fmt.Errorf("Replenish. Expect %d open, got %d", sp.MinOpened, sp.numOpened)
}
return nil
Expand All @@ -1574,12 +1574,22 @@ func TestMaintainer(t *testing.T) {
t.Fatalf("cannot get session from session pool: %v", err)
}
}
sp.mu.Lock()
g, w := sp.numOpened, sp.MinOpened+sp.incStep
sp.mu.Unlock()
if g != w {
t.Fatalf("numOpened sessions mismatch\nGot: %d\nWant: %d", g, w)
}
// Wait for all sessions to be added to the pool.
// The pool already contained 5 sessions (MinOpened=5).
// The test took 20 sessions from the pool. That initiated the creation of
// additional sessions, and that is done in batches of 25 sessions, so the
// pool should contain 30 sessions (with 20 currently checked out). It
// could take a couple of milliseconds before all sessions have been
// created and added to the pool.
waitFor(t, func() error {
sp.mu.Lock()
defer sp.mu.Unlock()
g, w := sp.numOpened, sp.MinOpened+sp.incStep
if g != w {
return fmt.Errorf("numOpened sessions mismatch\nGot: %d\nWant: %d", g, w)
}
return nil
})

// Return 14 sessions to the pool. There are still 6 sessions checked out.
for _, sh := range shs[:14] {
Expand Down

0 comments on commit cf30830

Please sign in to comment.