Skip to content

Commit

Permalink
Merge pull request eclipse-openj9#17928 from babsingh/add_incremental…
Browse files Browse the repository at this point in the history
…_delays_vthreadtests

[JDK21+] Increase wait time in VirtualThreadTests
  • Loading branch information
pshipton authored Aug 10, 2023
2 parents 9576ce3 + d6c6a06 commit e4258d8
Showing 1 changed file with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public class VirtualThreadTests {

public static native boolean lockSupportPark();

private void incrementalWait(Thread t) throws InterruptedException {
/* Incrementally wait for 10000 ms. */
for (int i = 0; i < 200; i++) {
Thread.sleep(50);
if (Thread.State.WAITING == t.getState()) {
break;
}
}
}

@Test
public void test_basicVirtualthread() {
var wrapper = new Object(){ boolean executed = false; };
Expand Down Expand Up @@ -113,24 +123,23 @@ public void test_VirtualthreadYieldResume() {
}
}

private static volatile boolean testSyncThread_ready;
private static volatile boolean testSyncThreadReady = false;

@Test
public void test_synchronizedBlockFromVirtualthread() {
try {
Thread t = Thread.ofVirtual().name("synchronized").unstarted(() -> {
Thread t = Thread.ofVirtual().name("synchronized").start(() -> {
synchronized (VirtualThreadTests.class) {
testSyncThread_ready = true;
testSyncThreadReady = true;
LockSupport.park();
}
});

t.start();
while (!testSyncThread_ready) {
Thread.sleep(1);
while (!testSyncThreadReady) {
Thread.sleep(10);
}
/* Let virtual thread park */
Thread.sleep(500);
/* Incrementally wait for 10000 ms to let the virtual thread park. */
incrementalWait(t);
Assert.assertEquals(t.getState(), Thread.State.WAITING);
LockSupport.unpark(t);
t.join();
Expand All @@ -139,22 +148,21 @@ public void test_synchronizedBlockFromVirtualthread() {
}
}

private static volatile boolean testJNIThread_ready;
private static volatile boolean testJNIThreadReady = false;

@Test
public void test_jniFromVirtualthread() {
try {
Thread t = Thread.ofVirtual().name("native").unstarted(() -> {
testJNIThread_ready = true;
Thread t = Thread.ofVirtual().name("native").start(() -> {
testJNIThreadReady = true;
lockSupportPark();
});

t.start();
while (!testJNIThread_ready) {
Thread.sleep(1);
while (!testJNIThreadReady) {
Thread.sleep(10);
}
/* Let virtual thread park */
Thread.sleep(500);
/* Incrementally wait for 10000 ms to let the virtual thread park. */
incrementalWait(t);
Assert.assertEquals(t.getState(), Thread.State.WAITING);
LockSupport.unpark(t);
t.join();
Expand Down Expand Up @@ -182,14 +190,8 @@ public void test_YieldedVirtualThreadGetStackTrace() {
Thread.sleep(10);
}

/* Incrementally wait for 10000 ms. */
for (int i = 0; i < 20; i++) {
/* Let the virtual thread park. */
Thread.sleep(500);
if (Thread.State.WAITING == t.getState()) {
break;
}
}
/* Incrementally wait for 10000 ms to let the virtual thread park. */
incrementalWait(t);

StackTraceElement[] ste = t.getStackTrace();

Expand Down

0 comments on commit e4258d8

Please sign in to comment.