Skip to content

Commit

Permalink
Fix CI jobs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lilla28 committed Apr 21, 2023
1 parent cc50bce commit 6db36d9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration-prototypes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: Get-ChildItem -Recurse -Include *.sln | ForEach-Object {dotnet build $_ --configuration Release --no-restore; if ($LASTEXITCODE -ne 0 ) {throw "Build for $_ FAILED"; }}

- name: Test .Net
run: Get-ChildItem -Recurse -Include *.sln | ForEach-Object {dotnet test $_ --no-restore --verbosity normal --collect:"XPlat Code Coverage"}
run: Get-ChildItem -Recurse -Include *.sln | ForEach-Object {dotnet test $_ --configuration Release --no-restore --verbosity normal --collect:"XPlat Code Coverage"}


- name: Setup Node.js ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
run: Get-ChildItem -Recurse -Include *.sln | ForEach-Object {dotnet build $_ --configuration Release --no-restore; if ($LASTEXITCODE -ne 0 ) {throw "Build for $_ FAILED"; }}
working-directory: src
- name: Test
run: Get-ChildItem -Recurse -Include *.sln | ForEach-Object {dotnet test $_ --no-restore --verbosity normal}
run: Get-ChildItem -Recurse -Include *.sln | ForEach-Object {dotnet test $_ --configuration Release --no-restore --verbosity normal}
working-directory: src
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ public override float GetCpuUsage(int processId, string? processName)
if (processName == null) return default;

using var cpuPerformanceCounter = _memoryPerformanceCounters.GetOrAdd(
processId,
_ => new PerformanceCounter(
"Process",
"% Processor Time",
processName,
true));
processId, _ =>
{
return new PerformanceCounter(
"Process",
"% Processor Time",
processName,
true);
});


cpuPerformanceCounter.NextValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,20 @@ public void ClearProcessIds_will_remove_all_the_elements()
processMonitor.Dispose();
}

[Fact]
[Fact] //It is hard to reproduce a process which ses cpu in a time that is being measured in percentage
public void GetCpuUsage_will_return_with_some_value()
{
var loggerMock = CreateLoggerMock();
var processMonitor = CreateWindowsProcessMonitor(loggerMock.Object);
var process = Process.Start(GetSimpleTestApplicationPath());

var cpuUsageResult = processMonitor.GetCpuUsage(
Environment.ProcessId,
Process.GetProcessById(Environment.ProcessId).ProcessName);
process.Id,
process.ProcessName);

cpuUsageResult.Should().BeGreaterThan(0);
cpuUsageResult.Should().BeGreaterThanOrEqualTo(0);
process.Kill();
processMonitor.Dispose();
}

[Fact]
Expand All @@ -137,6 +140,7 @@ public void GetMemoryUsage_will_return_with_some_value()
Process.GetProcessById(Environment.ProcessId).ProcessName);

memoryUsageResult.Should().BeGreaterThan(0);
processMonitor.Dispose();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using TestConsoleApp;

Console.WriteLine("Hello, World!");

var stopwatch = Stopwatch.StartNew();
Console.WriteLine("This is a test application to test the ProcessMonitor...");

Console.WriteLine("Starting a process...");
Expand All @@ -23,6 +23,7 @@
Helper.IsDebug(ref isDebug);

var folder = isDebug ? "Debug" : "Release";
Console.WriteLine(folder);

var childProcess = Process.Start($"../../../../TestConsoleApp2/bin/{folder}/net6.0/TestConsoleApp2.exe");

Expand All @@ -35,5 +36,5 @@

Console.WriteLine("Terminating a process....");
childProcess.Kill();

stopwatch.Stop();
Console.WriteLine("ChildProcess is terminated");

0 comments on commit 6db36d9

Please sign in to comment.