chore: fix lengthy tests in psql (#7545)

* chore: fix lengthy tests in psql

This was adding at a minimum 3mins to our psql tests!

* fix: automatically cancel tests on cleanup
This commit is contained in:
Kyle Carberry
2023-05-17 11:26:53 -05:00
committed by GitHub
parent d1b1122690
commit 6e7175b589
5 changed files with 15 additions and 7 deletions
+7 -1
View File
@@ -137,6 +137,7 @@ func Start(t *testing.T, inv *clibase.Invocation) {
// before ours.
waiter := StartWithWaiter(t, inv)
t.Cleanup(func() {
waiter.Cancel()
<-closeCh
})
@@ -163,11 +164,16 @@ func Run(t *testing.T, inv *clibase.Invocation) {
type ErrorWaiter struct {
waitOnce sync.Once
cachedError error
cancelFunc context.CancelFunc
c <-chan error
t *testing.T
}
func (w *ErrorWaiter) Cancel() {
w.cancelFunc()
}
func (w *ErrorWaiter) Wait() error {
w.waitOnce.Do(func() {
var ok bool
@@ -241,5 +247,5 @@ func StartWithWaiter(t *testing.T, inv *clibase.Invocation) *ErrorWaiter {
cleaningUp.Store(true)
<-doneCh
})
return &ErrorWaiter{c: errCh, t: t}
return &ErrorWaiter{c: errCh, t: t, cancelFunc: cancel}
}