Skip to content

Commit ae2e6de

Browse files
authored
fix(LruAssignmentLogger): always log latest assignment (#52)
1 parent a0bc1e7 commit ae2e6de

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

eppoclient/lruassignmentlogger.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ type LruAssignmentLogger struct {
1414
// knowing the latest assignment. Therefore, both allocation and
1515
// variation are part of the cacheKey.
1616
type cacheKey struct {
17-
flag string
18-
subject string
19-
allocation string
20-
variation string
17+
flag string
18+
subject string
2119
}
2220
type cacheValue struct {
21+
allocation string
22+
variation string
2323
}
2424

2525
func NewLruAssignmentLogger(logger IAssignmentLogger, cacheSize int) IAssignmentLogger {
@@ -37,12 +37,13 @@ func NewLruAssignmentLogger(logger IAssignmentLogger, cacheSize int) IAssignment
3737

3838
func (self *LruAssignmentLogger) LogAssignment(event AssignmentEvent) {
3939
key := cacheKey{
40-
flag: event.FeatureFlag,
41-
subject: event.Subject,
40+
flag: event.FeatureFlag,
41+
subject: event.Subject,
42+
}
43+
value := cacheValue{
4244
allocation: event.Allocation,
4345
variation: event.Variation,
4446
}
45-
value := cacheValue{}
4647
previousValue, recentlyLogged := self.cache.Get(key)
4748
if !recentlyLogged || previousValue != value {
4849
self.inner.LogAssignment(event)

eppoclient/lruassignmentlogger_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func Test_LruAssignmentLogger_changeInVariationCausesLogging(t *testing.T) {
139139
innerLogger.AssertNumberOfCalls(t, "LogAssignment", 2)
140140
}
141141

142-
func Test_LruAssignmentLogger_allocationOscillationOnlyLoggedOnce(t *testing.T) {
142+
func Test_LruAssignmentLogger_allocationOscillationLogsAll(t *testing.T) {
143143
innerLogger := new(mockLogger)
144144
innerLogger.On("LogAssignment", mock.Anything).Return()
145145

@@ -182,10 +182,10 @@ func Test_LruAssignmentLogger_allocationOscillationOnlyLoggedOnce(t *testing.T)
182182
SubjectAttributes: Attributes{"testKey": "testValue"},
183183
})
184184

185-
innerLogger.AssertNumberOfCalls(t, "LogAssignment", 2)
185+
innerLogger.AssertNumberOfCalls(t, "LogAssignment", 4)
186186
}
187187

188-
func Test_LruAssignmentLogger_variationOscillationOnlyLoggedOnce(t *testing.T) {
188+
func Test_LruAssignmentLogger_variationOscillationLogsAll(t *testing.T) {
189189
innerLogger := new(mockLogger)
190190
innerLogger.On("LogAssignment", mock.Anything).Return()
191191

@@ -228,5 +228,5 @@ func Test_LruAssignmentLogger_variationOscillationOnlyLoggedOnce(t *testing.T) {
228228
SubjectAttributes: Attributes{"testKey": "testValue"},
229229
})
230230

231-
innerLogger.AssertNumberOfCalls(t, "LogAssignment", 2)
231+
innerLogger.AssertNumberOfCalls(t, "LogAssignment", 4)
232232
}

0 commit comments

Comments
 (0)