From d4a6419783a9317edc0244fc867a5b5b23e50f1f Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 4 Apr 2024 16:05:48 +0100 Subject: [PATCH] JAL-4059 Fixed macOS timeoutscheduler and revert to --timeout for other OSes --- build.gradle | 77 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/build.gradle b/build.gradle index 94eed44..94d143e 100644 --- a/build.gradle +++ b/build.gradle @@ -3454,21 +3454,6 @@ task jalviewjsTransferUnzipLib(type: Copy) { zipFiles.each { file_zip -> from zipTree(file_zip) - // rename files in jsmol/j2s/... to swingjs/j2s/... - /* - if (file_zip.getName().startsWith("Jmol-j2s-site")) { - eachFile { fcd -> - // jsmol/... -> swingjs/... - def relPathSegments = fcd.relativePath.getSegments() - if (relPathSegments[0] == "jsmol") { - def newRelPathSegments = relPathSegments - newRelPathSegments[0] = "swingjs" - fcd.relativePath = new RelativePath(true, newRelPathSegments) - } - } - } - */ - // The following replace() is needed due to a mismatch in Jmol calls to // colorPtToFFRGB$javajs_util_T3d when only colorPtToFFRGB$javajs_util_T3 is defined // in the SwingJS.zip (github or the one distributed with JSmol) @@ -4018,7 +4003,7 @@ def jalviewjsCallCore(String name, FileCollection list, String prefixFile, Strin } -task jalviewjsBuildAllCores { +task jalviewjsBuildCore { group "JalviewJS" description "Build the core js lib closures listed in the classlists dir" dependsOn jalviewjsTransferSiteMergeDirs @@ -4045,8 +4030,7 @@ task jalviewjsBuildAllCores { ] } - // _jmol and _jalview cores. Add any other peculiar classlist.txt files here - //classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jmol}"), 'name': "_jvjmol" ] + // _jalview core classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jalview}"), 'name': jalviewjsJalviewCoreName ] jalviewjsCoreClasslists = [] @@ -4091,7 +4075,7 @@ task jalviewjsBuildAllCores { def logOutFile = file("${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_closure_stdout}") logOutFile.getParentFile().mkdirs() logOutFile.createNewFile() - logOutFile.write(getDate("yyyy-MM-dd HH:mm:ss")+" jalviewjsBuildAllCores\n----\n") + logOutFile.write(getDate("yyyy-MM-dd HH:mm:ss")+" jalviewjsBuildCore\n----\n") jalviewjsCoreClasslists.each { jalviewjsCallCore(it.name, it.list, prefixFile, suffixFile, it.jsfile, it.zjsfile, logOutFile, jalviewjs_j2s_to_console.equals("true")) @@ -4127,7 +4111,7 @@ def jalviewjsPublishCoreTemplate(String coreName, String templateName, File inpu task jalviewjsPublishCoreTemplates { - dependsOn jalviewjsBuildAllCores + dependsOn jalviewjsBuildCore def inputFileName = "${jalviewDir}/${j2s_coretemplate_html}" def inputFile = file(inputFileName) @@ -4151,7 +4135,7 @@ task jalviewjsPublishCoreTemplates { task jalviewjsSyncCore (type: Sync) { - dependsOn jalviewjsBuildAllCores + dependsOn jalviewjsBuildCore dependsOn jalviewjsPublishCoreTemplates def inputDir = file("${jalviewDir}/${jalviewjsTransferSiteCoreDir}") @@ -4559,9 +4543,10 @@ task jalviewjsLaunchTest { execStdout = stdout execStderr = stderr } - // macOS not running properly with timeout arguments - def execArgs = macOS ? [] : [ + // macOS seems okay now with timeout arguments + def execArgs = [ "--virtual-time-budget=${timeoutms}", + "--timeout=${timeoutms}", ] execArgs += [ "--no-sandbox", // --no-sandbox IS USED BY THE THORIUM APPIMAGE ON THE BUILDSERVER @@ -4573,21 +4558,23 @@ task jalviewjsLaunchTest { "--enable-logging=stderr", "file://${jalviewDirAbsolutePath}/${jalviewjsStderrLaunchFilename}" ] - - if (true || macOS) { - ScheduledExecutorService executor = Executors.newScheduledThreadPool(3); - Future f1 = executor.submit( - () -> { - exec { - standardOutput = execStdout - errorOutput = execStderr - executable(chromiumBinary) - args(execArgs) - println "COMMAND: '"+commandLine.join(" ")+"'" - } - executor.shutdownNow() + + java.lang.Runnable runChrome = () -> { + exec { + standardOutput = execStdout + errorOutput = execStderr + executable(chromiumBinary) + args(execArgs) + println "COMMAND: '"+commandLine.join(" ")+"'" } - ) + executor.shutdownNow() + } + + if (macOS) { + // we create our own timeout executor as --timeout doesn't work on macOS + ScheduledExecutorService executor = Executors.newScheduledThreadPool(3); + + Future f1 = executor.submit( runChrome ) def noChangeBytes = 0 def noChangeIterations = 0 @@ -4596,10 +4583,10 @@ task jalviewjsLaunchTest { String stderrString = stderr.toString() // shutdown the task if we have a success string if (stderrString.contains(jalviewjs_desktop_init_string)) { - f1.cancel() - Thread.sleep(1000) + f1.cancel(true) + Thread.sleep(100) executor.shutdownNow() - } + } else // if no change in stderr for 10s then also end if (noChangeIterations >= jalviewjs_chromium_idle_timeout) { executor.shutdownNow() @@ -4611,17 +4598,21 @@ task jalviewjsLaunchTest { noChangeIterations = 0 } }, - 1, 1, TimeUnit.SECONDS) + 200, 200, TimeUnit.MILLISECONDS) executor.schedule(new Runnable(){ public void run(){ - f1.cancel() + f1.cancel(true) executor.shutdownNow() } }, timeoutms, TimeUnit.MILLISECONDS) - executor.awaitTermination(timeoutms+10000, TimeUnit.MILLISECONDS) + executor.awaitTermination(timeoutms+200, TimeUnit.MILLISECONDS) + f1.cancel(true) executor.shutdownNow() + } else { + // just run chrome and rely on --virtual-time-budget and --timeout + runChrome.run() } } -- 1.7.10.2