@@ -43,6 +43,19 @@ import (
4343 "github.com/stretchr/testify/require"
4444)
4545
46+ func waitReady (t * testing.T , f * Future , runDone chan error ) {
47+ t .Helper ()
48+ select {
49+ case <- f .done :
50+ case err := <- runDone :
51+ runDone <- err
52+ require .NoError (t , err , "decoder group exited before future became ready" )
53+ t .Fatal ("decoder group exited before future became ready" )
54+ case <- t .Context ().Done ():
55+ require .NoError (t , context .Cause (t .Context ()))
56+ }
57+ }
58+
4659func TestDecodeStorageCanalJSONSharesAlignedTableInfo (t * testing.T ) {
4760 cfg := common .NewConfig (config .ProtocolCanalJSON )
4861 cfg .EnableTiDBExtension = true
@@ -204,7 +217,7 @@ func TestDecodeGroupConcurrentPoolPreservesOrderAndDynamicPartitions(t *testing.
204217
205218 for i , part := range partitions {
206219 f := <- group .Output ()
207- require . NoError (t , f . Ready ( t . Context ()) )
220+ waitReady (t , f , runDone )
208221 require .Equal (t , part , f .Payload .Partition )
209222 require .Len (t , f .Events , 1 )
210223 dml := f .Events [0 ].(* event.DMLEvent )
@@ -256,7 +269,7 @@ func TestDecodeGroupConcurrentPoolPreservesOrderAndDynamicPartitions(t *testing.
256269
257270 for i := range 4 {
258271 f := <- storageGroup .Output ()
259- require . NoError (t , f . Ready ( t . Context ()) )
272+ waitReady (t , f , storageDone )
260273 dml := f .Events [0 ].(* event.DMLEvent )
261274 dml .PostFlush ()
262275 require .Equal (t , uint64 (200 + i ), dml .CommitTs )
@@ -350,7 +363,7 @@ func TestDecodeGroupDebeziumAvroSharesSchemaManagerAndCloses(t *testing.T) {
350363
351364 for range payloads {
352365 f := <- group .Output ()
353- require . NoError (t , f . Ready ( t . Context ()) )
366+ waitReady (t , f , runDone )
354367 require .Len (t , f .Events , 1 )
355368 resolved := f .Events [0 ].(* event.ResolvedEvent )
356369 require .Equal (t , uint64 (12345 ), resolved .ResolvedTs )
@@ -454,16 +467,16 @@ func TestDecodeGroupSimpleCrossPartitionWakeupOutOfOrderAndOver128(t *testing.T)
454467 t2Pending := make (map [uint64 ]int64 , t2Count )
455468 for range t1Count + t2Count {
456469 f := <- group .Output ()
457- require . NoError (t , f . Ready ( t . Context ()) )
470+ waitReady (t , f , runDone )
458471 require .Empty (t , f .Events )
459472 require .Len (t , f .Pending , 1 )
460473 if f .Payload .Partition == 0 {
461474 require .Equal (t , uint64 (200 ), f .Pending [0 ].CommitTs )
462475 t1Pending [f .Pending [0 ].ID ] = f .Payload .Offset
463- } else {
464- require .Equal (t , uint64 (210 ), f .Pending [0 ].CommitTs )
465- t2Pending [f .Pending [0 ].ID ] = f .Payload .Offset
476+ continue
466477 }
478+ require .Equal (t , uint64 (210 ), f .Pending [0 ].CommitTs )
479+ t2Pending [f .Pending [0 ].ID ] = f .Payload .Offset
467480 }
468481 require .NoError (t , <- addErr )
469482
@@ -474,7 +487,7 @@ func TestDecodeGroupSimpleCrossPartitionWakeupOutOfOrderAndOver128(t *testing.T)
474487 }))
475488
476489 fBoot2 := <- group .Output ()
477- require . NoError (t , fBoot2 . Ready ( t . Context ()) )
490+ waitReady (t , fBoot2 , runDone )
478491 require .Empty (t , fBoot2 .Events )
479492 require .Len (t , fBoot2 .Resolved , t2Count )
480493 for _ , r := range fBoot2 .Resolved {
@@ -488,7 +501,7 @@ func TestDecodeGroupSimpleCrossPartitionWakeupOutOfOrderAndOver128(t *testing.T)
488501 require .Empty (t , t2Pending )
489502
490503 fBoot1 := <- group .Output ()
491- require . NoError (t , fBoot1 . Ready ( t . Context ()) )
504+ waitReady (t , fBoot1 , runDone )
492505 require .Empty (t , fBoot1 .Events )
493506 require .Len (t , fBoot1 .Resolved , t1Count )
494507 for _ , r := range fBoot1 .Resolved {
@@ -578,11 +591,11 @@ func TestDecodeGroupSimpleDDLWakesPreAndPostSchemaWaiters(t *testing.T) {
578591 }))
579592
580593 fPre := <- group .Output ()
581- require . NoError (t , fPre . Ready ( t . Context ()) )
594+ waitReady (t , fPre , runDone )
582595 require .Len (t , fPre .Pending , 1 )
583596
584597 fPost := <- group .Output ()
585- require . NoError (t , fPost . Ready ( t . Context ()) )
598+ waitReady (t , fPost , runDone )
586599 require .Len (t , fPost .Pending , 1 )
587600
588601 require .NoError (t , group .Add (t .Context (), []* source.Payload {
@@ -591,7 +604,7 @@ func TestDecodeGroupSimpleDDLWakesPreAndPostSchemaWaiters(t *testing.T) {
591604
592605 // First ALTER arrival wakes both PreTableSchema and post-DDL waiters and forwards the DDL.
593606 fAlter := <- group .Output ()
594- require . NoError (t , fAlter . Ready ( t . Context ()) )
607+ waitReady (t , fAlter , runDone )
595608 require .Zero (t , fAlter .Marker )
596609 require .Len (t , fAlter .Events , 1 )
597610 forwardedDDL := fAlter .Events [0 ].(* event.DDLEvent )
@@ -618,7 +631,7 @@ func TestDecodeGroupSimpleDDLWakesPreAndPostSchemaWaiters(t *testing.T) {
618631 {Partition : 3 , Offset : 40 , Value : alterMsg .Value },
619632 }))
620633 fDup := <- group .Output ()
621- require . NoError (t , fDup . Ready ( t . Context ()) )
634+ waitReady (t , fDup , runDone )
622635 require .Empty (t , fDup .Events )
623636 require .Equal (t , uint64 (200 ), fDup .Marker )
624637 require .Empty (t , fDup .Resolved )
0 commit comments