Skip to content

Commit

Permalink
feat: Method for removing forced variations (#176)
Browse files Browse the repository at this point in the history
This adds a RemoveVariation method of MapExperimentOverridesStore, which can be used to delete a previously set variation.
  • Loading branch information
mjc1283 committed Nov 12, 2019
1 parent a2b7018 commit 0c62964
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/decision/experiment_override_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ func (m *MapExperimentOverridesStore) SetVariation(overrideKey ExperimentOverrid
m.mutex.Unlock()
}

// RemoveVariation removes the override variation key associated with the argument user+experiment key.
// If there is no override variation key set, this method has no effect.
func (m *MapExperimentOverridesStore) RemoveVariation(overrideKey ExperimentOverrideKey) {
m.mutex.Lock()
delete(m.overridesMap, overrideKey)
m.mutex.Unlock()
}

// ExperimentOverrideService makes a decision using an ExperimentOverridesStore
// Implements the ExperimentService interface
type ExperimentOverrideService struct {
Expand Down
16 changes: 16 additions & 0 deletions pkg/decision/experiment_override_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ func (s *ExperimentOverrideServiceTestSuite) TestMapExperimentOverridesStoreConc
s.Exactly(testExp1111Var2222.Key, user3Decision.Variation.Key)
}

func (s *ExperimentOverrideServiceTestSuite) TestRemovePreviouslySetVariation() {
testDecisionContext := ExperimentDecisionContext{
Experiment: &testExp1111,
ProjectConfig: s.mockConfig,
}
testUserContext := entities.UserContext{
ID: "test_user_1",
}
overrideKey := ExperimentOverrideKey{ExperimentKey: testExp1111.Key, UserID: "test_user_1"}
s.overrides.SetVariation(overrideKey, testExp1111Var2222.Key)
s.overrides.RemoveVariation(overrideKey)
decision, err := s.overrideService.GetDecision(testDecisionContext, testUserContext)
s.NoError(err)
s.Nil(decision.Variation)
}

func TestExperimentOverridesTestSuite(t *testing.T) {
suite.Run(t, new(ExperimentOverrideServiceTestSuite))
}

0 comments on commit 0c62964

Please sign in to comment.