@@ -84,35 +84,36 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
8484 // we mutate the single supplied top-level context, then only the
8585 // first deadline/timeout will be used.
8686 specCtx , specCancel := context .WithCancel (ctx )
87- defer specCancel ()
8887
8988 to := getTimeout (ctx , scDefaults , plugin , spec )
9089 if to != nil {
91- var cancel context.CancelFunc
92- specCtx , cancel = context .WithTimeout (specCtx , to .Duration ())
93- defer cancel ()
90+ specCtx , specCancel = context .WithTimeout (specCtx , to .Duration ())
9491 }
9592
9693 var res * api.Result
9794 ch := make (chan runSpecRes , 1 )
9895
99- go s .runSpec (specCtx , ch , rt , to , idx , spec )
96+ go s .runSpec (specCtx , ch , rt , idx , spec )
10097
10198 select {
10299 case <- specCtx .Done ():
103100 t .Fatalf ("assertion failed: timeout exceeded (%s)" , to .After )
101+ specCancel ()
104102 break
105103 case runres := <- ch :
106104 res = runres .r
107105 rterr = runres .err
108106 }
109107 if rterr != nil {
108+ specCancel ()
110109 break
111110 }
111+
112112 if wait != nil && wait .After != "" {
113113 debug .Println (ctx , "wait: %s after" , wait .After )
114114 time .Sleep (wait .AfterDuration ())
115115 }
116+
116117 // Results can have arbitrary run data stored in them and we
117118 // save this prior run data in the top-level context (and pass
118119 // that context to the next Run invocation).
@@ -122,6 +123,7 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
122123 for _ , fail := range res .Failures () {
123124 t .Fatal (fail )
124125 }
126+ specCancel ()
125127 }
126128 })
127129 return rterr
@@ -137,7 +139,6 @@ func (s *Scenario) runSpec(
137139 ctx context.Context ,
138140 ch chan runSpecRes ,
139141 retry * api.Retry ,
140- timeout * api.Timeout ,
141142 idx int ,
142143 spec api.Evaluable ,
143144) {
0 commit comments