Skip to content

Commit

Permalink
[EagerAppCDS] Fix unstable test case TestExecStartupProbe
Browse files Browse the repository at this point in the history
Summary: Change hard-code sleep time to test if a file exist which means CDS dump successful.

Test Plan: TestExecStartupProbe.java

Reviewed-by: jia-wei-tang, yuleil

Issue: #687
  • Loading branch information
lingjun-cg committed Oct 11, 2023
1 parent ed89ff6 commit fbd63de
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions test/jdk/com/alibaba/quickstart/StartupProbeTestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ protected void runAsProfile(Project p, ProjectWorkDir workDir) throws Exception
ProcessBuilder pb = createJavaProcessBuilder(cp, merge(new String[][]{
getProfileOptions(workDir.getCacheDir()), commands}));
pb.environment().put("DRAGONWELL_QUICKSTART_STARTUP_PROBE",base64StartupProbe);
//set a file flag that indicate CDS dump successful
pb.environment().put("CDS_DUMP_FINISH_FILE", workDir.getCacheDir() + File.separator + "metadata");
jdk.test.lib.process.OutputAnalyzer output = new jdk.test.lib.process.OutputAnalyzer(pb.start());
output.shouldContain("Running as profiler");
output.shouldHaveExitValue(0);
Expand Down
26 changes: 20 additions & 6 deletions test/jdk/com/alibaba/quickstart/TestExecStartupProbe.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,39 @@ public static void main(String[] args) throws Exception {
"}", succKeyWord, logFile);

String probeBase64 = Base64.getEncoder().encodeToString(probeJSON.getBytes(StandardCharsets.UTF_8));
new StartupProbeTestRunner(QuickStartFeature.FULL, probeBase64).run(new TestExecStartupProbe(succKeyWord, logFile));
new StartupProbeTestRunner(QuickStartFeature.EAGER_APPCDS, probeBase64).run(new TestExecStartupProbe(succKeyWord, logFile));
}

@Override
public Project getProject() {
final String mainClass = "com.App1";
//when run with 'trace' or 'profile' role, there must sleep until the probe process
//launch other helper process execute CDS dump.
//but when run with 'replayer' role, no need wait anything.
String sourceTemplate =
"package com;\n" +
"import java.io.File;\n" +
"import java.io.FileWriter;\n" +
"public class App1{ \n" +
" public static void main(String[] args) throws Exception {\n" +
" FileWriter fw = new FileWriter(\"%s\");\n" +
" fw.write(\"%s\");\n" +
" fw.close();\n" +
" String debug = System.getProperty(\"jdk.debug\");\n" +
" int time = 15 + (debug.equals(\"release\") ? 0 : 10);\n"+
" Thread.sleep(time * 1000);\n" +
" }" +
" }";
" String role = System.getenv(\"ALIBABA_QUICKSTART_ROLE\");\n" +
" if (!\"REPLAYER\".equals(role)) {\n" +
" long startTime = System.currentTimeMillis();\n" +
" String cdsFinishFile = System.getenv(\"CDS_DUMP_FINISH_FILE\");\n" +
" System.out.println(\"CDS finish file: \" + cdsFinishFile);\n" +
" while (System.currentTimeMillis() - startTime <= 60*1000) {\n" +
" if (new File(cdsFinishFile).exists()) {\n" +
" break;\n" +
" } else {\n" +
" Thread.sleep(1*1000L);\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n";


Project project = new Project(new RunWithURLClassLoaderConf(mainClass),
Expand Down

0 comments on commit fbd63de

Please sign in to comment.