Skip to content

Commit cbc2c21

Browse files
authored
Fix flaky TestDataSampler/GetSamplesForPCollectionsTooManySamples (#38736)
Since GetSamples is a destructive operation that clears stored samples, polling it in a loop is flaky. If it is called before all asynchronous samples have finished processing, it consumes the early samples and clears them, causing verifySampledElements to fail. In this PR, we wait for the sampler to finish before reading to ensure all elements are successfully captured.
1 parent f771827 commit cbc2c21

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

sdks/go/pkg/beam/core/runtime/exec/datasampler_test.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,9 @@ func TestDataSampler(t *testing.T) {
104104
for _, sample := range test.samples {
105105
dataSampler.SendSample(sample.PCollectionID, sample.Element, sample.Timestamp)
106106
}
107-
var samplesCount = -1
108-
var samples map[string][]*DataSample
109-
for i := 0; i < 5; i++ {
110-
samples = dataSampler.GetSamples(test.pids)
111-
if len(samples) == len(test.want) {
112-
samplesCount = len(samples)
113-
break
114-
}
115-
time.Sleep(time.Second)
116-
}
107+
time.Sleep(1 * time.Second)
108+
samples := dataSampler.GetSamples(test.pids)
109+
samplesCount := len(samples)
117110
cancel()
118111
if samplesCount != len(test.want) {
119112
t.Errorf("got an unexpected number of sampled elements: %v, want: %v", samplesCount, len(test.want))

0 commit comments

Comments
 (0)