File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 11module github.com/coder/quartz
22
33go 1.23.9
4+
5+ require go.uber.org/goleak v1.3.0
Original file line number Diff line number Diff line change @@ -761,6 +761,11 @@ func (t *Trap) matches(c *apiCall) bool {
761761func (t * Trap ) Close () {
762762 t .mock .mu .Lock ()
763763 defer t .mock .mu .Unlock ()
764+ select {
765+ case <- t .done :
766+ return // already closed
767+ default :
768+ }
764769 if t .unreleasedCalls != 0 {
765770 t .mock .tb .Helper ()
766771 t .mock .tb .Errorf ("trap Closed() with %d unreleased calls" , t .unreleasedCalls )
Original file line number Diff line number Diff line change 88 "time"
99
1010 "github.com/coder/quartz"
11+ "go.uber.org/goleak"
1112)
1213
1314func TestTimer_NegativeDuration (t * testing.T ) {
@@ -403,7 +404,10 @@ func Test_UnreleasedCalls(t *testing.T) {
403404 _ = mClock .Now ()
404405 }()
405406
406- trap .MustWait (testCtx ) // missing release
407+ c := trap .MustWait (testCtx ) // missing release
408+ trap .Close () // detect unreleased call and fail
409+
410+ c .Release (testCtx ) // clean up goroutine
407411 })
408412}
409413
@@ -573,3 +577,7 @@ func TestTickerStop_Go123(t *testing.T) {
573577 // OK!
574578 }
575579}
580+
581+ func TestMain (m * testing.M ) {
582+ goleak .VerifyTestMain (m )
583+ }
You can’t perform that action at this time.
0 commit comments