mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
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:
@@ -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}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user