Skip to content

Commit

Permalink
test split removal
Browse files Browse the repository at this point in the history
  • Loading branch information
mredolatti committed Nov 30, 2023
1 parent 0484f05 commit 5b37ef1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion splitio/commitversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ This file is created automatically, please do not edit
*/

// CommitVersion is the version of the last commit previous to release
const CommitVersion = "3d3bf05"
const CommitVersion = "0484f05"
21 changes: 1 addition & 20 deletions splitio/proxy/storage/splits.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func snapshotFromDisk(dst *mutexmap.MMSplitStorage, historic optimized.HistoricC

func archivedDTOForView(view *optimized.FeatureView) dtos.SplitDTO {
return dtos.SplitDTO{
ChangeNumber: 1,
ChangeNumber: view.LastUpdated,
TrafficTypeName: view.TrafficTypeName,
Name: view.Name,
TrafficAllocation: 100,
Expand All @@ -251,25 +251,6 @@ func archivedDTOForView(view *optimized.FeatureView) dtos.SplitDTO {
}
}

func appendArchivedSplitsForViews(views []optimized.FeatureView, dst *[]dtos.SplitDTO) {
for idx := range views {
*dst = append(*dst, dtos.SplitDTO{
ChangeNumber: 1,
TrafficTypeName: views[idx].TrafficTypeName,
Name: views[idx].Name,
TrafficAllocation: 100,
TrafficAllocationSeed: 0,
Seed: 0,
Status: "ARCHIVED",
Killed: false,
DefaultTreatment: "off",
Algo: 1,
Conditions: make([]dtos.ConditionDTO, 0),
Sets: views[idx].FlagSetNames(),
})
}
}

var _ ProxySplitStorage = (*ProxySplitStorageImpl)(nil)
var _ storage.SplitStorage = (*ProxySplitStorageImpl)(nil)
var _ observability.ObservableSplitStorage = (*ProxySplitStorageImpl)(nil)
35 changes: 31 additions & 4 deletions splitio/proxy/storage/splits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ func TestSplitStorage(t *testing.T) {
logger := logging.NewLogger(nil)

toAdd := []dtos.SplitDTO{
{Name: "f1", ChangeNumber: 1, Status: "ACTIVE"},
{Name: "f2", ChangeNumber: 2, Status: "ACTIVE"},
{Name: "f1", ChangeNumber: 1, Status: "ACTIVE", TrafficTypeName: "ttt"},
{Name: "f2", ChangeNumber: 2, Status: "ACTIVE", TrafficTypeName: "ttt"},
}
toAdd2 := []dtos.SplitDTO{{Name: "f3", ChangeNumber: 3, Status: "ACTIVE", TrafficTypeName: "ttt"}}
toRemove := []dtos.SplitDTO{
archivedDTOForView(&optimized.FeatureView{Name: "f2", Active: false, LastUpdated: 4, TrafficTypeName: "ttt"}),
}

splitC := persistent.NewSplitChangesCollection(dbw, logger)
splitC.Update(toAdd, nil, 2)
Expand All @@ -38,8 +41,8 @@ func TestSplitStorage(t *testing.T) {
// validate initial state of the historic cache & replace it with a mock for the next validations
assert.ElementsMatch(t,
[]optimized.FeatureView{
{Name: "f1", Active: true, LastUpdated: 1, FlagSets: []optimized.FlagSetView{}},
{Name: "f2", Active: true, LastUpdated: 2, FlagSets: []optimized.FlagSetView{}},
{Name: "f1", Active: true, LastUpdated: 1, FlagSets: []optimized.FlagSetView{}, TrafficTypeName: "ttt"},
{Name: "f2", Active: true, LastUpdated: 2, FlagSets: []optimized.FlagSetView{}, TrafficTypeName: "ttt"},
}, pss.historic.GetUpdatedSince(-1, nil))
pss.historic = &historicMock
// ----
Expand Down Expand Up @@ -73,6 +76,30 @@ func TestSplitStorage(t *testing.T) {
assert.Equal(t, int64(3), changes.Till)
assert.ElementsMatch(t, changes.Splits, toAdd2)

// archive split2 and check it's no longer returned
historicMock.On("Update", []dtos.SplitDTO(nil), toRemove, int64(4)).Once()
pss.Update(nil, toRemove, 4)
historicMock.On("GetUpdatedSince", int64(3), []string(nil)).
Once().
Return([]optimized.FeatureView{{Name: "f2", LastUpdated: 4, Active: false, TrafficTypeName: "ttt"}})

changes, err = pss.ChangesSince(-1, nil)
assert.Nil(t, err)
assert.Equal(t, int64(-1), changes.Since)
assert.Equal(t, int64(4), changes.Till)
assert.ElementsMatch(t,
[]dtos.SplitDTO{
{Name: "f1", ChangeNumber: 1, Status: "ACTIVE", TrafficTypeName: "ttt"},
{Name: "f3", ChangeNumber: 3, Status: "ACTIVE", TrafficTypeName: "ttt"},
},
changes.Splits)

changes, err = pss.ChangesSince(3, nil)
assert.Nil(t, err)
assert.Equal(t, int64(3), changes.Since)
assert.Equal(t, int64(4), changes.Till)
assert.ElementsMatch(t, toRemove, changes.Splits)

historicMock.AssertExpectations(t)
}

Expand Down

0 comments on commit 5b37ef1

Please sign in to comment.