From 5b37ef11df567b99724960778c056a6a55a900d0 Mon Sep 17 00:00:00 2001 From: Martin Redolatti Date: Thu, 30 Nov 2023 15:52:41 -0300 Subject: [PATCH] test split removal --- splitio/commitversion.go | 2 +- splitio/proxy/storage/splits.go | 21 +---------------- splitio/proxy/storage/splits_test.go | 35 ++++++++++++++++++++++++---- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/splitio/commitversion.go b/splitio/commitversion.go index 36632630..17b85678 100644 --- a/splitio/commitversion.go +++ b/splitio/commitversion.go @@ -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" diff --git a/splitio/proxy/storage/splits.go b/splitio/proxy/storage/splits.go index d36f6bb9..de3359b6 100644 --- a/splitio/proxy/storage/splits.go +++ b/splitio/proxy/storage/splits.go @@ -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, @@ -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) diff --git a/splitio/proxy/storage/splits_test.go b/splitio/proxy/storage/splits_test.go index 1afac7e1..b35219df 100644 --- a/splitio/proxy/storage/splits_test.go +++ b/splitio/proxy/storage/splits_test.go @@ -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) @@ -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 // ---- @@ -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) }