Skip to content

Commit 0c62964

Browse files
authored
feat: Method for removing forced variations (#176)
This adds a RemoveVariation method of MapExperimentOverridesStore, which can be used to delete a previously set variation.
1 parent a2b7018 commit 0c62964

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pkg/decision/experiment_override_service.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ func (m *MapExperimentOverridesStore) SetVariation(overrideKey ExperimentOverrid
6868
m.mutex.Unlock()
6969
}
7070

71+
// RemoveVariation removes the override variation key associated with the argument user+experiment key.
72+
// If there is no override variation key set, this method has no effect.
73+
func (m *MapExperimentOverridesStore) RemoveVariation(overrideKey ExperimentOverrideKey) {
74+
m.mutex.Lock()
75+
delete(m.overridesMap, overrideKey)
76+
m.mutex.Unlock()
77+
}
78+
7179
// ExperimentOverrideService makes a decision using an ExperimentOverridesStore
7280
// Implements the ExperimentService interface
7381
type ExperimentOverrideService struct {

pkg/decision/experiment_override_service_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ func (s *ExperimentOverrideServiceTestSuite) TestMapExperimentOverridesStoreConc
187187
s.Exactly(testExp1111Var2222.Key, user3Decision.Variation.Key)
188188
}
189189

190+
func (s *ExperimentOverrideServiceTestSuite) TestRemovePreviouslySetVariation() {
191+
testDecisionContext := ExperimentDecisionContext{
192+
Experiment: &testExp1111,
193+
ProjectConfig: s.mockConfig,
194+
}
195+
testUserContext := entities.UserContext{
196+
ID: "test_user_1",
197+
}
198+
overrideKey := ExperimentOverrideKey{ExperimentKey: testExp1111.Key, UserID: "test_user_1"}
199+
s.overrides.SetVariation(overrideKey, testExp1111Var2222.Key)
200+
s.overrides.RemoveVariation(overrideKey)
201+
decision, err := s.overrideService.GetDecision(testDecisionContext, testUserContext)
202+
s.NoError(err)
203+
s.Nil(decision.Variation)
204+
}
205+
190206
func TestExperimentOverridesTestSuite(t *testing.T) {
191207
suite.Run(t, new(ExperimentOverrideServiceTestSuite))
192208
}

0 commit comments

Comments
 (0)