Fixing a few STC glitches.

Change-Id: I38c0a81911e392be0d6e1d392511456b57acf16c
diff --git a/utils/stc/src/main/java/org/onlab/stc/Coordinator.java b/utils/stc/src/main/java/org/onlab/stc/Coordinator.java
index 23c25bd..8e3aad5 100644
--- a/utils/stc/src/main/java/org/onlab/stc/Coordinator.java
+++ b/utils/stc/src/main/java/org/onlab/stc/Coordinator.java
@@ -83,7 +83,7 @@
         this.logDir = logDir;
         this.store = new ScenarioStore(processFlow, logDir, scenario.name());
         this.delegate = new Delegate();
-        this.latch = new CountDownLatch(store.getSteps().size());
+        this.latch = new CountDownLatch(1);
     }
 
     /**
@@ -349,7 +349,9 @@
             store.markComplete(step, status);
             listeners.forEach(listener -> listener.onCompletion(step, status));
             executeSucessors(step);
-            latch.countDown();
+            if (store.isComplete()) {
+                latch.countDown();
+            }
         }
 
         @Override
diff --git a/utils/stc/src/main/java/org/onlab/stc/Main.java b/utils/stc/src/main/java/org/onlab/stc/Main.java
index 310c96e..b615890 100644
--- a/utils/stc/src/main/java/org/onlab/stc/Main.java
+++ b/utils/stc/src/main/java/org/onlab/stc/Main.java
@@ -157,27 +157,26 @@
 
     // Processes the scenario 'run' command.
     private void processRun() {
-        try {
-            coordinator.reset();
-            coordinator.start();
-            int exitCode = coordinator.waitFor();
-            pause(100); // allow stdout to flush
-            System.exit(exitCode);
-        } catch (InterruptedException e) {
-            print("Unable to execute scenario %s", scenarioFile);
-        }
+        coordinator.reset();
+        runCoordinator();
+    }
+
+    // Processes the scenario 'run' command for range of steps.
+    private void processRunRange() {
+        coordinator.reset(list(runFromPatterns), list(runToPatterns));
+        runCoordinator();
     }
 
     // Processes the scenario 'list' command.
     private void processList() {
         coordinator.getRecords()
                 .forEach(event -> logStatus(event.time(), event.name(), event.status(), event.command()));
+        System.exit(0);
     }
 
-    // Processes the scenario 'run' command for range of steps.
-    private void processRunRange() {
+    // Runs the coordinator and waits for it to finish.
+    private void runCoordinator() {
         try {
-            coordinator.reset(list(runFromPatterns), list(runToPatterns));
             coordinator.start();
             int exitCode = coordinator.waitFor();
             pause(100); // allow stdout to flush
diff --git a/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java b/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java
index 80fa4f4..d37222b 100644
--- a/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java
+++ b/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java
@@ -125,6 +125,16 @@
     }
 
     /**
+     * Returns true if all steps in the store have been marked as completed
+     * regardless of the completion status.
+     *
+     * @return true if all steps completed one way or another
+     */
+    synchronized boolean isComplete() {
+        return !statusMap.values().stream().anyMatch(s -> s == WAITING || s == IN_PROGRESS);
+    }
+
+    /**
      * Indicates whether there are any failures.
      *
      * @return true if there are failed steps