test: correct the logic of comparing revision in linearizablity/watch.go

Signed-off-by: Benjamin Wang <wachao@vmware.com>
This commit is contained in:
Benjamin Wang 2023-02-12 15:30:08 +08:00
parent 87e271701b
commit b4dfa9d34f
2 changed files with 23 additions and 16 deletions

View File

@ -144,9 +144,7 @@ func TestLinearizability(t *testing.T) {
e2e.WithSnapshotCount(100), e2e.WithSnapshotCount(100),
), ),
}, },
// TODO: investigate periodic `Model is not linearizable` failures {
// see https://github.com/etcd-io/etcd/pull/15104#issuecomment-1416371288
/*{
name: "Snapshot", name: "Snapshot",
failpoint: RandomSnapshotFailpoint, failpoint: RandomSnapshotFailpoint,
traffic: &HighTraffic, traffic: &HighTraffic,
@ -156,7 +154,7 @@ func TestLinearizability(t *testing.T) {
e2e.WithSnapshotCatchUpEntries(100), e2e.WithSnapshotCatchUpEntries(100),
e2e.WithPeerProxy(true), e2e.WithPeerProxy(true),
), ),
},*/ },
}...) }...)
for _, scenario := range scenarios { for _, scenario := range scenarios {
if scenario.traffic == nil { if scenario.traffic == nil {

View File

@ -82,28 +82,37 @@ func validateWatchResponses(t *testing.T, responses [][]watchResponse, expectPro
} }
func validateMemberWatchResponses(t *testing.T, responses []watchResponse, expectProgressNotify bool) { func validateMemberWatchResponses(t *testing.T, responses []watchResponse, expectProgressNotify bool) {
var gotProgressNotify = false var (
var lastRevision int64 = 1 gotProgressNotify = false
lastEventModRevision int64 = 1 // The event.Kv.ModRevision in the latest event.
lastHeadRevision int64 = 1 // The resp.Header.Revision in last watch response.
)
for _, resp := range responses { for _, resp := range responses {
if resp.Header.Revision < lastRevision { if resp.Header.Revision < lastHeadRevision {
t.Errorf("Revision should never decrease") t.Errorf("Server revision should never decrease, lastHeadRevision: %d, resp.Header.Revision: %d",
lastHeadRevision, resp.Header.Revision)
} }
if resp.IsProgressNotify() && resp.Header.Revision == lastRevision {
if resp.IsProgressNotify() && resp.Header.Revision == lastHeadRevision {
gotProgressNotify = true gotProgressNotify = true
} }
if resp.Header.Revision == lastRevision && len(resp.Events) != 0 { if resp.Header.Revision == lastHeadRevision && len(resp.Events) != 0 {
t.Errorf("Got two non-empty responses about same revision") t.Errorf("Got two non-empty responses about same revision")
} }
for _, event := range resp.Events { for _, event := range resp.Events {
if event.Kv.ModRevision != lastRevision+1 { if event.Kv.ModRevision != lastEventModRevision+1 {
t.Errorf("Expect revision to grow by 1, last: %d, mod: %d", lastRevision, event.Kv.ModRevision) t.Errorf("Expect event revision to grow by 1, last: %d, mod: %d", lastEventModRevision, event.Kv.ModRevision)
} }
lastRevision = event.Kv.ModRevision lastEventModRevision = event.Kv.ModRevision
} }
if resp.Header.Revision != lastRevision {
t.Errorf("Expect response revision equal last event mod revision") if resp.Header.Revision < lastEventModRevision {
t.Errorf("Event revision should never exceed the server's revision, lastEventRevision: %d, resp.Header.Revision: %d",
lastEventModRevision, resp.Header.Revision)
} }
lastRevision = resp.Header.Revision
lastHeadRevision = resp.Header.Revision
} }
if gotProgressNotify != expectProgressNotify { if gotProgressNotify != expectProgressNotify {
t.Errorf("Expected progress notify: %v, got: %v", expectProgressNotify, gotProgressNotify) t.Errorf("Expected progress notify: %v, got: %v", expectProgressNotify, gotProgressNotify)