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 @@ -22,6 +22,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
22
22
23
23
- Decimal package uses a test variable DecimalPrecision instead of a
24
24
package-level variable decimalPrecision (#233 )
25
+ - Flaky tests TestClientRequestObjectsWithContext and
26
+ TestClientIdRequestObjectWithContext (#244 )
25
27
26
28
## [ 1.9.0] - 2022-11-02
27
29
Original file line number Diff line number Diff line change @@ -2397,15 +2397,57 @@ func TestClientRequestObjectsWithPassedCanceledContext(t *testing.T) {
2397
2397
}
2398
2398
}
2399
2399
2400
+ // waitCtxRequest waits for the WaitGroup in Body() call and returns
2401
+ // the context from Ctx() call. The request helps us to make sure that
2402
+ // the context's cancel() call is called before a response received.
2403
+ type waitCtxRequest struct {
2404
+ ctx context.Context
2405
+ wg sync.WaitGroup
2406
+ }
2407
+
2408
+ func (req * waitCtxRequest ) Code () int32 {
2409
+ return NewPingRequest ().Code ()
2410
+ }
2411
+
2412
+ func (req * waitCtxRequest ) Body (res SchemaResolver , enc * encoder ) error {
2413
+ req .wg .Wait ()
2414
+ return NewPingRequest ().Body (res , enc )
2415
+ }
2416
+
2417
+ func (req * waitCtxRequest ) Ctx () context.Context {
2418
+ return req .ctx
2419
+ }
2420
+
2421
+ func (req * waitCtxRequest ) Async () bool {
2422
+ return NewPingRequest ().Async ()
2423
+ }
2424
+
2400
2425
func TestClientRequestObjectsWithContext (t * testing.T ) {
2401
2426
var err error
2402
2427
conn := test_helpers .ConnectWithValidation (t , server , opts )
2403
2428
defer conn .Close ()
2404
2429
2405
2430
ctx , cancel := context .WithCancel (context .Background ())
2406
- req := NewPingRequest ().Context (ctx )
2407
- fut := conn .Do (req )
2431
+ req := & waitCtxRequest {ctx : ctx }
2432
+ req .wg .Add (1 )
2433
+
2434
+ var futWg sync.WaitGroup
2435
+ var fut * Future
2436
+
2437
+ futWg .Add (1 )
2438
+ go func () {
2439
+ defer futWg .Done ()
2440
+ fut = conn .Do (req )
2441
+ }()
2442
+
2408
2443
cancel ()
2444
+ req .wg .Done ()
2445
+
2446
+ futWg .Wait ()
2447
+ if fut == nil {
2448
+ t .Fatalf ("fut must be not nil" )
2449
+ }
2450
+
2409
2451
resp , err := fut .Get ()
2410
2452
if resp != nil {
2411
2453
t .Fatalf ("response must be nil" )
You can’t perform that action at this time.
0 commit comments