Fix memory leak in tests

- Stop leaking tickers. As the docs state, using time.Tick() will leak tickers,
      so use time.NewTicker() with time.Ticker.Stop().
    - Be more efficient by using time.NewTimer() with time.Timer.Stop() instead of time.After().
This commit is contained in:
Dale Hui 2019-01-04 14:39:32 -08:00
parent caa5719a86
commit d549fd5265
1 changed files with 6 additions and 4 deletions

View File

@ -48,17 +48,19 @@ func ParallelTest(t *testing.T, versions []Version, readyFn IsReadyFunc, testFn
defer container.Remove()
// wait until database is ready
tick := time.Tick(1000 * time.Millisecond)
timeout := time.After(time.Duration(timeout) * time.Second)
tick := time.NewTicker(1000 * time.Millisecond)
defer tick.Stop()
timeout := time.NewTimer(time.Duration(timeout) * time.Second)
defer timeout.Stop()
outer:
for {
select {
case <-tick:
case <-tick.C:
if readyFn(container) {
break outer
}
case <-timeout:
case <-timeout.C:
t.Fatalf("Docker: Container not ready, timeout for %v.\n%s", version, containerLogs(t, container))
}
}