Skip to content

Commit

Permalink
reworked TestOpenOptions logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoffl01 committed Feb 27, 2024
1 parent f016742 commit 9523300
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions contrib/database/sql/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,26 @@ func TestOpenOptions(t *testing.T) {
defer sc.Stop()
globalconfig.SetStatsCarrier(sc)

// The polling interval has been reduced to 500ms for the sake of this test, so at least one round of `pollDBStats` has completed in 1s
// The polling interval has been reduced to 500ms for the sake of this test, so at least one round of `pollDBStats` should be complete in 1s
deadline := time.Now().Add(1 * time.Second)
wantStats := []string{MaxOpenConnections, OpenConnections, InUse, Idle, WaitCount, WaitDuration, MaxIdleClosed, MaxIdleTimeClosed, MaxLifetimeClosed}
for {
if time.Now().After(deadline) {
t.Fatalf("Stats not collected in expected interval of %v", interval)
}
calls := tg.CallNames()
if len(calls) < len(wantStats) {
time.Sleep(50 * time.Millisecond)
continue
}
for _, s := range wantStats {
assert.Contains(t, calls, s)
// if the expected volume of stats has been collected, ensure 9/9 of the DB Stats are included
if len(calls) >= len(wantStats) {
for _, s := range wantStats {
if !assert.Contains(t, calls, s) {
t.Fatalf("Missing stat %s", s)
}
}
// all expected stats have been collected; exit out of loop, test should pass
break
}
// not all stats have been collected yet, try again in 50ms
time.Sleep(50 * time.Millisecond)
}
})
}
Expand Down

0 comments on commit 9523300

Please sign in to comment.