Skip to content

Commit

Permalink
tests: Limit number of revision increase due to failures
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
  • Loading branch information
serathius committed Dec 1, 2022
1 parent 37f9da0 commit accc53f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/linearizability/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type EtcdState struct {
Value string
LastRevision int64
FailedWrite *EtcdRequest
FailedCount int64
}

var etcdModel = porcupine.Model{
Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand All @@ -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
}
}
Expand All @@ -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
}
9 changes: 9 additions & 0 deletions tests/linearizability/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
},
},
{
Expand All @@ -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}},
},
},
}
Expand Down

0 comments on commit accc53f

Please sign in to comment.