Skip to content

Commit

Permalink
test: retry count assertion on session invalidation (#135)
Browse files Browse the repository at this point in the history
Session context tests check the counter value hold by a session bean right
after invalidating the Vaadin session. Since the counter is incremented
in the PreDestroy hook, it may happen that when the test checks for the
counter value, the callback has not yet been invoked.
This change retries the counter check for at most on second, to preven
ttest flakyness.

Fixes #126
  • Loading branch information
mcollovati authored Jul 5, 2023
1 parent 1a40a91 commit 4eb35f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ protected String getText(String id) {
return findElement(By.id(id)).getText();
}

protected void waitForCount(int expectedCount, String counter) {
waitUntil(driver -> {
try {
assertCountEquals(expectedCount, counter);
return true;
} catch (Exception ex) {
return false;
}
}, 1);
}

protected void assertCountEquals(int expectedCount, String counter)
throws IOException {
Assert.assertEquals(expectedCount, getCount(counter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public void vaadinSessionCloseDestroysSessionContext() throws Exception {

private void assertDestroyCountEquals(int expectedCount)
throws IOException {
assertCountEquals(expectedCount, DESTROY_COUNT);
waitForCount(expectedCount, DESTROY_COUNT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void assertLabelEquals(String expected) {

private void assertDestroyCountEquals(int expectedCount)
throws IOException {
assertCountEquals(expectedCount, DESTROY_COUNT);
waitForCount(expectedCount, DESTROY_COUNT);
}

private static Logger getLogger() {
Expand Down

0 comments on commit 4eb35f9

Please sign in to comment.