Skip to content

Commit

Permalink
- force shutdown advisor to be utilized in interactive mode as well
Browse files Browse the repository at this point in the history
Signed-off-by: automike <[email protected]>
  • Loading branch information
mikeliucc committed Nov 13, 2018
1 parent 70f643a commit 5b6a59a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 43 deletions.
82 changes: 39 additions & 43 deletions src/main/java/org/nexial/core/Nexial.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,45 +216,37 @@ public static void main(String[] args) {
System.exit(-1);
}

// integration mode, only for metrics and post-exec analysis
if (main.isIntegrationMode()) { return; }
ExecutionSummary summary = null;
try {
// integration mode, only for metrics and post-exec analysis
if (main.isIntegrationMode()) { return; }

// listen mode, only for studio integration
if (main.isListenMode()) {
try {
// listen mode, only for studio integration
if (main.isListenMode()) {
main.listen();
ConsoleUtils.log("Nexial Services ready...");
} catch (Throwable e) {
e.printStackTrace();
return;
}
return;
}

// interactive mode, only for stepwise or blockwise execution. to be integrated into studio
if (main.isInteractiveMode()) {
try {
// interactive mode, only for stepwise or blockwise execution. to be integrated into studio
if (main.isInteractiveMode()) {
main.interact();
} catch (Throwable e) {
ConsoleUtils.error("Unknown/unexpected error occurred: " + e.getMessage());
e.printStackTrace();
return;
}
return;
}

// normal execution
ExecutionSummary summary = null;
try {
// normal execution
MemManager.recordMemoryChanges("before execution");
summary = main.execute();
main.trackEvent(new NexialExecutionCompleteEvent(summary));
MemManager.recordMemoryChanges("after execution");

} catch (Throwable e) {
ConsoleUtils.error("Unknown/unexpected error occurred: " + e.getMessage());
e.printStackTrace();
} finally {
ConsoleUtils.log("Exiting Nexial...");
System.exit(main.beforeShutdown(summary));
}

ConsoleUtils.log("Exiting Nexial...");
System.exit(beforeShutdown(summary));
}

protected void listen() throws Exception { ServiceLauncher.main(new String[]{}); }
Expand Down Expand Up @@ -978,11 +970,14 @@ private List<String> resolveScenarios(CommandLine cmd, Excel script) {
return targetScenarios;
}

private static int beforeShutdown(ExecutionSummary summary) {
private int beforeShutdown(ExecutionSummary summary) {
// need to kill JVM forcefully if awt was used during runtime
// -- haven't found a way to do this more gracefully yet...
if (ShutdownAdvisor.mustForcefullyTerminate()) { ShutdownAdvisor.forcefullyTerminate(); }

if (isIntegrationMode() || isListenMode() || isInteractiveMode()) { return 0; }

// only for normal execution mode
int exitStatus;
if (summary == null) {
ConsoleUtils.error("Unable to cleanly execute tests; execution summary missing!");
Expand Down Expand Up @@ -1035,25 +1030,26 @@ private static int beforeShutdown(ExecutionSummary summary) {
}
}

File eventPath = new File(EventTracker.INSTANCE.getStorageLocation());
if (FileUtil.isDirectoryReadable(eventPath)) {
String[] ext = new String[]{StringUtils.removeStart(EventTracker.INSTANCE.getExtension(), ".")};
Collection<File> eventFiles = FileUtils.listFiles(eventPath, ext, false);
long sleepTime = 500;
while (CollectionUtils.isNotEmpty(eventFiles)) {
// don't sleep too long... 5 sec tops
if (sleepTime > 5000) { break; }

// sleep/wait
try { Thread.sleep(sleepTime);} catch (InterruptedException e) { }

// next sleep time will be doubled
sleepTime += sleepTime;

// check for event files again...
eventFiles = FileUtils.listFiles(eventPath, ext, false);
}
}
// not used at this time
// File eventPath = new File(EventTracker.INSTANCE.getStorageLocation());
// if (FileUtil.isDirectoryReadable(eventPath)) {
// String[] ext = new String[]{StringUtils.removeStart(EventTracker.INSTANCE.getExtension(), ".")};
// Collection<File> eventFiles = FileUtils.listFiles(eventPath, ext, false);
// long sleepTime = 500;
// while (CollectionUtils.isNotEmpty(eventFiles)) {
// // don't sleep too long... 5 sec tops
// if (sleepTime > 5000) { break; }
//
// // sleep/wait
// try { Thread.sleep(sleepTime);} catch (InterruptedException e) { }
//
// // next sleep time will be doubled
// sleepTime += sleepTime;
//
// // check for event files again...
// eventFiles = FileUtils.listFiles(eventPath, ext, false);
// }
// }

beforeShutdownMemUsage();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ protected boolean executeActivities(InteractiveSession session, ExecutionSummary
}
}

parentSummary.aggregatedNestedExecutions(context);
return allPass;
}

Expand Down

0 comments on commit 5b6a59a

Please sign in to comment.