Skip to content

Commit

Permalink
Fix comparison of upgrade metadata (#3779)
Browse files Browse the repository at this point in the history
  • Loading branch information
pchila authored Nov 16, 2023
1 parent 38bee24 commit c813d3f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/agent/application/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func reportNextScheduledUpgrade(input []fleetapi.Action, detailsSetter details.O

upgradeDetails := details.NewDetails(nextUpgrade.Version, details.StateScheduled, nextUpgrade.ID())
startTime, _ := nextUpgrade.StartTime()
upgradeDetails.Metadata.ScheduledAt = startTime
upgradeDetails.Metadata.ScheduledAt = &startTime

detailsSetter(upgradeDetails)
}
5 changes: 3 additions & 2 deletions internal/pkg/agent/application/dispatcher/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ func Test_ActionDispatcher_scheduleRetry(t *testing.T) {
func TestReportNextScheduledUpgrade(t *testing.T) {
now := time.Now().UTC()
later := now.Add(3 * time.Hour)
laterTruncate := later.Truncate(time.Second)
muchLater := later.Add(3 * time.Hour)

cases := map[string]struct {
Expand Down Expand Up @@ -522,7 +523,7 @@ func TestReportNextScheduledUpgrade(t *testing.T) {
State: details.StateScheduled,
ActionID: "action2",
Metadata: details.Metadata{
ScheduledAt: later.Truncate(time.Second),
ScheduledAt: &laterTruncate,
},
},
},
Expand All @@ -544,7 +545,7 @@ func TestReportNextScheduledUpgrade(t *testing.T) {
State: details.StateScheduled,
ActionID: "action4",
Metadata: details.Metadata{
ScheduledAt: later.Truncate(time.Second),
ScheduledAt: &laterTruncate,
},
},
},
Expand Down
13 changes: 12 additions & 1 deletion internal/pkg/agent/application/upgrade/details/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,24 @@ func (d *Details) notifyObserver(observer Observer) {
}

func (m Metadata) Equals(otherM Metadata) bool {
return m.ScheduledAt.Equal(otherM.ScheduledAt) &&
return equalTimePointers(m.ScheduledAt, otherM.ScheduledAt) &&
m.FailedState == otherM.FailedState &&
m.ErrorMsg == otherM.ErrorMsg &&
m.DownloadPercent == otherM.DownloadPercent &&
m.DownloadRate == otherM.DownloadRate
}

func equalTimePointers(t, otherT *time.Time) bool {
if t == otherT {
return true
}
if t == nil || otherT == nil {
return false
}

return t.Equal(*otherT)
}

func (dr *downloadRate) MarshalJSON() ([]byte, error) {
downloadRateBytesPerSecond := float64(*dr)
if math.IsInf(downloadRateBytesPerSecond, 0) {
Expand Down

0 comments on commit c813d3f

Please sign in to comment.