diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2021-05-23 17:14:35 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2021-05-23 17:14:35 +0200 |
commit | cbf71e9b6bf517560be8288ef8449005e9445b2e (patch) | |
tree | 36fa0189aec3e804d1cd8cade8a8022b65ed0a59 /node-admin | |
parent | 3996d10f675ec994e541eaa5dfbd3f15adea6926 (diff) |
Improve error messages on unexpected test terminal command line.
Diffstat (limited to 'node-admin')
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/TestProcessFactory.java | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/TestProcessFactory.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/TestProcessFactory.java index 0586797d259..6771e0d5a27 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/TestProcessFactory.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/TestProcessFactory.java @@ -23,6 +23,8 @@ public class TestProcessFactory implements ProcessFactory { private final List<SpawnCall> expectedSpawnCalls = new ArrayList<>(); private final List<CommandLine> spawnCommandLines = new ArrayList<>(); + private boolean muteVerifyAllCommandsExecuted = false; + /** Forward call to spawn() to callback. */ public TestProcessFactory interceptSpawn(String commandDescription, Function<CommandLine, ChildProcess2> callback) { @@ -32,9 +34,10 @@ public class TestProcessFactory implements ProcessFactory { // Convenience method for the caller to avoid having to create a TestChildProcess2 instance. public TestProcessFactory expectSpawn(String commandLineString, TestChildProcess2 toReturn) { + int commandIndex = expectedSpawnCalls.size(); return interceptSpawn( commandLineString, - commandLine -> defaultSpawn(commandLine, commandLineString, toReturn)); + commandLine -> defaultSpawn(commandLine, commandLineString, toReturn, commandIndex)); } // Convenience method for the caller to avoid having to create a TestChildProcess2 instance. @@ -54,6 +57,8 @@ public class TestProcessFactory implements ProcessFactory { } public void verifyAllCommandsExecuted() { + if (muteVerifyAllCommandsExecuted) return; + if (spawnCommandLines.size() < expectedSpawnCalls.size()) { int missingCommandIndex = spawnCommandLines.size(); throw new IllegalStateException("Command #" + missingCommandIndex + @@ -81,12 +86,14 @@ public class TestProcessFactory implements ProcessFactory { return expectedSpawnCalls.get(spawnCommandLines.size() - 1).callback.apply(commandLine); } - private static ChildProcess2 defaultSpawn(CommandLine commandLine, + private ChildProcess2 defaultSpawn(CommandLine commandLine, String expectedCommandLineString, - ChildProcess2 toReturn) { + ChildProcess2 toReturn, + int commandSequenceNumber) { String actualCommandLineString = commandLine.toString(); if (!Objects.equals(actualCommandLineString, expectedCommandLineString)) { - throw new IllegalArgumentException("Expected command line '" + + muteVerifyAllCommandsExecuted = true; + throw new IllegalArgumentException("Expected command #" + commandSequenceNumber + " to be '" + expectedCommandLineString + "' but got '" + actualCommandLineString + "'"); } |