Skip to content

[Tests] ProcessKillerTests.Dispose — cmd cleanup loop has empty body; dead code or missing Kill() #740

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Info
File: tests/Servy.Core.UnitTests/Helpers/ProcessKillerTests.cs lines 23–30

Description:
The test-class Dispose method iterates child cmd.exe processes to clean up test-spawned shells, but the body of the conditional is empty:

foreach (var p in Process.GetProcessesByName("cmd"))
{
    // Only kill cmd processes that were likely spawned by these tests
    if (p.MainWindowTitle == "" && p.SessionId == Process.GetCurrentProcess().SessionId)
    {
        // Careful here; usually safe in CI environments
    }
}

The comment ("Careful here; usually safe in CI environments") indicates someone started writing the kill path and then backed off. Either the intended cleanup was never finished (orphan cmd.exe processes survive test runs) or the guard was deliberately removed and the foreach should now be deleted.

Suggested fix:
Decide between the two outcomes and make it explicit:

  • If the kill is wanted: add try { p.Kill(); } catch { /* ignore */ } finally { p.Dispose(); } inside the if.
  • If it is not: remove the dead foreach and its comment so the file stops inviting the question.

Whichever path is chosen, dispose the iterated Process instances (the first foreach on line 19 also leaks the iterated processes — each one needs p.Dispose()).

Metadata

Metadata

Assignees

Labels

testsChanges to test code and coverage

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions