File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Expand file tree Collapse file tree 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.
2323
2424- Decimal package uses a test variable DecimalPrecision instead of a
2525 package-level variable decimalPrecision (#233 )
26+ - Flaky tests TestClientRequestObjectsWithContext and
27+ TestClientIdRequestObjectWithContext (#244 )
2628
2729## [ 1.9.0] - 2022-11-02
2830
Original file line number Diff line number Diff line change @@ -2429,15 +2429,57 @@ func TestClientRequestObjectsWithPassedCanceledContext(t *testing.T) {
24292429 }
24302430}
24312431
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+
24322457func TestClientRequestObjectsWithContext (t * testing.T ) {
24332458 var err error
24342459 conn := test_helpers .ConnectWithValidation (t , server , opts )
24352460 defer conn .Close ()
24362461
24372462 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+
24402475 cancel ()
2476+ req .wg .Done ()
2477+
2478+ futWg .Wait ()
2479+ if fut == nil {
2480+ t .Fatalf ("fut must be not nil" )
2481+ }
2482+
24412483 resp , err := fut .Get ()
24422484 if resp != nil {
24432485 t .Fatalf ("response must be nil" )
You can’t perform that action at this time.
0 commit comments