Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing flaky tests #3098

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public void flakyTest() {
}
}

@Test(timeOut = 2, priority = 4)
@Test(timeOut = 25, priority = 4)
public void timingOutTest() throws InterruptedException {
TimeUnit.MILLISECONDS.sleep(10);
TimeUnit.SECONDS.sleep(10);
Assert.fail();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@ public void anotherSampleTest() {

private void sleepSilently() {
try {
TimeUnit.MILLISECONDS.sleep(500 * random.nextInt(10));
TimeUnit.MILLISECONDS.sleep(500 * random());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}

private static long random() {
int value = random.nextInt(10);
if (value == 0) {
return 1;
}
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,20 @@ public void testSuiteLevelParallelMode() {
String allTimeStamps =
keyset.stream().map(Objects::toString).collect(Collectors.joining(","));
long prev = keyset.get(0);
int permissibleLag = 40;
for (int i = 1; i < keyset.size(); i++) {
long current = keyset.get(i);
long diff = current - prev;
Assertions.assertThat(diff)
.withFailMessage(
"Test methods should have started within a lag of max 40 ms but it was "
"Test methods should have started within a lag of max "
+ permissibleLag
+ " ms but it was "
+ diff
+ " ms ["
+ allTimeStamps
+ "]")
.isLessThanOrEqualTo(40);
.isLessThanOrEqualTo(permissibleLag);
prev = current;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public Option[] config() {
return options(defaultTestngOsgiOptions());
}

@Test
// TODO: Enable this test once the PR https://github.com/ops4j/org.ops4j.pax.exam2/pull/1112
// gets merged and there's a new release done.
@Test(enabled = false)
public void versionShouldStartWithDigit() throws Exception {
Class<?> versionClass = Class.forName("org.testng.internal.Version");
Method getVersionStringMethod = versionClass.getMethod("getVersionString");
Expand Down
Loading