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

jdk19 Jep425Tests_testVirtualThread test_VirtualthreadYieldResume Virtual Thread 1: incorrect result of 1 #15651

Closed
pshipton opened this issue Aug 3, 2022 · 11 comments · Fixed by #15684 or #16558
Assignees
Labels
comp:vm jdk19 project:loom Used to track Project Loom related work test failure

Comments

@pshipton
Copy link
Member

pshipton commented Aug 3, 2022

https://openj9-jenkins.osuosl.org/job/Test_openjdk19_j9_sanity.functional_x86-64_windows_OpenJDK19_testList_1/9
Jep425Tests_testVirtualThread_0

13:17:15  FAILED: test_VirtualthreadYieldResume
13:17:15  java.lang.AssertionError: Virtual Thread 1: incorrect result of 1
13:17:15  	at org.testng.AssertJUnit.fail(AssertJUnit.java:59)
13:17:15  	at org.testng.AssertJUnit.assertTrue(AssertJUnit.java:24)
13:17:15  	at org.openj9.test.jep425.VirtualThreadTests.test_VirtualthreadYieldResume(VirtualThreadTests.java:86)

@tajila fyi

@tajila
Copy link
Contributor

tajila commented Aug 3, 2022

@JasonFengJ9 We'll need t exclude these as well

@tajila tajila added the project:loom Used to track Project Loom related work label Aug 3, 2022
@tajila
Copy link
Contributor

tajila commented Aug 4, 2022

@fengxue-IS

@babsingh
Copy link
Contributor

Removing the test excluded label since this issue has been resolved.

@pshipton
Copy link
Member Author

https://openj9-jenkins.osuosl.org/job/Test_openjdk19_j9_sanity.functional_ppc64_aix_Nightly_testList_1/89
Jep425Tests_testVirtualThread_2 --enable-preview -Xgcpolicy:balanced

01:17:03  FAILED: test_VirtualthreadYieldResume
01:17:03  java.lang.AssertionError: Virtual Thread 0: incorrect result of 2
01:17:03  	at org.testng.AssertJUnit.fail(AssertJUnit.java:59)
01:17:03  	at org.testng.AssertJUnit.assertTrue(AssertJUnit.java:24)
01:17:03  	at org.openj9.test.jep425.VirtualThreadTests.test_VirtualthreadYieldResume(VirtualThreadTests.java:87)

@pshipton pshipton reopened this Jan 11, 2023
@pshipton pshipton changed the title jdk19 Jep425Tests_testVirtualThread_0 test_VirtualthreadYieldResume Virtual Thread 1: incorrect result of 1 jdk19 Jep425Tests_testVirtualThread test_VirtualthreadYieldResume Virtual Thread 1: incorrect result of 1 Jan 11, 2023
@tajila
Copy link
Contributor

tajila commented Jan 12, 2023

@babsingh can you please take a look at this?

@babsingh
Copy link
Contributor

babsingh commented Jan 13, 2023

re #15651 (comment):

Unable to reproduce the failure

Ran two grinders:

The failure couldn't be reproduced.

Failing test's source code

public void test_VirtualthreadYieldResume() {
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
int[] results = new int[6];
IntStream.range(0, 6).forEach(i -> {
executor.submit(() -> {
results[i] = 1;
Thread.sleep(Duration.ofSeconds(1));
results[i] += 1;
Thread.sleep(Duration.ofSeconds(1));
results[i] += 1;
return i;
});
});
executor.awaitTermination(5L, TimeUnit.SECONDS);
for (int i = 0; i < 6; i++) {
AssertJUnit.assertTrue("Virtual Thread " + i + ": incorrect result of " + results[i], (results[i] == 3));
}
} catch (Exception e) {
Assert.fail("Unexpected exception occured : " + e.getMessage() , e);
}
}

Probable cause

I believe that the problem lies in the below line of the test's source code:

executor.awaitTermination(5L, TimeUnit.SECONDS);

5 seconds is not sufficient in the worst case scenario.

Why? 6 virtual threads are being launched in the test-case. Each virtual thread sleeps twice for 1 second (2 seconds in total) and performs three arithmetic operations. In addition, there is cost associated to schedule, sleep and wake the thread. Assumption: each virtual thread may take 3-4 seconds to execute in the worst case scenario. If the machine has scarce resources i.e. each virtual thread is executed sequentially (worst-case), the test-case may take 4 seconds x 6 threads = 24 seconds to execute. Overall, awaitTermination should wait for 24 seconds or preferably more for the virtual threads to finish. Next week, I will create a PR to reflect this change in the test code.

@pshipton
Copy link
Member Author

Removing from milestone plan since this won't block the release.

@pshipton pshipton removed this from the Java 19 milestone Jan 13, 2023
babsingh added a commit to babsingh/openj9 that referenced this issue Jan 16, 2023
In test_VirtualthreadYieldResume, the wait time has been increased to
support the worst-case scenario where all virtual threads are executed
sequentially. The wait loop is dynamic i.e. it will exit if the virtual
threads finish early.

Fixes: eclipse-openj9#15651

Signed-off-by: Babneet Singh <sbabneet@ca.ibm.com>
@pshipton
Copy link
Member Author

https://openj9-jenkins.osuosl.org/job/Test_openjdk19_j9_sanity.functional_ppc64_aix_Nightly_testList_1/109
Jep425Tests_testVirtualThread_1

02:10:08  FAILED: test_YieldedVirtualThreadGetStackTrace
02:10:08  java.lang.AssertionError: Expected 11 frames, got 7
02:10:08  	at org.testng.AssertJUnit.fail(AssertJUnit.java:59)
02:10:08  	at org.testng.AssertJUnit.assertTrue(AssertJUnit.java:24)
02:10:08  	at org.openj9.test.jep425.VirtualThreadTests.test_YieldedVirtualThreadGetStackTrace(VirtualThreadTests.java:182)

@babsingh
Copy link
Contributor

babsingh commented Feb 14, 2023

@fengxue-IS A similar failure from #16693 is seen above for different reasons. Can you review the test case for other weaknesses?

@babsingh
Copy link
Contributor

This issue only tracks failures related to test_VirtualthreadYieldResume. The test_YieldedVirtualThreadGetStackTrace failure is seen for the first time. @pshipton Should we track it in a new issue?

@pshipton
Copy link
Member Author

Yes, sorry. Created #16722

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:vm jdk19 project:loom Used to track Project Loom related work test failure
Projects
None yet
4 participants