File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 9
9
10
10
func Context (s * testcase.Spec ) testcase.Var [context.Context ] {
11
11
return testcase .Let (s , func (t * testcase.T ) context.Context {
12
- return context .Background ()
12
+ ctx , cancel := context .WithCancel (context .Background ())
13
+ t .Defer (cancel )
14
+ return ctx
13
15
})
14
16
}
15
17
Original file line number Diff line number Diff line change @@ -34,7 +34,16 @@ func TestSTD_smoke(t *testing.T) {
34
34
}
35
35
36
36
s .Test ("" , func (t * testcase.T ) {
37
- t .Must .Equal (context .Background (), Context .Get (t ))
37
+ t .Must .NotNil (Context .Get (t ))
38
+ t .Must .NoError (Context .Get (t ).Err ())
39
+ t .Must .NotWithin (time .Millisecond , func (ctx context.Context ) {
40
+ select {
41
+ case <- Context .Get (t ).Done ():
42
+ // expect to block
43
+ case <- ctx .Done ():
44
+ // will be done after the assertion
45
+ }
46
+ })
38
47
t .Must .Error (Error .Get (t ))
39
48
t .Must .NotEmpty (String .Get (t ))
40
49
t .Must .NotEmpty (StringNC .Get (t ))
@@ -53,3 +62,17 @@ func TestSTD_smoke(t *testing.T) {
53
62
})
54
63
})
55
64
}
65
+
66
+ func TestContext_cancellationDuringCleanup (t * testing.T ) {
67
+ s := testcase .NewSpec (t )
68
+ s .Sequential ()
69
+ ctxVar := let .Context (s )
70
+ var ctx context.Context
71
+ s .Test ("" , func (t * testcase.T ) {
72
+ ctx = ctxVar .Get (t )
73
+ t .Must .NoError (ctx .Err ())
74
+ })
75
+ s .Finish ()
76
+ assert .NotNil (t , ctx )
77
+ assert .ErrorIs (t , context .Canceled , ctx .Err ())
78
+ }
You can’t perform that action at this time.
0 commit comments