mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
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 <madhav.jiv@gmail.com>
This commit is contained in:
parent
4fa07a1c8a
commit
cdd018ad2a
@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user