Skip to content

Commit c2cbdaf

Browse files
committed
Multiple issue fixes to the following features: 1) directory log uploads, 2) ExecuteCommand command parsing, 3) test framework mocks.
1 parent fb4365f commit c2cbdaf

File tree

42 files changed

+1681
-674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1681
-674
lines changed

src/VirtualClient/VirtualClient.Actions.FunctionalTests/TestDependencies.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ public static ProfileExecutor CreateProfileExecutor(string profile, IServiceColl
4646

4747
workloadProfile.Inline();
4848

49-
ProfileExecutor profileExecutor = new ProfileExecutor(workloadProfile, dependencies)
49+
ComponentSettings settings = new ComponentSettings
50+
{
51+
ExitWait = TimeSpan.Zero
52+
};
53+
54+
ProfileExecutor profileExecutor = new ProfileExecutor(workloadProfile, dependencies, settings)
5055
{
5156
ExecuteActions = !dependenciesOnly,
5257
ExecuteDependencies = true,
5358
ExecuteMonitors = !dependenciesOnly,
54-
ExitWait = TimeSpan.Zero
5559
};
5660

5761
return profileExecutor;

src/VirtualClient/VirtualClient.Actions/Network2/NetworkingWorkload2/NetworkingWorkloadProxy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ protected void OnInstructionsReceived(object sender, JObject instructions)
132132
// Create WorkloadServerExecutor
133133
VirtualClientComponent serverComponent = ComponentFactory.CreateComponent(
134134
element,
135-
this.Dependencies);
135+
this.Dependencies,
136+
new ComponentSettings(element.Parameters));
136137

137138
serverComponent.ClientRequestId = workloadInstructions.ClientRequestId;
138139

src/VirtualClient/VirtualClient.Common.UnitTests/ProcessExecutionExtensionsTests.cs renamed to src/VirtualClient/VirtualClient.Common.UnitTests/ProcessExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace VirtualClient.Common
1111

1212
[TestFixture]
1313
[Category("Unit")]
14-
internal class ProcessExecutionExtensionsTests
14+
internal class ProcessExtensionsTests
1515
{
1616
private InMemoryProcess mockProcess;
1717
private MemoryStream standardInput;

src/VirtualClient/VirtualClient.Common/Extensions/StringExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
namespace VirtualClient.Common.Extensions
55
{
66
using System;
7-
using System.Collections;
87
using System.Diagnostics.CodeAnalysis;
9-
using System.Linq;
108
using System.Runtime.InteropServices;
119
using System.Security;
1210
using System.Text.RegularExpressions;

src/VirtualClient/VirtualClient.Common/IProcessProxy.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace VirtualClient.Common
55
{
66
using System;
7+
using System.Collections.Generic;
78
using System.Collections.Specialized;
89
using System.Diagnostics;
910
using System.IO;
@@ -41,11 +42,6 @@ public interface IProcessProxy : IDisposable
4142
/// </summary>
4243
DateTime ExitTime { get; set; }
4344

44-
/// <summary>
45-
/// The underlying process details.
46-
/// </summary>
47-
ProcessDetails ProcessDetails { get; }
48-
4945
/// <summary>
5046
/// A pointer to the process module control handle.
5147
/// </summary>

src/VirtualClient/VirtualClient.Common/ProcessDetails.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
using System;
45
using System.Collections.Generic;
56

67
namespace VirtualClient.Common
@@ -20,6 +21,29 @@ public class ProcessDetails
2021
/// </summary>
2122
public string CommandLine { get; set; }
2223

24+
/// <summary>
25+
/// The amount of time elapsed between the process/operation start time
26+
/// and end time.
27+
/// </summary>
28+
public TimeSpan? ElapsedTime
29+
{
30+
get
31+
{
32+
TimeSpan? elapsedTime = null;
33+
if (this.StartTime != null && this.ExitTime != null)
34+
{
35+
elapsedTime = this.ExitTime.Value - this.StartTime.Value;
36+
}
37+
38+
return elapsedTime;
39+
}
40+
}
41+
42+
/// <summary>
43+
/// The end time for the process or operation.
44+
/// </summary>
45+
public DateTime? ExitTime { get; set; }
46+
2347
/// <summary>
2448
/// Exit code of the command executed.
2549
/// </summary>
@@ -28,7 +52,7 @@ public class ProcessDetails
2852
/// <summary>
2953
/// Generated Results of the command.
3054
/// </summary>
31-
public IEnumerable<string> GeneratedResults { get; set; }
55+
public IEnumerable<string> Results { get; set; }
3256

3357
/// <summary>
3458
/// Standard output of the command.
@@ -40,6 +64,11 @@ public class ProcessDetails
4064
/// </summary>
4165
public string StandardError { get; set; }
4266

67+
/// <summary>
68+
/// The start time for the process or operation.
69+
/// </summary>
70+
public DateTime? StartTime { get; set; }
71+
4372
/// <summary>
4473
/// Tool Name ran by command.
4574
/// </summary>

src/VirtualClient/VirtualClient.Common/ProcessExtensions.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
namespace VirtualClient.Common
55
{
66
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
79
using System.Text.RegularExpressions;
810
using System.Threading;
911
using System.Threading.Tasks;
@@ -87,6 +89,31 @@ public static async Task StartAndWaitAsync(this IProcessProxy process, Cancellat
8789
}
8890
}
8991

92+
/// <summary>
93+
/// Creates a <see cref="ProcessDetails"/> instance for the current process.
94+
/// </summary>
95+
/// <param name="process">The process from which to get the details.</param>
96+
/// <param name="toolName">The name of the tool/toolset associated with the process.</param>
97+
/// <param name="results">One or more sets of results generated by the process.</param>
98+
public static ProcessDetails ToProcessDetails(this IProcessProxy process, string toolName, IEnumerable<string> results = null)
99+
{
100+
process.ThrowIfNull(nameof(process));
101+
102+
return new ProcessDetails
103+
{
104+
Id = process.Id,
105+
CommandLine = SensitiveData.ObscureSecrets($"{process.StartInfo?.FileName} {process.StartInfo?.Arguments}".Trim()),
106+
ExitCode = process.ExitCode,
107+
Results = results,
108+
StandardError = process.StandardError?.Length > 0 ? process.StandardError.ToString() : string.Empty,
109+
StandardOutput = process.StandardOutput?.Length > 0 ? process.StandardOutput.ToString() : string.Empty,
110+
StartTime = process.StartTime,
111+
ExitTime = process.ExitTime,
112+
ToolName = toolName,
113+
WorkingDirectory = process.StartInfo?.WorkingDirectory
114+
};
115+
}
116+
90117
/// <summary>
91118
/// Waits for process to produce a response.
92119
/// </summary>

src/VirtualClient/VirtualClient.Common/ProcessProxy.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace VirtualClient.Common
88
using System.Collections.Specialized;
99
using System.Diagnostics;
1010
using System.IO;
11+
using System.Linq;
12+
using System.Text.RegularExpressions;
1113
using System.Threading;
1214
using System.Threading.Tasks;
1315
using VirtualClient.Common.Extensions;
@@ -40,7 +42,7 @@ public ProcessProxy(Process process)
4042
this.StandardError = new ConcurrentBuffer();
4143
this.StandardOutput = new ConcurrentBuffer();
4244
this.processDetails = new ProcessDetails();
43-
this.processDetails.GeneratedResults = new List<string>();
45+
this.processDetails.Results = new List<string>();
4446
}
4547

4648
/// <inheritdoc />
@@ -131,22 +133,6 @@ public bool RedirectStandardOutput
131133
}
132134
}
133135

134-
/// <inheritdoc />
135-
public ProcessDetails ProcessDetails
136-
{
137-
get
138-
{
139-
this.processDetails.Id = this.Id;
140-
this.processDetails.CommandLine = SensitiveData.ObscureSecrets($"{this.StartInfo?.FileName} {this.StartInfo?.Arguments}".Trim());
141-
this.processDetails.ExitCode = this.ExitCode;
142-
this.processDetails.StandardError = this.StandardError?.Length > 0 ? this.StandardError.ToString() : string.Empty;
143-
this.processDetails.StandardOutput = this.StandardOutput?.Length > 0 ? this.StandardOutput.ToString() : string.Empty;
144-
this.processDetails.WorkingDirectory = this.StartInfo?.WorkingDirectory;
145-
146-
return this.processDetails;
147-
}
148-
}
149-
150136
/// <inheritdoc />
151137
public ConcurrentBuffer StandardError { get; }
152138

src/VirtualClient/VirtualClient.Contracts.UnitTests/ComponentFactoryTests.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,15 @@ public void ComponentFactoryAppliesCommandLineInstructionsProvidedToComponents(s
584584
VirtualClientComponent component = ComponentFactory.CreateComponent(
585585
action,
586586
this.mockFixture.Dependencies,
587-
randomizationSeed: 123,
588-
failFast: true,
589-
logToFile: true);
587+
new ComponentSettings
588+
{
589+
FailFast = true,
590+
LogToFile = true,
591+
Seed = 123
592+
});
590593

591594
Assert.IsNotNull(component);
592-
Assert.AreEqual(123, component.ExecutionSeed);
595+
Assert.AreEqual(123, component.Seed);
593596
Assert.IsTrue(component.FailFast);
594597
Assert.IsTrue(component.LogToFile);
595598
}
@@ -607,18 +610,21 @@ public void ComponentFactoryAppliesCommandLineInstructionsProvidedToSubComponent
607610
VirtualClientComponent component = ComponentFactory.CreateComponent(
608611
action,
609612
this.mockFixture.Dependencies,
610-
randomizationSeed: 123,
611-
failFast: true,
612-
logToFile: true);
613+
new ComponentSettings
614+
{
615+
FailFast = true,
616+
LogToFile = true,
617+
Seed = 123
618+
});
613619

614620
Assert.IsNotNull(component);
615-
Assert.AreEqual(123, component.ExecutionSeed);
621+
Assert.AreEqual(123, component.Seed);
616622
Assert.IsTrue(component.FailFast);
617623
Assert.IsTrue(component.LogToFile);
618624

619625
foreach (VirtualClientComponent subComponent in component as VirtualClientComponentCollection)
620626
{
621-
Assert.AreEqual(123, subComponent.ExecutionSeed);
627+
Assert.AreEqual(123, subComponent.Seed);
622628
Assert.IsTrue(subComponent.FailFast);
623629
Assert.IsTrue(subComponent.LogToFile);
624630
}

src/VirtualClient/VirtualClient.Contracts.UnitTests/FileUploadDescriptorFactoryTests.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class FileUploadDescriptorFactoryTests
1919
private MockFixture mockFixture;
2020
private Mock<IFileInfo> mockFile;
2121

22-
public void SetupDefaults()
22+
public void Setup()
2323
{
2424
this.mockFixture = new MockFixture();
2525
this.mockFixture.Setup(PlatformID.Unix);
@@ -40,7 +40,7 @@ public void SetupDefaults()
4040
[TestCase("Agent01", "ToolA", "Scenario01", "Client")]
4141
public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptor_When_Not_Timestamped(string expectedAgentId, string expectedToolName, string expectedScenario, string expectedRole)
4242
{
43-
this.SetupDefaults();
43+
this.Setup();
4444

4545
string expectedExperimentId = Guid.NewGuid().ToString();
4646
string expectedContentType = HttpContentType.PlainText;
@@ -87,7 +87,7 @@ public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptor_When_Not_Tim
8787
[TestCase("Agent01", "ToolA", "Scenario01", "Client")]
8888
public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptor_When_Timestamped(string expectedAgentId, string expectedToolName, string expectedScenario, string expectedRole)
8989
{
90-
this.SetupDefaults();
90+
this.Setup();
9191

9292
string expectedExperimentId = Guid.NewGuid().ToString();
9393
string expectedContentType = HttpContentType.PlainText;
@@ -130,7 +130,7 @@ public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptorWithDefaultCo
130130
{
131131
// Default Template:
132132
// {experimentId}/{agentId}/{toolName}/{scenario}
133-
this.SetupDefaults();
133+
this.Setup();
134134

135135
string expectedExperimentId = Guid.NewGuid().ToString();
136136
string expectedAgentId = "Agent01";
@@ -176,7 +176,7 @@ public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptorWithDefaultCo
176176
{
177177
// Default Template:
178178
// {experimentId}/{agentId}/{toolName}/{role}/{scenario}
179-
this.SetupDefaults();
179+
this.Setup();
180180

181181
string expectedExperimentId = Guid.NewGuid().ToString();
182182
string expectedAgentId = "Agent01";
@@ -259,7 +259,7 @@ public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptorWithDefaultCo
259259
)]
260260
public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptorWithCustomContentPathTemplates(string contentPathTemplate, string expectedContainer, string expectedBlobPath)
261261
{
262-
this.SetupDefaults();
262+
this.Setup();
263263

264264
string expectedExperimentName = "Test_Experiment";
265265
string expectedExperimentId = "cfad01a9-8F5c-4210-841e-63210ed6a85d";
@@ -326,7 +326,7 @@ public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptorWithCustomCon
326326
)]
327327
public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptorWithCustomContentPathTemplatesDefinedInCommandLineMetadata(string contentPathTemplate, string expectedContainer, string expectedBlobPath)
328328
{
329-
this.SetupDefaults();
329+
this.Setup();
330330

331331
string expectedExperimentName = "Test_Experiment";
332332
string expectedExperimentId = "cfad01a9-8F5c-4210-841e-63210ed6a85d";
@@ -380,7 +380,7 @@ public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptorWithCustomCon
380380
[TestCase("contentPathTemplate")]
381381
public void FileUploadDescriptorFactoryIsNotCaseSensitiveOnContentPathTemplatesDefinedInCommandLineMetadata(string contentPathTemplateParameterName)
382382
{
383-
this.SetupDefaults();
383+
this.Setup();
384384

385385
string expectedContentPathTemplate = "customcontainer/{ExperimentDefinitionId}/{ExperimentName}/{ExperimentId},{Revision}/{AgentId}/{Scenario}/{Role}";
386386
string expectedExperimentName = "Test_Experiment";
@@ -450,7 +450,7 @@ public void FileUploadDescriptorFactoryIsNotCaseSensitiveOnContentPathTemplatesD
450450
)]
451451
public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptorWithCustomContentPathTemplatesDefinedInComponentParameters(string contentPathTemplate, string expectedContainer, string expectedBlobPath)
452452
{
453-
this.SetupDefaults();
453+
this.Setup();
454454

455455
string expectedExperimentName = "Test_Experiment";
456456
string expectedExperimentId = "cfad01a9-8F5c-4210-841e-63210ed6a85d";
@@ -512,7 +512,7 @@ public void FileUploadDescriptorFactoryCreatesTheExpectedDescriptorWithCustomCon
512512
)]
513513
public void FileUploadDescriptorFactoryCreatesBlobPathsWithTheExpectedCasing(string contentPathTemplate, string expectedContainer, string expectedBlobPath)
514514
{
515-
this.SetupDefaults();
515+
this.Setup();
516516

517517
string expectedContentType = HttpContentType.PlainText;
518518
string expectedContentEncoding = Encoding.UTF8.WebName;
@@ -548,7 +548,7 @@ public void FileUploadDescriptorFactoryCreatesBlobPathsWithTheExpectedCasing(str
548548
[TestCase("{ThisDoesNotExist}")]
549549
public void FileUploadDescriptorFactoryValidatesTheContentPath(string invalidContentPathTemplate)
550550
{
551-
this.SetupDefaults();
551+
this.Setup();
552552

553553
FileContext context = new FileContext(
554554
this.mockFile.Object,
@@ -567,7 +567,7 @@ public void FileUploadDescriptorFactoryValidatesTheContentPath(string invalidCon
567567
[Test]
568568
public void FileUploadDescriptorFactorySupportsEitherOrPathTemplateDefinitions_1()
569569
{
570-
this.SetupDefaults();
570+
this.Setup();
571571

572572
string expectedContainerName = "customcontainer";
573573
string expectedExperimentName = "Test_Experiment";
@@ -624,7 +624,7 @@ public void FileUploadDescriptorFactorySupportsEitherOrPathTemplateDefinitions_1
624624
[Test]
625625
public void FileUploadDescriptorFactorySupportsEitherOrPathTemplateDefinitions_2()
626626
{
627-
this.SetupDefaults();
627+
this.Setup();
628628

629629
string expectedContainerName = "customcontainer";
630630
string expectedExperimentName = "Test_Experiment";
@@ -678,7 +678,7 @@ public void FileUploadDescriptorFactorySupportsEitherOrPathTemplateDefinitions_2
678678
[Test]
679679
public void FileUploadDescriptorFactoryHandlesCasesWhereTheTemplateReferencesAParameterThatDoesNotExist()
680680
{
681-
this.SetupDefaults();
681+
this.Setup();
682682

683683
string expectedContainerName = "customcontainer";
684684
string expectedExperimentName = "Test_Experiment";

0 commit comments

Comments
 (0)