From accc53f22e1a0ecc81708325393150dc5e37e401 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Thu, 1 Dec 2022 22:51:42 +0100 Subject: [PATCH] tests: Limit number of revision increase due to failures Signed-off-by: Marek Siarkowicz --- tests/linearizability/model.go | 10 ++++++++-- tests/linearizability/model_test.go | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/linearizability/model.go b/tests/linearizability/model.go index 0b04914a57e7..3d67ed968ed6 100644 --- a/tests/linearizability/model.go +++ b/tests/linearizability/model.go @@ -45,6 +45,7 @@ type EtcdState struct { Value string LastRevision int64 FailedWrite *EtcdRequest + FailedCount int64 } var etcdModel = porcupine.Model{ @@ -117,6 +118,7 @@ func initState(request EtcdRequest, response EtcdResponse) EtcdState { state.Value = request.PutData } else { state.FailedWrite = &request + state.FailedCount += 1 } default: panic("Unknown operation") @@ -128,9 +130,10 @@ func stepGet(state EtcdState, request EtcdRequest, response EtcdResponse) (bool, if state.Value == response.GetData && state.LastRevision == response.Revision { state.LastRevision = response.Revision state.FailedWrite = nil + state.FailedCount = 0 return true, state } - if state.FailedWrite != nil && state.LastRevision < response.Revision { + if state.FailedWrite != nil && state.LastRevision < response.Revision && state.LastRevision+state.FailedCount >= response.Revision { var ok bool switch state.FailedWrite.Op { case Get: @@ -144,6 +147,7 @@ func stepGet(state EtcdState, request EtcdRequest, response EtcdResponse) (bool, state.Value = response.GetData state.LastRevision = response.Revision state.FailedWrite = nil + state.FailedCount = 0 return true, state } } @@ -153,16 +157,18 @@ func stepGet(state EtcdState, request EtcdRequest, response EtcdResponse) (bool, func stepPut(state EtcdState, request EtcdRequest, response EtcdResponse) (bool, EtcdState) { if response.Err != nil { state.FailedWrite = &request + state.FailedCount += 1 return true, state } if response.Revision <= state.LastRevision { return false, state } - if response.Revision != state.LastRevision+1 && state.FailedWrite == nil { + if response.Revision != state.LastRevision+1 && (state.FailedWrite == nil || response.Revision > state.LastRevision+1+state.FailedCount) { return false, state } state.Value = request.PutData state.LastRevision = response.Revision state.FailedWrite = nil + state.FailedCount = 0 return true, state } diff --git a/tests/linearizability/model_test.go b/tests/linearizability/model_test.go index 8240499d024e..9ce5a3f9e256 100644 --- a/tests/linearizability/model_test.go +++ b/tests/linearizability/model_test.go @@ -79,10 +79,14 @@ func TestModel(t *testing.T) { operations: []testOperation{ {req: EtcdRequest{Op: Get, Key: "key"}, resp: EtcdResponse{Revision: 1}}, {req: EtcdRequest{Op: Put, Key: "key", PutData: "2"}, resp: EtcdResponse{Err: errors.New("failed")}}, + {req: EtcdRequest{Op: Put, Key: "key", PutData: "3"}, resp: EtcdResponse{Revision: 4}, failure: true}, {req: EtcdRequest{Op: Put, Key: "key", PutData: "3"}, resp: EtcdResponse{Revision: 3}}, {req: EtcdRequest{Op: Put, Key: "key", PutData: "4"}, resp: EtcdResponse{Err: errors.New("failed")}}, {req: EtcdRequest{Op: Put, Key: "key", PutData: "5"}, resp: EtcdResponse{Err: errors.New("failed")}}, {req: EtcdRequest{Op: Put, Key: "key", PutData: "6"}, resp: EtcdResponse{Revision: 6}}, + {req: EtcdRequest{Op: Put, Key: "key", PutData: "7"}, resp: EtcdResponse{Err: errors.New("failed")}}, + {req: EtcdRequest{Op: Put, Key: "key", PutData: "8"}, resp: EtcdResponse{Err: errors.New("failed")}}, + {req: EtcdRequest{Op: Put, Key: "key", PutData: "9"}, resp: EtcdResponse{Revision: 8}}, }, }, { @@ -92,12 +96,17 @@ func TestModel(t *testing.T) { {req: EtcdRequest{Op: Put, Key: "key", PutData: "2"}, resp: EtcdResponse{Err: errors.New("failed")}}, {req: EtcdRequest{Op: Get, Key: "key"}, resp: EtcdResponse{GetData: "3", Revision: 2}, failure: true}, {req: EtcdRequest{Op: Get, Key: "key"}, resp: EtcdResponse{GetData: "2", Revision: 1}, failure: true}, + {req: EtcdRequest{Op: Get, Key: "key"}, resp: EtcdResponse{GetData: "2", Revision: 3}, failure: true}, {req: EtcdRequest{Op: Get, Key: "key"}, resp: EtcdResponse{GetData: "2", Revision: 2}}, {req: EtcdRequest{Op: Put, Key: "key", PutData: "3"}, resp: EtcdResponse{Err: errors.New("failed")}}, {req: EtcdRequest{Op: Put, Key: "key", PutData: "4"}, resp: EtcdResponse{Err: errors.New("failed")}}, {req: EtcdRequest{Op: Get, Key: "key"}, resp: EtcdResponse{GetData: "3", Revision: 3}, failure: true}, {req: EtcdRequest{Op: Get, Key: "key"}, resp: EtcdResponse{GetData: "3", Revision: 4}, failure: true}, + {req: EtcdRequest{Op: Get, Key: "key"}, resp: EtcdResponse{GetData: "4", Revision: 5}, failure: true}, {req: EtcdRequest{Op: Get, Key: "key"}, resp: EtcdResponse{GetData: "4", Revision: 4}}, + {req: EtcdRequest{Op: Put, Key: "key", PutData: "5"}, resp: EtcdResponse{Err: errors.New("failed")}}, + {req: EtcdRequest{Op: Put, Key: "key", PutData: "6"}, resp: EtcdResponse{Err: errors.New("failed")}}, + {req: EtcdRequest{Op: Get, Key: "key"}, resp: EtcdResponse{GetData: "6", Revision: 5}}, }, }, }