Skip to content

Commit

Permalink
Improve Supervisor test assertions on Windows
Browse files Browse the repository at this point in the history
Let the test assertions be OS specific, rather than skipping the tests
altogether on Windows. This improves test coverage there, even if the
result is slightly different on Windows.

Signed-off-by: Tom Wieczorek <[email protected]>
  • Loading branch information
twz123 committed Oct 13, 2024
1 parent e7c689e commit f1ce0d9
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pkg/supervisor/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ func TestMultiThread(t *testing.T) {
}

func TestCleanupPIDFile_Gracefully(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("PID file cleanup not yet implemented on Windows")
}

// Start some k0s-managed process.
prevCmd, prevPingPong := pingpong.Start(t, pingpong.StartOptions{
Env: []string{k0sManaged},
Expand All @@ -271,18 +267,20 @@ func TestCleanupPIDFile_Gracefully(t *testing.T) {
t.Cleanup(s.Stop)

// Expect the previous process to be gracefully terminated.
assert.NoError(t, prevCmd.Wait())
err := prevCmd.Wait()
switch runtime.GOOS {
case "windows": // We don't have graceful termination here
assert.ErrorContains(t, err, "exit status 137")
default:
assert.NoError(t, err)
}

// Stop the supervisor and check if the PID file is gone.
s.Stop()
assert.NoFileExists(t, pidFilePath)
}

func TestCleanupPIDFile_Forcefully(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("PID file cleanup not yet implemented on Windows")
}

// Start some k0s-managed process that won't terminate gracefully.
prevCmd, prevPingPong := pingpong.Start(t, pingpong.StartOptions{
Env: []string{k0sManaged},
Expand Down Expand Up @@ -310,7 +308,13 @@ func TestCleanupPIDFile_Forcefully(t *testing.T) {
t.Cleanup(s.Stop)

// Expect the previous process to be forcefully terminated.
assert.ErrorContains(t, prevCmd.Wait(), "signal: killed")
err := prevCmd.Wait()
switch runtime.GOOS {
case "windows":
assert.ErrorContains(t, err, "exit status 137")
default:
assert.ErrorContains(t, err, "signal: killed")
}

// Stop the supervisor and check if the PID file is gone.
assert.NoError(t, pingPong.AwaitPing())
Expand Down

0 comments on commit f1ce0d9

Please sign in to comment.