[FLINK-33018][Tests] Fix flaky test when cancelling source #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We sometimes observe the test failure described in FLINK-33018
This occurs because the thread running the source is explicitly cancelled in the finally clause. Unlike the other tests in this class, the source thread should run to completion and finish when the last message ID (
"3"
) arrives without external intervention.In rare cases, it was possible for the explicit
cancel()
to happen after the two records arrived, but before the third record causes the source to cleanly shut itself down and finish.This is fixed by no longer waiting for any records to arrive, just letting the thread run to completion, and then testing the results.
I checked this by running this particular test as a
@RepeatedTest(100_000)
. I have never observed the behaviour described in the issue after this change, but I've noticed that with or without the change, this test will consistently fail after the 16,248-16,250th execution, during thethread.start()
.