Skip to content

Commit 5bac48c

Browse files
committed
Harden contention regression tests
1 parent 9989fc5 commit 5bac48c

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/test/java/net/openhft/chronicle/queue/ChronicleHistoryReaderMainTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public void setUp() {
4343

4444
@After
4545
public void tearDown() {
46-
System.setSecurityManager(null);
46+
if (Jvm.majorVersion() < 17)
47+
System.setSecurityManager(null);
4748
}
4849

4950
@Test

src/test/java/net/openhft/chronicle/queue/ChronicleRollingIssueTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.List;
2020
import java.util.Map;
2121
import java.util.concurrent.atomic.AtomicInteger;
22+
import java.util.concurrent.locks.LockSupport;
2223

2324
import static net.openhft.chronicle.queue.rollcycles.TestRollCycles.TEST_SECONDLY;
2425

@@ -39,9 +40,10 @@ public void tearDown() {
3940
IOTools.deleteDirWithFiles(path);
4041
}
4142

42-
@Test
43+
@Test(timeout = 180_000L)
4344
public void test() throws InterruptedException {
44-
int threads = Math.min(64, Runtime.getRuntime().availableProcessors() * 4) - 1;
45+
int processors = Runtime.getRuntime().availableProcessors();
46+
int threads = Math.max(2, Math.min(64, processors * 2) - 1);
4547
int messages = 100;
4648

4749
AtomicInteger count = new AtomicInteger();
@@ -55,12 +57,12 @@ public void test() throws InterruptedException {
5557
.rollCycle(TEST_SECONDLY).build();
5658
ExcerptAppender appender = writeQueue.createAppender()) {
5759
for (int i = 0; i < messages; i++) {
58-
long millis = System.currentTimeMillis() % 100;
59-
if (millis > 1 && millis < 99) {
60-
Jvm.pause(99 - millis);
61-
}
6260
Map<String, Object> map = new HashMap<>();
6361
map.put("key", Thread.currentThread().getName() + " - " + i);
62+
63+
long nanos = System.nanoTime() % 100_000_000;
64+
// should cause them all to try to wake and write at the same time
65+
LockSupport.parkNanos(100_000_000 - nanos);
6466
appender.writeMap(map);
6567
count.incrementAndGet();
6668
}

src/test/java/net/openhft/chronicle/queue/impl/single/AppenderFileHandleLeakTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void setUp() {
8989
queuePath = getTmpDir();
9090
}
9191

92-
@Test
92+
@Test(timeout = 180_000L)
9393
public void appenderAndTailerResourcesShouldBeCleanedUpByGarbageCollection() throws InterruptedException, TimeoutException, ExecutionException {
9494
finishedNormally = false;
9595
try (ChronicleQueue queue = createQueue(SYSTEM_TIME_PROVIDER)) {
@@ -125,7 +125,7 @@ public void appenderAndTailerResourcesShouldBeCleanedUpByGarbageCollection() thr
125125
finishedNormally = true;
126126
}
127127

128-
@Test
128+
@Test(timeout = 180_000L)
129129
public void tailerResourcesCanBeReleasedManually() throws Exception {
130130
FlakyTestRunner.builder(this::tailerResourcesCanBeReleasedManually0).build().run();
131131
}

0 commit comments

Comments
 (0)