-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interp: Fix panic when trigger before any context has been pushed
Make sure there is a top cancel function before calling it. Fixes panic caused when interrupting decode before interp context has been pushed. Also cleanup confusing naming a bit. Thanks @pldin601 for reporting
- Loading branch information
Showing
2 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ctxstack_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/wader/fq/internal/ctxstack" | ||
) | ||
|
||
func TestCancelBeforePush(t *testing.T) { | ||
// TODO: nicer way to test trigger before any push | ||
waitTriggerFn := make(chan struct{}) | ||
triggerCh := make(chan struct{}) | ||
waitCh := make(chan struct{}) | ||
hasTriggeredOnce := false | ||
|
||
ctxstack.New(func(stopCh chan struct{}) { | ||
if hasTriggeredOnce { | ||
close(stopCh) | ||
close(waitCh) | ||
return | ||
} | ||
|
||
close(waitTriggerFn) | ||
<-triggerCh | ||
|
||
hasTriggeredOnce = true | ||
}) | ||
|
||
// wait for trigger func to be called | ||
<-waitTriggerFn | ||
// make trigger func return and cancel | ||
close(triggerCh) | ||
|
||
<-waitCh | ||
} |