@@ -546,16 +546,20 @@ func testSchemaEvolution(ctx context.Context, t *testing.T, mwClient *Client, bq
546
546
withExactRowCount (0 ))
547
547
548
548
var result * AppendResult
549
+ var curOffset int64
550
+ var latestRow []byte
549
551
for k , mesg := range testSimpleData {
550
552
b , err := proto .Marshal (mesg )
551
553
if err != nil {
552
554
t .Errorf ("failed to marshal message %d: %v" , k , err )
553
555
}
556
+ latestRow = b
554
557
data := [][]byte {b }
555
- result , err = ms .AppendRows (ctx , data )
558
+ result , err = ms .AppendRows (ctx , data , WithOffset ( curOffset ) )
556
559
if err != nil {
557
560
t .Errorf ("single-row append %d failed: %v" , k , err )
558
561
}
562
+ curOffset = curOffset + int64 (len (data ))
559
563
}
560
564
// wait for the result to indicate ready, then validate.
561
565
_ , err = result .GetResult (ctx )
@@ -572,9 +576,30 @@ func testSchemaEvolution(ctx context.Context, t *testing.T, mwClient *Client, bq
572
576
t .Errorf ("failed to evolve table schema: %v" , err )
573
577
}
574
578
575
- // TODO: we need a more elegant mechanism for detecting when the backend has registered the schema change.
576
- // In the continuous case, we'd get it from the response, but the change-and-wait case needs something more.
577
- time .Sleep (6 * time .Second )
579
+ // Resend latest row until we get a new schema notification.
580
+ // It _should_ be possible to send duplicates, but this currently will not propagate the schema error.
581
+ // Internal issue: b/211899346
582
+ for {
583
+ resp , err := ms .AppendRows (ctx , [][]byte {latestRow }, WithOffset (curOffset ))
584
+ if err != nil {
585
+ t .Errorf ("got error on dupe append: %v" , err )
586
+ break
587
+ }
588
+ curOffset = curOffset + 1
589
+ if err != nil {
590
+ t .Errorf ("got error on offset %d: %v" , curOffset , err )
591
+ break
592
+ }
593
+ s , err := resp .UpdatedSchema (ctx )
594
+ if err != nil {
595
+ t .Errorf ("getting schema error: %v" , err )
596
+ break
597
+ }
598
+ if s != nil {
599
+ break
600
+ }
601
+
602
+ }
578
603
579
604
// ready descriptor, send an additional append
580
605
m2 := & testdata.SimpleMessageEvolvedProto2 {
@@ -587,7 +612,7 @@ func testSchemaEvolution(ctx context.Context, t *testing.T, mwClient *Client, bq
587
612
if err != nil {
588
613
t .Errorf ("failed to marshal evolved message: %v" , err )
589
614
}
590
- result , err = ms .AppendRows (ctx , [][]byte {b }, UpdateSchemaDescriptor (descriptorProto ))
615
+ result , err = ms .AppendRows (ctx , [][]byte {b }, UpdateSchemaDescriptor (descriptorProto ), WithOffset ( curOffset ) )
591
616
if err != nil {
592
617
t .Errorf ("failed evolved append: %v" , err )
593
618
}
@@ -597,7 +622,7 @@ func testSchemaEvolution(ctx context.Context, t *testing.T, mwClient *Client, bq
597
622
}
598
623
599
624
validateTableConstraints (ctx , t , bqClient , testTable , "after send" ,
600
- withExactRowCount (int64 (len ( testSimpleData ) + 1 )),
625
+ withExactRowCount (int64 (curOffset + 1 )),
601
626
withNullCount ("name" , 0 ),
602
627
withNonNullCount ("other" , 1 ),
603
628
)
0 commit comments