Skip to content

Commit b7ff5b5

Browse files
committed
Messy parallellisation
1 parent a060e65 commit b7ff5b5

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed

source/Octopus.Tentacle.Tests.Integration/TentacleCommandLineTests.cs

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -281,40 +281,35 @@ public async Task HelpForInstanceSpecificCommandsAlwaysWorks(TentacleConfigurati
281281
stdout,
282282
new
283283
{
284-
Commands = new[]
284+
Commands = new TentacleCommand[]
285285
{
286-
new
286+
new()
287287
{
288288
Name = "",
289289
Description = "",
290-
Aliases = new string[0]
290+
Aliases = Array.Empty<string>()
291291
}
292292
}
293293
});
294294

295295
help.Commands.Should().HaveCountGreaterThan(0);
296296

297-
var failed = help.Commands.Select(async c =>
298-
{
299-
var (exitCode2, stdout2, stderr2) = await RunCommand(tc, null,$"{c.Name}", "--help");
300-
return new
301-
{
302-
Command = c,
303-
ExitCode = exitCode2,
304-
StdOut = stdout2,
305-
StdErr = stderr2,
306-
HasExpectedExitCode = exitCode2 == 0,
307-
HasExpectedHelpMessage = stdout2.StartsWith($"Usage: Tentacle {c.Name} [<options>]")
308-
};
309-
})
310-
.Where(r => !(r.Result.HasExpectedExitCode && r.Result.HasExpectedHelpMessage))
311-
.ToArray();
312-
313-
if (failed.Any())
297+
List<Task<CommandReturnValue>> commandResults = new List<Task<CommandReturnValue>>();
298+
299+
foreach (var command in help.Commands)
300+
{
301+
commandResults.Add(GetCommandReturnValue(tc, command));
302+
}
303+
304+
Task.WaitAll(commandResults.ToArray());
305+
306+
Task<CommandReturnValue>[] failedCommands = commandResults.Where(r => !(r.Result.HasExpectedExitCode && r.Result.HasExpectedHelpMessage)).ToArray();
307+
308+
if (failedCommands.Any())
314309
{
315310
var failureDetails = string.Empty;
316311

317-
foreach (var failure in failed)
312+
foreach (var failure in failedCommands)
318313
{
319314
failureDetails += $@"{failure.Result.Command.Name}
320315
StdErr:{failure.Result.StdErr}
@@ -327,6 +322,37 @@ public async Task HelpForInstanceSpecificCommandsAlwaysWorks(TentacleConfigurati
327322
The details are logged above. These commands probably need to take Lazy<T> dependencies so they can be instantiated for showing help without requiring every dependency to be resolvable.");
328323
}
329324
}
325+
326+
async Task<CommandReturnValue> GetCommandReturnValue(TentacleConfigurationTestCase tc, TentacleCommand c)
327+
{
328+
var (exitCode2, stdout2, stderr2) = await RunCommand(tc, null,$"{c.Name}", "--help");
329+
return new CommandReturnValue
330+
{
331+
Command = c,
332+
ExitCode = exitCode2,
333+
StdOut = stdout2,
334+
StdErr = stderr2,
335+
HasExpectedExitCode = exitCode2 == 0,
336+
HasExpectedHelpMessage = stdout2.StartsWith($"Usage: Tentacle {c.Name} [<options>]")
337+
};
338+
}
339+
340+
class TentacleCommand
341+
{
342+
public string Name { get; set; }
343+
public string Description { get; set; }
344+
public string[] Aliases { get; set; }
345+
}
346+
347+
class CommandReturnValue
348+
{
349+
public TentacleCommand Command { get; set; }
350+
public int ExitCode { get; set; }
351+
public string StdOut { get; set; }
352+
public string StdErr { get; set; }
353+
public bool HasExpectedExitCode { get; set; }
354+
public bool HasExpectedHelpMessage { get; set; }
355+
}
330356

331357
[Test]
332358
[TentacleConfigurations(scriptServiceToTest: ScriptServiceVersionToTest.None)]

0 commit comments

Comments
 (0)