From 830932041a7417445eb3aa7f88bf5f5e44295284 Mon Sep 17 00:00:00 2001 From: Dragan Milic Date: Tue, 27 Dec 2022 15:25:44 +0100 Subject: [PATCH] cancel context for each scenario --- CHANGELOG.md | 1 + suite.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfdd8d9c..739815c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt ## Unreleased ### Changed +- Each scenario is run with a cancellable `context.Context` which is cancelled at the end of the scenario. ([514](https://github.com/cucumber/godog/pull/514) - [draganm](https://github.com/draganm)) - README example is updated with `context.Context` and `go test` usage. ([477](https://github.com/cucumber/godog/pull/477) - [vearutop](https://github.com/vearutop)) - Removed deprecation of `godog.BindFlags` ([498](https://github.com/cucumber/godog/pull/498) - [vearutop](https://github.com/vearutop)) diff --git a/suite.go b/suite.go index 05860526..c0f2b512 100644 --- a/suite.go +++ b/suite.go @@ -426,6 +426,12 @@ func (s *suite) runPickle(pickle *messages.Pickle) (err error) { ctx = context.Background() } + var cancel context.CancelFunc + + ctx, cancel = context.WithCancel(ctx) + + defer cancel() + if len(pickle.Steps) == 0 { pr := models.PickleResult{PickleID: pickle.Id, StartedAt: utils.TimeNowFunc()} s.storage.MustInsertPickleResult(pr)