Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unit/Change]: trigger config change on unit config and revision changes #109

Merged
merged 4 commits into from
May 16, 2024
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
6 changes: 2 additions & 4 deletions pkg/client/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,8 @@ func (u *Unit) updateState(

if u.configIdx != cfgIdx {
u.configIdx = cfgIdx
if !gproto.Equal(u.config.GetSource(), cfg.GetSource()) {
u.config = cfg
triggers |= TriggeredConfigChange
}
u.config = cfg
triggers |= TriggeredConfigChange
}

if !gproto.Equal(u.apm, expAPM) {
Expand Down
9 changes: 7 additions & 2 deletions pkg/client/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ func TestUnitUpdateWithSameMap(t *testing.T) {
_, err = gproto.Marshal(newUnit)
require.NoError(t, err)

// This should return TriggeredNothing, as the two underlying maps in `source` are the same
got := defaultTest.updateState(UnitStateHealthy, UnitLogLevelDebug, 0, nil, newUnit, 2, nil)
// This should return TriggeredNothing, as the configIdx hasn't changed
got := defaultTest.updateState(UnitStateHealthy, UnitLogLevelDebug, 0, nil, newUnit, 1, nil)
assert.Equal(t, TriggeredNothing, got)

// This should return TriggeredConfigChange, as the configIdx has changed (this is our criteria)
// no matter if the actual map is the same
got = defaultTest.updateState(UnitStateHealthy, UnitLogLevelDebug, 0, nil, newUnit, 2, nil)
assert.Equal(t, TriggeredConfigChange, got)
}

func TestUnitUpdateWithNewMap(t *testing.T) {
Expand Down