File tree 2 files changed +46
-2
lines changed
2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
23
23
24
24
- Decimal package uses a test variable DecimalPrecision instead of a
25
25
package-level variable decimalPrecision (#233 )
26
+ - Flaky tests TestClientRequestObjectsWithContext and
27
+ TestClientIdRequestObjectWithContext (#244 )
26
28
27
29
## [ 1.9.0] - 2022-11-02
28
30
Original file line number Diff line number Diff line change @@ -2429,15 +2429,57 @@ func TestClientRequestObjectsWithPassedCanceledContext(t *testing.T) {
2429
2429
}
2430
2430
}
2431
2431
2432
+ // waitCtxRequest waits for the WaitGroup in Body() call and returns
2433
+ // the context from Ctx() call. The request helps us to make sure that
2434
+ // the context's cancel() call is called before a response received.
2435
+ type waitCtxRequest struct {
2436
+ ctx context.Context
2437
+ wg sync.WaitGroup
2438
+ }
2439
+
2440
+ func (req * waitCtxRequest ) Code () int32 {
2441
+ return NewPingRequest ().Code ()
2442
+ }
2443
+
2444
+ func (req * waitCtxRequest ) Body (res SchemaResolver , enc * encoder ) error {
2445
+ req .wg .Wait ()
2446
+ return NewPingRequest ().Body (res , enc )
2447
+ }
2448
+
2449
+ func (req * waitCtxRequest ) Ctx () context.Context {
2450
+ return req .ctx
2451
+ }
2452
+
2453
+ func (req * waitCtxRequest ) Async () bool {
2454
+ return NewPingRequest ().Async ()
2455
+ }
2456
+
2432
2457
func TestClientRequestObjectsWithContext (t * testing.T ) {
2433
2458
var err error
2434
2459
conn := test_helpers .ConnectWithValidation (t , server , opts )
2435
2460
defer conn .Close ()
2436
2461
2437
2462
ctx , cancel := context .WithCancel (context .Background ())
2438
- req := NewPingRequest ().Context (ctx )
2439
- fut := conn .Do (req )
2463
+ req := & waitCtxRequest {ctx : ctx }
2464
+ req .wg .Add (1 )
2465
+
2466
+ var futWg sync.WaitGroup
2467
+ var fut * Future
2468
+
2469
+ futWg .Add (1 )
2470
+ go func () {
2471
+ defer futWg .Done ()
2472
+ fut = conn .Do (req )
2473
+ }()
2474
+
2440
2475
cancel ()
2476
+ req .wg .Done ()
2477
+
2478
+ futWg .Wait ()
2479
+ if fut == nil {
2480
+ t .Fatalf ("fut must be not nil" )
2481
+ }
2482
+
2441
2483
resp , err := fut .Get ()
2442
2484
if resp != nil {
2443
2485
t .Fatalf ("response must be nil" )
You can’t perform that action at this time.
0 commit comments