Skip to content

Commit

Permalink
RSDK-8831 - Add log for failing module restart (viamrobotics#4378)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheukt authored Sep 23, 2024
1 parent c0763fc commit 2fd93b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions module/modmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,11 @@ func (mgr *Manager) newOnUnexpectedExitHandler(mod *module) func(exitCode int) b
if orphanedResourceNames := mgr.attemptRestart(mgr.restartCtx, mod); orphanedResourceNames != nil {
if mgr.removeOrphanedResources != nil {
mgr.removeOrphanedResources(mgr.restartCtx, orphanedResourceNames)
rNames := make([]string, len(orphanedResourceNames))
for idx, rName := range orphanedResourceNames {
rNames[idx] = rName.String()
}
mgr.logger.Debugw("Removed resources after failed module restart", "module", mod.cfg.Name, "resources", rNames)
}
return false
}
Expand Down
12 changes: 8 additions & 4 deletions module/modmanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ func TestModuleReloading(t *testing.T) {

testutils.WaitForAssertion(t, func(tb testing.TB) {
tb.Helper()
test.That(tb, logs.FilterMessageSnippet("Error while restarting crashed module").Len(),
test.ShouldEqual, 3)
test.That(tb, logs.FilterMessageSnippet("Removed resources after failed module restart").Len(),
test.ShouldEqual, 1)
})

ok = mgr.IsModularResource(rNameMyHelper)
Expand All @@ -546,6 +546,8 @@ func TestModuleReloading(t *testing.T) {
test.ShouldEqual, 1)
test.That(t, logs.FilterMessageSnippet("Module successfully restarted").Len(),
test.ShouldEqual, 0)
test.That(t, logs.FilterMessageSnippet("Error while restarting crashed module").Len(),
test.ShouldEqual, 3)

// Assert that RemoveOrphanedResources was called once.
test.That(t, dummyRemoveOrphanedResourcesCallCount.Load(), test.ShouldEqual, 1)
Expand Down Expand Up @@ -587,7 +589,7 @@ func TestModuleReloading(t *testing.T) {

testutils.WaitForAssertion(t, func(tb testing.TB) {
tb.Helper()
test.That(tb, logs.FilterMessageSnippet("Will not attempt to restart crashed module").Len(),
test.That(tb, logs.FilterMessageSnippet("Removed resources after failed module restart").Len(),
test.ShouldEqual, 1)
})

Expand All @@ -598,11 +600,13 @@ func TestModuleReloading(t *testing.T) {
test.That(t, err.Error(), test.ShouldContainSubstring, "not connected")

// Assert that logs reflect that test-module crashed and was not
// successfully restarted.
// restarted.
test.That(t, logs.FilterMessageSnippet("Module has unexpectedly exited").Len(),
test.ShouldEqual, 1)
test.That(t, logs.FilterMessageSnippet("Module successfully restarted").Len(),
test.ShouldEqual, 0)
test.That(t, logs.FilterMessageSnippet("Will not attempt to restart crashed module").Len(),
test.ShouldEqual, 1)

// Assert that RemoveOrphanedResources was called once.
test.That(t, dummyRemoveOrphanedResourcesCallCount.Load(), test.ShouldEqual, 1)
Expand Down

0 comments on commit 2fd93b2

Please sign in to comment.