forked from etcd-io/etcd
-
Notifications
You must be signed in to change notification settings - Fork 2
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
18 changed files
with
709 additions
and
5 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,17 @@ | ||
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: | | ||
mkdir -p /tmp/linearizability | ||
EXPECT_DEBUG=true GO_TEST_FLAGS=-v RESULTS_DIR=/tmp/linearizability make test-linearizability | ||
- uses: actions/upload-artifact@v2 | ||
if: always() | ||
with: | ||
path: /tmp/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,87 @@ | ||
// 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 ( | ||
"context" | ||
"time" | ||
|
||
"github.com/anishathalye/porcupine" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type recordingClient struct { | ||
client clientv3.Client | ||
id int | ||
|
||
operations []porcupine.Operation | ||
} | ||
|
||
func NewClient(endpoints []string, id int) (*recordingClient, error) { | ||
cc, err := clientv3.New(clientv3.Config{ | ||
Endpoints: endpoints, | ||
Logger: zap.NewNop(), | ||
DialKeepAliveTime: 1 * time.Millisecond, | ||
DialKeepAliveTimeout: 5 * time.Millisecond, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &recordingClient{ | ||
client: *cc, | ||
id: id, | ||
operations: []porcupine.Operation{}, | ||
}, nil | ||
} | ||
|
||
func (c *recordingClient) Close() error { | ||
return c.client.Close() | ||
} | ||
|
||
func (c *recordingClient) Get(ctx context.Context, key string) error { | ||
callTime := time.Now() | ||
resp, err := c.client.Get(ctx, key) | ||
returnTime := time.Now() | ||
if err != nil { | ||
return err | ||
} | ||
var readData string | ||
if len(resp.Kvs) == 1 { | ||
readData = string(resp.Kvs[0].Value) | ||
} | ||
c.operations = append(c.operations, porcupine.Operation{ | ||
ClientId: c.id, | ||
Input: etcdRequest{op: Get, key: key}, | ||
Call: callTime.UnixNano(), | ||
Output: etcdResponse{getData: readData}, | ||
Return: returnTime.UnixNano(), | ||
}) | ||
return nil | ||
} | ||
|
||
func (c *recordingClient) Put(ctx context.Context, key, value string) error { | ||
callTime := time.Now() | ||
_, err := c.client.Put(ctx, key, value) | ||
returnTime := time.Now() | ||
c.operations = append(c.operations, porcupine.Operation{ | ||
ClientId: c.id, | ||
Input: etcdRequest{op: Put, key: key, putData: value}, | ||
Call: callTime.UnixNano(), | ||
Output: etcdResponse{err: err}, | ||
Return: returnTime.UnixNano(), | ||
}) | ||
return nil | ||
} |
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,49 @@ | ||
// 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 ( | ||
"context" | ||
"math/rand" | ||
|
||
"go.etcd.io/etcd/tests/v3/framework/e2e" | ||
) | ||
|
||
var ( | ||
KillFailpoint Failpoint = killFailpoint{} | ||
) | ||
|
||
type Failpoint interface { | ||
Trigger(ctx context.Context, clus *e2e.EtcdProcessCluster) error | ||
} | ||
|
||
type killFailpoint struct{} | ||
|
||
func (f killFailpoint) Trigger(ctx context.Context, clus *e2e.EtcdProcessCluster) error { | ||
member := clus.Procs[rand.Int()%len(clus.Procs)] | ||
err := member.Kill() | ||
if err != nil { | ||
return err | ||
} | ||
err = member.Wait() | ||
if err != nil { | ||
return err | ||
} | ||
err = member.Start(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
Oops, something went wrong.