From cdd018ad2ad4a903868e346ba954bbfc76188d1a Mon Sep 17 00:00:00 2001 From: Madhav Jivrajani Date: Wed, 14 Feb 2024 15:51:21 +0530 Subject: [PATCH] tests/robustness: add a robustness test for validating create events Split off valdiating create events from the prevKV test. The added test tests the following two: - A create event should not exist in our past history - A non-create event should exist in our past history Signed-off-by: Madhav Jivrajani --- tests/robustness/validate/validate_test.go | 4 ++++ tests/robustness/validate/watch.go | 26 +++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/robustness/validate/validate_test.go b/tests/robustness/validate/validate_test.go index 11c963e38..429641851 100644 --- a/tests/robustness/validate/validate_test.go +++ b/tests/robustness/validate/validate_test.go @@ -89,6 +89,7 @@ func TestValidateWatch(t *testing.T) { }, }, Revision: 2, + IsCreate: true, }, }, }, @@ -148,6 +149,7 @@ func TestValidateWatch(t *testing.T) { }, }, Revision: 2, + IsCreate: true, }, }, }, @@ -182,6 +184,7 @@ func TestValidateWatch(t *testing.T) { }, }, Revision: 2, + IsCreate: true, }, }, }, @@ -207,6 +210,7 @@ func TestValidateWatch(t *testing.T) { }, }, Revision: 2, + IsCreate: true, }, }, }, diff --git a/tests/robustness/validate/watch.go b/tests/robustness/validate/watch.go index 94f419dcc..32aeca97b 100644 --- a/tests/robustness/validate/watch.go +++ b/tests/robustness/validate/watch.go @@ -35,6 +35,7 @@ func validateWatch(t *testing.T, lg *zap.Logger, cfg Config, reports []report.Cl validateReliable(t, eventHistory, r) validateResumable(t, eventHistory, r) validatePrevKV(t, r, eventHistory) + validateCreateEvent(t, r, eventHistory) } } } @@ -171,11 +172,6 @@ func validatePrevKV(t *testing.T, report report.ClientReport, history []model.Pe // i.e. prevKV is nil iff the event is a create event, we cannot reliably // check that without knowing if compaction has run. - // A create event will not have an entry in our history and a non-create - // event *should* have an entry in our history. - if _, prevKeyExists := state.KeyValues[event.Key]; event.IsCreate == prevKeyExists { - t.Errorf("PrevKV - unexpected event ecountered, create event should not be in event history and update/delete event should be, event already exists: %t, is create event: %t, event: %+v", prevKeyExists, event.IsCreate, event) - } // We allow PrevValue to be nil since in the face of compaction, etcd does not // guarantee its presence. if event.PrevValue != nil && *event.PrevValue != state.KeyValues[event.Key] { @@ -186,6 +182,26 @@ func validatePrevKV(t *testing.T, report report.ClientReport, history []model.Pe } } +func validateCreateEvent(t *testing.T, report report.ClientReport, history []model.PersistedEvent) { + replay := model.NewReplay(history) + for _, op := range report.Watch { + for _, resp := range op.Responses { + for _, event := range resp.Events { + // Get state state just before the current event. + state, err := replay.StateForRevision(event.Revision - 1) + if err != nil { + t.Error(err) + } + // A create event will not have an entry in our history and a non-create + // event *should* have an entry in our history. + if _, prevKeyExists := state.KeyValues[event.Key]; event.IsCreate == prevKeyExists { + t.Errorf("CreateEvent - unexpected event ecountered, create event should not be in event history and update/delete event should be, event already exists: %t, is create event: %t, event: %+v", prevKeyExists, event.IsCreate, event) + } + } + } + } +} + func firstRevision(op model.WatchOperation) int64 { for _, resp := range op.Responses { for _, event := range resp.Events {