-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Validate etcd linearizability
Signed-off-by: Marek Siarkowicz <[email protected]>
- Loading branch information
Showing
14 changed files
with
380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: Linearizability | ||
on: [push, pull_request] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: "1.19.1" | ||
- run: make test-linearizability |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2022 The etcd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package linearizability | ||
|
||
import ( | ||
"testing" | ||
|
||
"go.etcd.io/etcd/tests/v3/framework" | ||
) | ||
|
||
var testRunner = framework.E2eTestRunner | ||
|
||
func TestMain(m *testing.M) { | ||
testRunner.TestMain(m) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2022 The etcd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package linearizability | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/anishathalye/porcupine" | ||
) | ||
|
||
type Operation int8 | ||
|
||
const Read Operation = 0 | ||
const Put Operation = 1 | ||
|
||
type etcdRequest struct { | ||
op Operation | ||
writeData string | ||
} | ||
|
||
type etcdResponse struct { | ||
readData string | ||
err error | ||
} | ||
|
||
type EtcdState struct { | ||
Value string | ||
FailedWrites []string | ||
} | ||
|
||
var etcdModel = porcupine.Model{ | ||
Init: func() interface{} { return "{}" }, | ||
Step: func(st interface{}, in interface{}, out interface{}) (bool, interface{}) { | ||
stateString := st.(string) | ||
var state EtcdState | ||
err := json.Unmarshal([]byte(stateString), &state) | ||
if err != nil { | ||
panic(err) | ||
} | ||
request := in.(etcdRequest) | ||
response := out.(etcdResponse) | ||
ok, state := step(state, request, response) | ||
data, err := json.Marshal(state) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return ok, string(data) | ||
}, | ||
DescribeOperation: func(in, out interface{}) string { | ||
request := in.(etcdRequest) | ||
response := out.(etcdResponse) | ||
var call, args, resp string | ||
switch request.op { | ||
case Read: | ||
call = "read" | ||
if response.err != nil { | ||
resp = response.err.Error() | ||
} else { | ||
resp = response.readData | ||
} | ||
case Put: | ||
call = "write" | ||
args = request.writeData | ||
if response.err != nil { | ||
resp = response.err.Error() | ||
} else { | ||
resp = "ok" | ||
} | ||
default: | ||
return "<invalid>" | ||
} | ||
return fmt.Sprintf("%s(%q) -> %s", call, args, resp) | ||
}, | ||
} | ||
|
||
func step(state EtcdState, request etcdRequest, response etcdResponse) (bool, EtcdState) { | ||
var ok bool | ||
switch request.op { | ||
case Read: | ||
ok = state.Value == response.readData | ||
if !ok { | ||
for i, write := range state.FailedWrites { | ||
if write == response.readData { | ||
ok = true | ||
state = EtcdState{Value: write, FailedWrites: append(state.FailedWrites[:i], state.FailedWrites[i+1:]...)} | ||
break | ||
} | ||
} | ||
} | ||
case Put: | ||
if response.err == nil { | ||
state.Value = request.writeData | ||
} else { | ||
state.FailedWrites = append(state.FailedWrites, request.writeData) | ||
} | ||
ok = true | ||
} | ||
return ok, state | ||
} |
Oops, something went wrong.