Skip to content

Commit

Permalink
Run osquery runner restart test on Windows (#2032)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany authored Jan 7, 2025
1 parent 557a918 commit 9cb1528
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
31 changes: 0 additions & 31 deletions pkg/osquery/runtime/runtime_posix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,34 +125,3 @@ func TestExtensionSocketPath(t *testing.T) {

waitShutdown(t, runner, logBytes)
}

// TestRestart tests that the launcher can restart the osqueryd process.
// This test causes time outs on windows, so it is only run on non-windows platforms.
// Should investigate why this is the case.
func TestRestart(t *testing.T) {
t.Parallel()
runner, logBytes, teardown := setupOsqueryInstanceForTests(t)
defer teardown()

previousStats := runner.instances[types.DefaultRegistrationID].stats

require.NoError(t, runner.Restart())
waitHealthy(t, runner, logBytes)

require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.StartTime, "start time should be set on latest instance stats after restart")
require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.ConnectTime, "connect time should be set on latest instance stats after restart")

require.NotEmpty(t, previousStats.ExitTime, "exit time should be set on last instance stats when restarted")
require.NotEmpty(t, previousStats.Error, "stats instance should have an error on restart")

previousStats = runner.instances[types.DefaultRegistrationID].stats

require.NoError(t, runner.Restart())
waitHealthy(t, runner, logBytes)

require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.StartTime, "start time should be added to latest instance stats after restart")
require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.ConnectTime, "connect time should be added to latest instance stats after restart")

require.NotEmpty(t, previousStats.ExitTime, "exit time should be set on instance stats when restarted")
require.NotEmpty(t, previousStats.Error, "stats instance should have an error on restart")
}
33 changes: 33 additions & 0 deletions pkg/osquery/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,39 @@ func TestExtensionIsCleanedUp(t *testing.T) {

// Ensure we've waited at least 32s
<-timer1.C

waitShutdown(t, runner, logBytes)
}

// TestRestart tests that the launcher can restart the osqueryd process.
func TestRestart(t *testing.T) {
t.Parallel()
runner, logBytes, teardown := setupOsqueryInstanceForTests(t)
defer teardown()

previousStats := runner.instances[types.DefaultRegistrationID].stats

require.NoError(t, runner.Restart())
waitHealthy(t, runner, logBytes)

require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.StartTime, "start time should be set on latest instance stats after restart")
require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.ConnectTime, "connect time should be set on latest instance stats after restart")

require.NotEmpty(t, previousStats.ExitTime, "exit time should be set on last instance stats when restarted")
require.NotEmpty(t, previousStats.Error, "stats instance should have an error on restart")

previousStats = runner.instances[types.DefaultRegistrationID].stats

require.NoError(t, runner.Restart())
waitHealthy(t, runner, logBytes)

require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.StartTime, "start time should be added to latest instance stats after restart")
require.NotEmpty(t, runner.instances[types.DefaultRegistrationID].stats.ConnectTime, "connect time should be added to latest instance stats after restart")

require.NotEmpty(t, previousStats.ExitTime, "exit time should be set on instance stats when restarted")
require.NotEmpty(t, previousStats.Error, "stats instance should have an error on restart")

waitShutdown(t, runner, logBytes)
}

// sets up an osquery instance with a running extension to be used in tests.
Expand Down

0 comments on commit 9cb1528

Please sign in to comment.