Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 963be98

Browse files
committed
Merge pull request #2404 from Priya91/processbug
BugFix: Process tests were accessing Modules when the process hasn't been loaded yet
2 parents 6d93e0e + 3d63514 commit 963be98

File tree

3 files changed

+25
-31
lines changed

3 files changed

+25
-31
lines changed

src/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests/ProcessTests.cs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.IO.Pipes;
88
using System.Linq;
99
using System.Runtime.InteropServices;
10+
using System.Threading;
1011
using Xunit;
1112

1213
namespace System.Diagnostics.ProcessTests
@@ -190,34 +191,25 @@ public void TestMachineName()
190191
[Fact]
191192
public void TestMainModule()
192193
{
193-
// Get MainModule property from a Process object
194-
ProcessModule mainModule = _process.MainModule;
195-
196-
if (!global::Interop.IsOSX) // OS X doesn't currently implement modules support
194+
// Module support is not enabled on OSX
195+
if (global::Interop.IsOSX)
197196
{
198-
Assert.NotNull(mainModule);
197+
Assert.Null(_process.MainModule);
198+
Assert.Equal(0, _process.Modules.Count);
199+
return;
199200
}
200201

201-
if (mainModule != null)
202-
{
203-
Assert.Equal(CoreRunName, Path.GetFileNameWithoutExtension(mainModule.ModuleName));
202+
// Ensure the process has loaded the modules.
203+
Assert.True(SpinWait.SpinUntil(() => _process.Modules.Count > 0, WaitInMS));
204204

205-
// Check that the mainModule is present in the modules list.
206-
bool foundMainModule = false;
207-
if (_process.Modules != null)
208-
{
209-
foreach (ProcessModule pModule in _process.Modules)
210-
{
211-
if (String.Equals(Path.GetFileNameWithoutExtension(pModule.ModuleName), CoreRunName, StringComparison.OrdinalIgnoreCase))
212-
{
213-
foundMainModule = true;
214-
break;
215-
}
216-
}
217-
218-
Assert.True(foundMainModule, "Could not found Module " + mainModule.ModuleName);
219-
}
220-
}
205+
// Get MainModule property from a Process object
206+
ProcessModule mainModule = _process.MainModule;
207+
Assert.NotNull(mainModule);
208+
Assert.Equal(CoreRunName, Path.GetFileNameWithoutExtension(mainModule.ModuleName));
209+
210+
// Check that the mainModule is present in the modules list.
211+
IEnumerable<string> processModuleNames = _process.Modules.Cast<ProcessModule>().Select(p => Path.GetFileNameWithoutExtension(p.ModuleName));
212+
Assert.Contains(CoreRunName, processModuleNames);
221213
}
222214

223215
[Fact]
@@ -372,17 +364,17 @@ public void TestProcessorTime()
372364
[Fact]
373365
public void TestProcessStartTime()
374366
{
375-
DateTime timeBeforeCreatingProcess = DateTime.UtcNow;
376367
Process p = CreateProcessInfinite();
377368
try
378369
{
379370
p.Start();
380-
Assert.True(timeBeforeCreatingProcess <= p.StartTime.ToUniversalTime(), "Process StartTime is lesser than previous time.");
371+
Assert.True(p.StartTime.ToUniversalTime() <= DateTime.UtcNow, string.Format("Process StartTime is larger than later time."));
381372
}
382373
finally
383374
{
384375
if (!p.HasExited)
385376
p.Kill();
377+
386378
Assert.True(p.WaitForExit(WaitInMS));
387379
}
388380
}

src/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"System.Security.SecureString": "4.0.0-beta-*",
1515
"System.Text.Encoding": "4.0.10-beta-*",
1616
"System.Text.Encoding.CodePages": "4.0.0-beta-*",
17+
"System.Threading": "4.0.10-beta-*",
1718
"System.Threading.Tasks": "4.0.10-beta-*",
1819
"System.Threading.Thread": "4.0.0-beta-*",
1920
"System.Threading.ThreadPool": "4.0.10-beta-*",

src/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests/project.lock.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@
413413
"lib/portable-net45+aspnetcore50+win+wpa81+wp80/xunit.core.dll": {}
414414
}
415415
},
416-
"xunit.netcore.extensions/1.0.0-prerelease-00056": {
416+
"xunit.netcore.extensions/1.0.0-prerelease-00058": {
417417
"dependencies": {
418418
"System.Diagnostics.Debug": "4.0.10-beta-22703",
419419
"System.IO": "4.0.10-beta-22703",
@@ -1207,11 +1207,11 @@
12071207
"lib/portable-net45+aspnetcore50+win+wpa81+wp80/xunit.runner.utility.xml"
12081208
]
12091209
},
1210-
"xunit.netcore.extensions/1.0.0-prerelease-00056": {
1211-
"sha512": "UPxtAjxht7LkVoI6njl23cSXiNtPjM0zT9ouhtS0Ju3bXDSUfWjT3i4vRx8f7xrV24AOdbLfxVETP8DapKHClw==",
1210+
"xunit.netcore.extensions/1.0.0-prerelease-00058": {
1211+
"sha512": "RBvpUtoMBeqXYDI+QXt4TIFMBFV3he+KPsTfyAuAiHtqwsrkJoxsA3gF7doOOpKKJ4QKtt7d1YBD3mLusLyveQ==",
12121212
"files": [
1213-
"xunit.netcore.extensions.1.0.0-prerelease-00056.nupkg",
1214-
"xunit.netcore.extensions.1.0.0-prerelease-00056.nupkg.sha512",
1213+
"xunit.netcore.extensions.1.0.0-prerelease-00058.nupkg",
1214+
"xunit.netcore.extensions.1.0.0-prerelease-00058.nupkg.sha512",
12151215
"xunit.netcore.extensions.nuspec",
12161216
"lib/portable-wpa80+win80+net45+aspnetcore50/Xunit.NetCore.Extensions.dll"
12171217
]
@@ -1249,6 +1249,7 @@
12491249
"System.Security.SecureString >= 4.0.0-beta-*",
12501250
"System.Text.Encoding >= 4.0.10-beta-*",
12511251
"System.Text.Encoding.CodePages >= 4.0.0-beta-*",
1252+
"System.Threading >= 4.0.10-beta-*",
12521253
"System.Threading.Tasks >= 4.0.10-beta-*",
12531254
"System.Threading.Thread >= 4.0.0-beta-*",
12541255
"System.Threading.ThreadPool >= 4.0.10-beta-*",

0 commit comments

Comments
 (0)