Skip to content

Commit f8d722e

Browse files
committed
Fixing flaky tests
1 parent 69dc232 commit f8d722e

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

testng-core/src/test/java/test/listeners/issue2916/ElaborateSampleTestCase.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public void flakyTest() {
2323
}
2424
}
2525

26-
@Test(timeOut = 2, priority = 4)
26+
@Test(timeOut = 25, priority = 4)
2727
public void timingOutTest() throws InterruptedException {
28-
TimeUnit.MILLISECONDS.sleep(10);
28+
TimeUnit.SECONDS.sleep(10);
29+
Assert.fail();
2930
}
3031
}

testng-core/src/test/java/test/thread/issue188/Issue188TestSample.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@ public void anotherSampleTest() {
3737

3838
private void sleepSilently() {
3939
try {
40-
TimeUnit.MILLISECONDS.sleep(500 * random.nextInt(10));
40+
TimeUnit.MILLISECONDS.sleep(500 * random());
4141
} catch (InterruptedException e) {
4242
Thread.currentThread().interrupt();
4343
}
4444
}
45+
46+
private static long random() {
47+
int value = random.nextInt(10);
48+
if (value == 0) {
49+
return 1;
50+
}
51+
return value;
52+
}
4553
}

testng-core/src/test/java/test/thread/issue188/IssueTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,20 @@ public void testSuiteLevelParallelMode() {
4040
String allTimeStamps =
4141
keyset.stream().map(Objects::toString).collect(Collectors.joining(","));
4242
long prev = keyset.get(0);
43+
int permissibleLag = 40;
4344
for (int i = 1; i < keyset.size(); i++) {
4445
long current = keyset.get(i);
4546
long diff = current - prev;
4647
Assertions.assertThat(diff)
4748
.withFailMessage(
48-
"Test methods should have started within a lag of max 40 ms but it was "
49+
"Test methods should have started within a lag of max "
50+
+ permissibleLag
51+
+ " ms but it was "
4952
+ diff
5053
+ " ms ["
5154
+ allTimeStamps
5255
+ "]")
53-
.isLessThanOrEqualTo(40);
56+
.isLessThanOrEqualTo(permissibleLag);
5457
prev = current;
5558
}
5659
}

testng-test-osgi/src/test/java/org/testng/test/osgi/PlainOsgiTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public Option[] config() {
2525
return options(defaultTestngOsgiOptions());
2626
}
2727

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

0 commit comments

Comments
 (0)