Added shutdown hook to STC to print summary even when interrupted by user.
Change-Id: I2ddb0d46ddfd776101a27ea76fe5ae34d28ddded
Showing
1 changed file
with
23 additions
and
4 deletions
... | @@ -45,7 +45,12 @@ public final class Main { | ... | @@ -45,7 +45,12 @@ public final class Main { |
45 | private static final String BLUE = "\u001B[36m"; | 45 | private static final String BLUE = "\u001B[36m"; |
46 | 46 | ||
47 | private static final String SUCCESS_SUMMARY = "%sPassed! %d steps succeeded%s"; | 47 | private static final String SUCCESS_SUMMARY = "%sPassed! %d steps succeeded%s"; |
48 | - private static final String FAILURE_SUMMARY = "%sFailed! %d steps succeeded; %d steps failed; %d steps skipped%s"; | 48 | + private static final String MIXED_SUMMARY = |
49 | + "%s%d steps succeeded; %s%d steps failed; %s%d steps skipped%s"; | ||
50 | + private static final String FAILURE_SUMMARY = "%sFailed! " + MIXED_SUMMARY; | ||
51 | + private static final String ABORTED_SUMMARY = "%sAborted! " + MIXED_SUMMARY; | ||
52 | + | ||
53 | + private boolean isReported = false; | ||
49 | 54 | ||
50 | private enum Command { | 55 | private enum Command { |
51 | LIST, RUN, RUN_RANGE, HELP | 56 | LIST, RUN, RUN_RANGE, HELP |
... | @@ -181,17 +186,20 @@ public final class Main { | ... | @@ -181,17 +186,20 @@ public final class Main { |
181 | // Runs the coordinator and waits for it to finish. | 186 | // Runs the coordinator and waits for it to finish. |
182 | private void runCoordinator() { | 187 | private void runCoordinator() { |
183 | try { | 188 | try { |
189 | + Runtime.getRuntime().addShutdownHook(new ShutdownHook()); | ||
184 | coordinator.start(); | 190 | coordinator.start(); |
185 | int exitCode = coordinator.waitFor(); | 191 | int exitCode = coordinator.waitFor(); |
186 | pause(100); // allow stdout to flush | 192 | pause(100); // allow stdout to flush |
187 | - printSummary(exitCode); | 193 | + printSummary(exitCode, false); |
188 | System.exit(exitCode); | 194 | System.exit(exitCode); |
189 | } catch (InterruptedException e) { | 195 | } catch (InterruptedException e) { |
190 | print("Unable to execute scenario %s", scenarioFile); | 196 | print("Unable to execute scenario %s", scenarioFile); |
191 | } | 197 | } |
192 | } | 198 | } |
193 | 199 | ||
194 | - private void printSummary(int exitCode) { | 200 | + private synchronized void printSummary(int exitCode, boolean isAborted) { |
201 | + if (!isReported) { | ||
202 | + isReported = true; | ||
195 | Set<Step> steps = coordinator.getSteps(); | 203 | Set<Step> steps = coordinator.getSteps(); |
196 | int count = steps.size(); | 204 | int count = steps.size(); |
197 | if (exitCode == 0) { | 205 | if (exitCode == 0) { |
... | @@ -200,7 +208,10 @@ public final class Main { | ... | @@ -200,7 +208,10 @@ public final class Main { |
200 | long success = steps.stream().filter(s -> coordinator.getStatus(s) == SUCCEEDED).count(); | 208 | long success = steps.stream().filter(s -> coordinator.getStatus(s) == SUCCEEDED).count(); |
201 | long failed = steps.stream().filter(s -> coordinator.getStatus(s) == FAILED).count(); | 209 | long failed = steps.stream().filter(s -> coordinator.getStatus(s) == FAILED).count(); |
202 | long skipped = steps.stream().filter(s -> coordinator.getStatus(s) == SKIPPED).count(); | 210 | long skipped = steps.stream().filter(s -> coordinator.getStatus(s) == SKIPPED).count(); |
203 | - print(FAILURE_SUMMARY, color(FAILED), success, failed, skipped, color(null)); | 211 | + print(isAborted ? ABORTED_SUMMARY : FAILURE_SUMMARY, |
212 | + color(FAILED), color(SUCCEEDED), success, | ||
213 | + color(FAILED), failed, color(SKIPPED), skipped, color(null)); | ||
214 | + } | ||
204 | } | 215 | } |
205 | } | 216 | } |
206 | 217 | ||
... | @@ -270,6 +281,14 @@ public final class Main { | ... | @@ -270,6 +281,14 @@ public final class Main { |
270 | } | 281 | } |
271 | } | 282 | } |
272 | 283 | ||
284 | + // Shutdown hook to report status even when aborted. | ||
285 | + private class ShutdownHook extends Thread { | ||
286 | + @Override | ||
287 | + public void run() { | ||
288 | + printSummary(1, true); | ||
289 | + } | ||
290 | + } | ||
291 | + | ||
273 | // Logger to quiet Jetty down | 292 | // Logger to quiet Jetty down |
274 | private static class NullLogger implements Logger { | 293 | private static class NullLogger implements Logger { |
275 | @Override | 294 | @Override | ... | ... |
-
Please register or login to post a comment