From fbd63de0026e3d1d449270ee3b7767f66b8b7cd9 Mon Sep 17 00:00:00 2001 From: "lingjun.cg" Date: Wed, 11 Oct 2023 15:25:51 +0800 Subject: [PATCH] [EagerAppCDS] Fix unstable test case TestExecStartupProbe 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: https://github.com/dragonwell-project/dragonwell11/issues/687 --- .../quickstart/StartupProbeTestRunner.java | 2 ++ .../quickstart/TestExecStartupProbe.java | 26 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/test/jdk/com/alibaba/quickstart/StartupProbeTestRunner.java b/test/jdk/com/alibaba/quickstart/StartupProbeTestRunner.java index 1e21eb1f268..4c5393224d1 100644 --- a/test/jdk/com/alibaba/quickstart/StartupProbeTestRunner.java +++ b/test/jdk/com/alibaba/quickstart/StartupProbeTestRunner.java @@ -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); diff --git a/test/jdk/com/alibaba/quickstart/TestExecStartupProbe.java b/test/jdk/com/alibaba/quickstart/TestExecStartupProbe.java index 03d60446fff..1671a3867cc 100644 --- a/test/jdk/com/alibaba/quickstart/TestExecStartupProbe.java +++ b/test/jdk/com/alibaba/quickstart/TestExecStartupProbe.java @@ -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),