Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ func (m *Manager) SubsystemUpdates(ctx context.Context) {
m.logger.Warn(err)
} else {
m.viamServerNeedsRestart = false
m.cache.MarkViamServerRunningVersion()
}
if m.viamAgentNeedsRestart {
m.Exit(fmt.Sprintf("A new version of %s has been installed", SubsystemName))
Expand All @@ -317,6 +316,9 @@ func (m *Manager) SubsystemUpdates(ctx context.Context) {
m.logger.Warnf("%s has NOT allowed a restart; will NOT restart", viamserver.SubsysName)
}
}
if !m.viamServerNeedsRestart {
m.cache.MarkViamServerRunningVersion()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] How is this different from what we initially had (I mean a week ago before your last PR/commit)? I'm having trouble parsing the if m.viamServerNeedsRestart || m.viamAgentNeedsRestart followed by if !m.viamServerNeedsRestart {. With which case are we not marking a running viam-server version with your changes that we were previously marking?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what we initially had was that we were always marking a running a viam-server version, which is bad if the viam-server didn't actually get stopped/get restarted.

now, if stopping viam-server failed, m.viamServerNeedsRestart will stay true and we won't be marking the running viam-server version.

that's the intended change anyway

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if stopping viam-server failed, m.viamServerNeedsRestart will stay true and we won't be marking the running viam-server version.

Got it; that makes sense to me. Thanks!

}
if err := m.viamServer.Start(ctx); err != nil {
m.logger.Warn(err)
}
Expand Down
26 changes: 15 additions & 11 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,20 +406,23 @@ func TestSubsystemUpdatesViamServerRestart(t *testing.T) {
}

// TestSubsystemUpdatesMarksRunningVersion verifies that SubsystemUpdates calls
// MarkViamServerRunningVersion iff the restart block successfully stopped
// viam-server. Mark snapshots the installed CurrentVersion into runningVersion;
// it is called before the new viam-server is started, so it reflects the
// decision to run a version, not confirmation of a healthy start.
// MarkViamServerRunningVersion whenever it is about to Start viam-server at
// the installed CurrentVersion — i.e., when no restart is pending at the
// point of Start. Mark reflects the decision to run a version, not
// confirmation of a healthy start; it is skipped only when the old version
// is still running (Stop failed or restart was disallowed).
func TestSubsystemUpdatesMarksRunningVersion(t *testing.T) {
for _, tc := range []struct {
name string
updateReturns bool
stopErr error
wantMark bool
name string
updateReturns bool
stopErr error
restartNotAllowed bool
wantMark bool
}{
{name: "no restart triggered; no mark", wantMark: false},
{name: "no restart triggered; marks running", wantMark: true},
{name: "restart succeeds; marks running", updateReturns: true, wantMark: true},
{name: "restart stop fails; no mark", updateReturns: true, stopErr: errors.New("stop failed"), wantMark: false},
{name: "restart not allowed; no mark", updateReturns: true, restartNotAllowed: true, wantMark: false},
} {
t.Run(tc.name, func(t *testing.T) {
utils.MockAndCreateViamDirs(t)
Expand All @@ -430,8 +433,9 @@ func TestSubsystemUpdatesMarksRunningVersion(t *testing.T) {

cfg := utils.DefaultConfiguration
fake := &fakeViamServer{
updateFn: func(context.Context, utils.AgentConfig) bool { return tc.updateReturns },
stopFn: func(context.Context) error { return tc.stopErr },
updateFn: func(context.Context, utils.AgentConfig) bool { return tc.updateReturns },
stopFn: func(context.Context) error { return tc.stopErr },
restartAllowedFn: func(context.Context) bool { return !tc.restartNotAllowed },
}
m := &Manager{
logger: logger,
Expand Down
Loading