@@ -24,7 +24,7 @@ func TestTimer_NegativeDuration(t *testing.T) {
2424 timers <- mClock .NewTimer (- time .Second )
2525 }()
2626 c := trap .MustWait (ctx )
27- c .Release ( )
27+ c .MustRelease ( ctx )
2828 // trap returns the actual passed value
2929 if c .Duration != - time .Second {
3030 t .Fatalf ("expected -time.Second, got: %v" , c .Duration )
@@ -62,7 +62,7 @@ func TestAfterFunc_NegativeDuration(t *testing.T) {
6262 })
6363 }()
6464 c := trap .MustWait (ctx )
65- c .Release ( )
65+ c .MustRelease ( ctx )
6666 // trap returns the actual passed value
6767 if c .Duration != - time .Second {
6868 t .Fatalf ("expected -time.Second, got: %v" , c .Duration )
@@ -99,7 +99,7 @@ func TestNewTicker(t *testing.T) {
9999 tickers <- mClock .NewTicker (time .Hour , "new" )
100100 }()
101101 c := trapNT .MustWait (ctx )
102- c .Release ( )
102+ c .MustRelease ( ctx )
103103 if c .Duration != time .Hour {
104104 t .Fatalf ("expected time.Hour, got: %v" , c .Duration )
105105 }
@@ -123,7 +123,7 @@ func TestNewTicker(t *testing.T) {
123123 go tkr .Reset (time .Minute , "reset" )
124124 c = trapReset .MustWait (ctx )
125125 mClock .Advance (time .Second ).MustWait (ctx )
126- c .Release ( )
126+ c .MustRelease ( ctx )
127127 if c .Duration != time .Minute {
128128 t .Fatalf ("expected time.Minute, got: %v" , c .Duration )
129129 }
@@ -142,7 +142,7 @@ func TestNewTicker(t *testing.T) {
142142 }
143143
144144 go tkr .Stop ("stop" )
145- trapStop .MustWait (ctx ).Release ( )
145+ trapStop .MustWait (ctx ).MustRelease ( ctx )
146146 mClock .Advance (time .Hour ).MustWait (ctx )
147147 select {
148148 case <- tkr .C :
@@ -153,7 +153,7 @@ func TestNewTicker(t *testing.T) {
153153
154154 // Resetting after stop
155155 go tkr .Reset (time .Minute , "reset" )
156- trapReset .MustWait (ctx ).Release ( )
156+ trapReset .MustWait (ctx ).MustRelease ( ctx )
157157 mClock .Advance (time .Minute ).MustWait (ctx )
158158 tTime = mClock .Now ()
159159 select {
@@ -344,11 +344,11 @@ func Test_MultipleTraps(t *testing.T) {
344344 done := make (chan struct {})
345345 go func () {
346346 defer close (done )
347- c0 .Release ( )
347+ c0 .MustRelease ( testCtx )
348348 }()
349349 c1 := trap1 .MustWait (testCtx )
350350 mClock .Advance (time .Second )
351- c1 .Release ( )
351+ c1 .MustRelease ( testCtx )
352352
353353 select {
354354 case <- done :
@@ -367,6 +367,28 @@ func Test_MultipleTraps(t *testing.T) {
367367 }
368368}
369369
370+ func Test_MultipleTrapsDeadlock (t * testing.T ) {
371+ t .Parallel ()
372+ tRunFail (t , func (t testing.TB ) {
373+ testCtx , testCancel := context .WithTimeout (context .Background (), 2 * time .Second )
374+ defer testCancel ()
375+ mClock := quartz .NewMock (t )
376+
377+ trap0 := mClock .Trap ().Now ("0" )
378+ defer trap0 .Close ()
379+ trap1 := mClock .Trap ().Now ("1" )
380+ defer trap1 .Close ()
381+
382+ timeCh := make (chan time.Time )
383+ go func () {
384+ timeCh <- mClock .Now ("0" , "1" )
385+ }()
386+
387+ c0 := trap0 .MustWait (testCtx )
388+ c0 .MustRelease (testCtx ) // deadlocks, test failure
389+ })
390+ }
391+
370392func Test_UnreleasedCalls (t * testing.T ) {
371393 t .Parallel ()
372394 tRunFail (t , func (t testing.TB ) {
0 commit comments