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

Commit ba678d3

Browse files
committed
Merge pull request #2513 from Priya91/pbugfix
BugFix: Attempt fix for process tests failing in CI environment.
2 parents 50ba714 + df1f445 commit ba678d3

File tree

3 files changed

+29
-54
lines changed

3 files changed

+29
-54
lines changed

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using Xunit;
88
using System.Threading;
9+
using System.ComponentModel;
910

1011
namespace System.Diagnostics.ProcessTests
1112
{
@@ -14,30 +15,17 @@ public class ProcessModuleTests : ProcessTestBase
1415
[Fact, PlatformSpecific(~PlatformID.OSX)]
1516
public void TestModulePropertiesExceptOnOSX()
1617
{
17-
string fileName = CoreRunName;
18-
if (global::Interop.IsWindows)
19-
fileName = string.Format("{0}.exe", CoreRunName);
20-
21-
// Ensure the process has loaded the modules.
22-
Assert.True(SpinWait.SpinUntil(() =>
23-
{
24-
if (_process.Modules.Count > 0)
25-
return true;
26-
_process.Refresh();
27-
return false;
28-
}, WaitInMS));
29-
30-
ProcessModuleCollection moduleCollection = _process.Modules;
18+
ProcessModuleCollection moduleCollection = Process.GetCurrentProcess().Modules;
3119
Assert.True(moduleCollection.Count > 0);
3220

33-
ProcessModule coreRunModule = _process.MainModule;
34-
Assert.True(coreRunModule.BaseAddress.ToInt64() > 0);
35-
Assert.True(coreRunModule.EntryPointAddress.ToInt64() >= 0);
36-
Assert.Equal(fileName, coreRunModule.ModuleName);
37-
Assert.True(coreRunModule.ModuleMemorySize > 0);
38-
Assert.EndsWith(fileName, coreRunModule.FileName);
39-
40-
Assert.Equal(string.Format("System.Diagnostics.ProcessModule ({0})", fileName), coreRunModule.ToString());
21+
for (int i = 0; i < moduleCollection.Count; i++)
22+
{
23+
Assert.True(moduleCollection[i].BaseAddress.ToInt64() > 0);
24+
// From MSDN: Due to changes in the way that Windows loads assemblies,
25+
// EntryPointAddress will always return 0 on Windows 8 or Windows 8.1 and should not be relied on for those platforms.
26+
Assert.True(moduleCollection[i].EntryPointAddress.ToInt64() >= 0);
27+
Assert.True(moduleCollection[i].ModuleMemorySize > 0);
28+
}
4129
}
4230

4331
[Fact, PlatformSpecific(PlatformID.OSX)]

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

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Collections.Generic;
5+
using System.ComponentModel;
56
using System.IO;
67
using System.Linq;
78
using System.Threading;
@@ -185,35 +186,18 @@ public void TestMachineName()
185186
Assert.NotNull(_process.MachineName);
186187
}
187188

188-
[ActiveIssue(1896)]
189-
[Fact]
190-
public void TestMainModule()
189+
[Fact, PlatformSpecific(~PlatformID.OSX)]
190+
public void TestMainModuleOnNonOSX()
191191
{
192-
// Module support is not enabled on OSX
193-
if (global::Interop.IsOSX)
194-
{
195-
Assert.Null(_process.MainModule);
196-
Assert.Equal(0, _process.Modules.Count);
197-
return;
198-
}
199-
200-
// Ensure the process has loaded the modules.
201-
Assert.True(SpinWait.SpinUntil(() =>
202-
{
203-
if (_process.Modules.Count > 0)
204-
return true;
205-
_process.Refresh();
206-
return false;
207-
}, WaitInMS));
208-
209-
// Get MainModule property from a Process object
210-
ProcessModule mainModule = _process.MainModule;
211-
Assert.NotNull(mainModule);
212-
Assert.Equal(CoreRunName, Path.GetFileNameWithoutExtension(mainModule.ModuleName));
192+
string fileName = "corerun";
193+
if (global::Interop.IsWindows)
194+
fileName = "CoreRun.exe";
213195

214-
// Check that the mainModule is present in the modules list.
215-
IEnumerable<string> processModuleNames = _process.Modules.Cast<ProcessModule>().Select(p => Path.GetFileNameWithoutExtension(p.ModuleName));
216-
Assert.Contains(CoreRunName, processModuleNames);
196+
Process p = Process.GetCurrentProcess();
197+
Assert.True(p.Modules.Count > 0);
198+
Assert.Equal(fileName, p.MainModule.ModuleName);
199+
Assert.EndsWith(fileName, p.MainModule.FileName);
200+
Assert.Equal(string.Format("System.Diagnostics.ProcessModule ({0})", fileName), p.MainModule.ToString());
217201
}
218202

219203
[Fact]
@@ -377,7 +361,6 @@ public void TestProcessorTime()
377361
Assert.InRange(processorTimeAtHalfSpin, processorTimeBeforeSpin, Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds);
378362
}
379363

380-
[ActiveIssue(2474)]
381364
[Fact]
382365
public void TestProcessStartTime()
383366
{
@@ -391,8 +374,10 @@ public void TestProcessStartTime()
391374
// Thus, because there are HZ timer interrupts in a second, there are HZ jiffies in a second. Hence 1\HZ, will
392375
// be the resolution of system timer. The lowest value of HZ on unix is 100, hence the timer resolution is 10 ms.
393376
// Allowing for error in 10 ms.
394-
long beforeTicks = timeBeforeCreatingProcess.Ticks - new TimeSpan(0, 0, 0, 0, 10).Ticks;
395-
Assert.InRange(p.StartTime.ToUniversalTime().Ticks, beforeTicks, DateTime.UtcNow.Ticks);
377+
long tenMSTicks = new TimeSpan(0, 0, 0, 0, 10).Ticks;
378+
long beforeTicks = timeBeforeCreatingProcess.Ticks - tenMSTicks;
379+
long afterTicks = DateTime.UtcNow.Ticks + tenMSTicks;
380+
Assert.InRange(p.StartTime.ToUniversalTime().Ticks, beforeTicks, afterTicks);
396381
}
397382
finally
398383
{

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ public void TestStartTimeProperty()
7979
// Thus, because there are HZ timer interrupts in a second, there are HZ jiffies in a second. Hence 1\HZ, will
8080
// be the resolution of system timer. The lowest value of HZ on unix is 100, hence the timer resolution is 10 ms.
8181
// Allowing for error in 10 ms.
82-
long beforeTicks = timeBeforeCreatingProcess.Ticks - new TimeSpan(0, 0, 0, 0, 10).Ticks;
83-
Assert.InRange(thread.StartTime.ToUniversalTime().Ticks, beforeTicks, DateTime.UtcNow.Ticks);
82+
long tenMSTicks = new TimeSpan(0, 0, 0, 0, 10).Ticks;
83+
long beforeTicks = timeBeforeCreatingProcess.Ticks - tenMSTicks;
84+
long afterTicks = DateTime.UtcNow.Ticks + tenMSTicks;
85+
Assert.InRange(thread.StartTime.ToUniversalTime().Ticks, beforeTicks, afterTicks);
8486
}
8587
}
8688
finally

0 commit comments

Comments
 (0)