🤔 What's the problem you're trying to solve?
When setting up mock servers running in separate go-routines, it would be useful when the context passed to the scenario Before hooks would be cancellable and be cancelled at the end of the scenario.
✨ What's your proposed solution?
Wrap the scenario context with context.WithCancel() before Before hooks are run and call the cancel() after last After() hook is being called.
⛏ Have you considered any alternatives or workarounds?
currently I achieve this with:
func InitializeScenario(ctx *godog.ScenarioContext) {
var cancel context.CancelFunc
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
ctx, cancel = context.WithCancel(ctx)
return ctx, nil
})
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
cancel()
return ctx, nil
})
}
it's not very elegant and gets repeated every time I use godog
📚 Any additional context?
My expectation was that this happens automatically, but only after trawling through the source code and running a couple of experiments it turned out it is not the case.
This text was originally generated from a template, then edited by hand. You can modify the template here.
🤔 What's the problem you're trying to solve?
When setting up mock servers running in separate go-routines, it would be useful when the context passed to the scenario
Beforehooks would be cancellable and be cancelled at the end of the scenario.✨ What's your proposed solution?
Wrap the scenario context with
context.WithCancel()beforeBeforehooks are run and call thecancel()after lastAfter()hook is being called.⛏ Have you considered any alternatives or workarounds?
currently I achieve this with:
it's not very elegant and gets repeated every time I use godog
📚 Any additional context?
My expectation was that this happens automatically, but only after trawling through the source code and running a couple of experiments it turned out it is not the case.
This text was originally generated from a template, then edited by hand. You can modify the template here.