1
1
mirror of https://github.com/wader/fq.git synced 2024-12-28 08:02:28 +03:00
fq/internal/ctxstack/ctxstacl_test.go
Mattias Wadman 568afff3f0 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
2022-11-29 17:38:58 +01:00

36 lines
625 B
Go

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
}