Thomas Vachuska

Added tracking of test run duration.

Change-Id: Ideeb01b8d822a90433aad4b90ebb6fb479759a1a
...@@ -109,6 +109,15 @@ public class Coordinator { ...@@ -109,6 +109,15 @@ public class Coordinator {
109 } 109 }
110 110
111 /** 111 /**
112 + * Returns number of milliseconds it took to execute.
113 + *
114 + * @return number of millis elapsed during the run
115 + */
116 + public long duration() {
117 + return store.endTime() - store.startTime();
118 + }
119 +
120 + /**
112 * Returns a list of steps that match the specified list of patterns. 121 * Returns a list of steps that match the specified list of patterns.
113 * 122 *
114 * @param runToPatterns list of patterns 123 * @param runToPatterns list of patterns
......
...@@ -44,11 +44,12 @@ public final class Main { ...@@ -44,11 +44,12 @@ public final class Main {
44 private static final String GREEN = "\u001B[32;1m"; 44 private static final String GREEN = "\u001B[32;1m";
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 =
48 + "%s %sPassed! %d steps succeeded%s";
48 private static final String MIXED_SUMMARY = 49 private static final String MIXED_SUMMARY =
49 "%s%d steps succeeded; %s%d steps failed; %s%d steps skipped%s"; 50 "%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 FAILURE_SUMMARY = "%s %sFailed! " + MIXED_SUMMARY;
51 - private static final String ABORTED_SUMMARY = "%sAborted! " + MIXED_SUMMARY; 52 + private static final String ABORTED_SUMMARY = "%s %sAborted! " + MIXED_SUMMARY;
52 53
53 private boolean isReported = false; 54 private boolean isReported = false;
54 55
...@@ -180,6 +181,7 @@ public final class Main { ...@@ -180,6 +181,7 @@ public final class Main {
180 private void processList() { 181 private void processList() {
181 coordinator.getRecords() 182 coordinator.getRecords()
182 .forEach(event -> logStatus(event.time(), event.name(), event.status(), event.command())); 183 .forEach(event -> logStatus(event.time(), event.name(), event.status(), event.command()));
184 + printSummary(0, false);
183 System.exit(0); 185 System.exit(0);
184 } 186 }
185 187
...@@ -201,14 +203,15 @@ public final class Main { ...@@ -201,14 +203,15 @@ public final class Main {
201 if (!isReported) { 203 if (!isReported) {
202 isReported = true; 204 isReported = true;
203 Set<Step> steps = coordinator.getSteps(); 205 Set<Step> steps = coordinator.getSteps();
206 + String duration = formatDuration((int) (coordinator.duration() / 1_000));
204 int count = steps.size(); 207 int count = steps.size();
205 if (exitCode == 0) { 208 if (exitCode == 0) {
206 - print(SUCCESS_SUMMARY, color(SUCCEEDED), count, color(null)); 209 + print(SUCCESS_SUMMARY, duration, color(SUCCEEDED), count, color(null));
207 } else { 210 } else {
208 long success = steps.stream().filter(s -> coordinator.getStatus(s) == SUCCEEDED).count(); 211 long success = steps.stream().filter(s -> coordinator.getStatus(s) == SUCCEEDED).count();
209 long failed = steps.stream().filter(s -> coordinator.getStatus(s) == FAILED).count(); 212 long failed = steps.stream().filter(s -> coordinator.getStatus(s) == FAILED).count();
210 long skipped = steps.stream().filter(s -> coordinator.getStatus(s) == SKIPPED).count(); 213 long skipped = steps.stream().filter(s -> coordinator.getStatus(s) == SKIPPED).count();
211 - print(isAborted ? ABORTED_SUMMARY : FAILURE_SUMMARY, 214 + print(isAborted ? ABORTED_SUMMARY : FAILURE_SUMMARY, duration,
212 color(FAILED), color(SUCCEEDED), success, 215 color(FAILED), color(SUCCEEDED), success,
213 color(FAILED), failed, color(SKIPPED), skipped, color(null)); 216 color(FAILED), failed, color(SKIPPED), skipped, color(null));
214 } 217 }
...@@ -281,6 +284,17 @@ public final class Main { ...@@ -281,6 +284,17 @@ public final class Main {
281 } 284 }
282 } 285 }
283 286
287 + // Formats time duration
288 + private static String formatDuration(int totalSeconds) {
289 + int seconds = totalSeconds % 60;
290 + int totalMinutes = totalSeconds / 60;
291 + int minutes = totalMinutes % 60;
292 + int hours = totalMinutes / 60;
293 + return hours > 0 ?
294 + String.format("%d:%02d:%02d", hours, minutes, seconds) :
295 + String.format("%d:%02d", minutes, seconds);
296 + }
297 +
284 // Shutdown hook to report status even when aborted. 298 // Shutdown hook to report status even when aborted.
285 private class ShutdownHook extends Thread { 299 private class ShutdownHook extends Thread {
286 @Override 300 @Override
......
...@@ -43,6 +43,9 @@ class ScenarioStore { ...@@ -43,6 +43,9 @@ class ScenarioStore {
43 private final List<StepEvent> events = Lists.newArrayList(); 43 private final List<StepEvent> events = Lists.newArrayList();
44 private final Map<String, Status> statusMap = Maps.newConcurrentMap(); 44 private final Map<String, Status> statusMap = Maps.newConcurrentMap();
45 45
46 + private long startTime = Long.MAX_VALUE;
47 + private long endTime = Long.MIN_VALUE;
48 +
46 /** 49 /**
47 * Creates a new scenario store for the specified process flow. 50 * Creates a new scenario store for the specified process flow.
48 * 51 *
...@@ -69,6 +72,8 @@ class ScenarioStore { ...@@ -69,6 +72,8 @@ class ScenarioStore {
69 PropertiesConfiguration cfg = new PropertiesConfiguration(storeFile); 72 PropertiesConfiguration cfg = new PropertiesConfiguration(storeFile);
70 cfg.clear(); 73 cfg.clear();
71 cfg.save(); 74 cfg.save();
75 + startTime = Long.MAX_VALUE;
76 + endTime = Long.MIN_VALUE;
72 } catch (ConfigurationException e) { 77 } catch (ConfigurationException e) {
73 print("Unable to store file %s", storeFile); 78 print("Unable to store file %s", storeFile);
74 } 79 }
...@@ -156,6 +161,8 @@ class ScenarioStore { ...@@ -156,6 +161,8 @@ class ScenarioStore {
156 private synchronized void add(StepEvent event) { 161 private synchronized void add(StepEvent event) {
157 events.add(event); 162 events.add(event);
158 statusMap.put(event.name(), event.status()); 163 statusMap.put(event.name(), event.status());
164 + startTime = Math.min(startTime, event.time());
165 + endTime = Math.max(endTime, event.time());
159 } 166 }
160 167
161 /** 168 /**
...@@ -198,4 +205,22 @@ class ScenarioStore { ...@@ -198,4 +205,22 @@ class ScenarioStore {
198 } 205 }
199 } 206 }
200 207
208 + /**
209 + * Returns the scenario run start time.
210 + *
211 + * @return start time in mills since start of epoch
212 + */
213 + public long startTime() {
214 + return startTime;
215 + }
216 +
217 + /**
218 + * Returns the scenario run end time or current time if the scenario
219 + * is still running.
220 + *
221 + * @return end time (or current time) in mills since start of epoch
222 + */
223 + public long endTime() {
224 + return endTime > 0 ? endTime : System.currentTimeMillis();
225 + }
201 } 226 }
......