test(spanner): fix potential race condition in TestRsdBlockingStates
The test case could proceed with checking the received rows against the expected,
before these had been added to the slice of received rows.
Fixes
@@ -1143,10 +1143,12 @@ func TestRsdBlockingStates(t *testing.T) {
}
var mutex = &sync.Mutex{}
var rs []*sppb.PartialResultSet
+ rowsFetched := make(chan int)
go func() {
for {
if !r.next() {
// Note that r.Next also exits on context cancel/timeout.
+ close(rowsFetched)
return
}
mutex.Lock()
@@ -1154,6 +1156,14 @@ func TestRsdBlockingStates(t *testing.T) {
mutex.Unlock()
}
}()
+ // Wait until all rows have been fetched.
+ if len(test.want) > 0 {
+ select {
+ case <-rowsFetched:
+ case <-time.After(1 * time.Second):
+ t.Fatal("Timeout in waiting for rows to be fetched")
+ }
+ }
// Verify that resumableStreamDecoder reaches expected state.
select {
case <-stateDone: // Note that at this point, receiver is still blocking on r.next().
