Skip to content

Commit

Permalink
test: fix flaky test ClientTest.shouldFailPollStreamedQueryResultIfFa…
Browse files Browse the repository at this point in the history
…iled (#9303)

The test sometimes fails with a NPE due to a race condition.
The needed `subscriber` is registered async.
This PRs add a check in the setup that the `subscriber` was indeed
registered and is not `null` before the test can start.
  • Loading branch information
mjsax authored Jul 18, 2022
1 parent 4b2b75b commit 5413985
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected long getDemand() {
return demand;
}

protected Subscriber<? super T> getSubscriber() {
public Subscriber<? super T> getSubscriber() {
return subscriber;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ public void setUp() {
createServer(serverConfig);
this.client = createClient();
setDefaultRowGenerator();

testEndpoints.getQueryPublishers().forEach(
publisher -> {
final long timeout = System.currentTimeMillis() + 30_000L;
while (publisher.getSubscriber() == null) {
try {
Thread.sleep(100L);
} catch (InterruptedException swallow) {
}

if (System.currentTimeMillis() > timeout) {
throw new RuntimeException("Test setup failed; no subscriber registered.");
}
}
}
);
}

@After
Expand Down

0 comments on commit 5413985

Please sign in to comment.