Skip to content

Commit

Permalink
validate: Add test cases for linearizability watch validation
Browse files Browse the repository at this point in the history
- Introduce new test cases to validate linearizability of watch events
  • Loading branch information
iamrajiv committed Feb 17, 2025
1 parent f402504 commit c22121d
Showing 1 changed file with 150 additions and 0 deletions.
150 changes: 150 additions & 0 deletions tests/robustness/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"
"time"

"github.com/anishathalye/porcupine"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"

Expand Down Expand Up @@ -1835,6 +1836,155 @@ func TestValidateWatch(t *testing.T) {
},
expectError: errBrokeFilter.Error(),
},
{
name: "Linearizable - ordered events match linearization - pass",
reports: []report.ClientReport{
{
Watch: []model.WatchOperation{
{
Request: model.WatchRequest{
WithPrefix: true,
},
Responses: []model.WatchResponse{
{
Events: []model.WatchEvent{
putWatchEvent("a", "1", 2, true),
putWatchEvent("b", "2", 3, true),
},
},
},
},
},
KeyValue: []porcupine.Operation{
{
Input: putRequest("a", "1"),
Call: 1,
Return: 2,
},
{
Input: putRequest("b", "2"),
Call: 3,
Return: 4,
},
},
},
},
persistedRequests: []model.EtcdRequest{
putRequest("a", "1"),
putRequest("b", "2"),
},
},
{
name: "Linearizable - concurrent atomic txn - pass",
reports: []report.ClientReport{
{
Watch: []model.WatchOperation{
{
Request: model.WatchRequest{
WithPrefix: true,
},
Responses: []model.WatchResponse{
{
Events: []model.WatchEvent{
putWatchEvent("a", "1", 2, true),
putWatchEvent("b", "2", 2, true),
},
},
},
},
},
KeyValue: []porcupine.Operation{
{
Input: model.EtcdRequest{
Type: model.Txn,
Txn: &model.TxnRequest{
OperationsOnSuccess: []model.EtcdOperation{
{
Type: model.PutOperation,
Put: model.PutOptions{
Key: "a",
Value: model.ToValueOrHash("1"),
},
},
{
Type: model.PutOperation,
Put: model.PutOptions{
Key: "b",
Value: model.ToValueOrHash("2"),
},
},
},
},
},
Call: 1,
Return: 2,
},
},
},
},
persistedRequests: []model.EtcdRequest{
{
Type: model.Txn,
Txn: &model.TxnRequest{
OperationsOnSuccess: []model.EtcdOperation{
{
Type: model.PutOperation,
Put: model.PutOptions{
Key: "a",
Value: model.ToValueOrHash("1"),
},
},
{
Type: model.PutOperation,
Put: model.PutOptions{
Key: "b",
Value: model.ToValueOrHash("2"),
},
},
},
},
},
},
},
{
name: "Linearizable - non-atomic unordered events - fail",
reports: []report.ClientReport{
{
Watch: []model.WatchOperation{
{
Request: model.WatchRequest{
WithPrefix: true,
},
Responses: []model.WatchResponse{
{
Events: []model.WatchEvent{
putWatchEvent("b", "2", 3, true),
putWatchEvent("a", "1", 2, true),
},
},
},
},
},
KeyValue: []porcupine.Operation{
{
Input: putRequest("a", "1"),
Call: 1,
Return: 2,
},
{
Input: putRequest("b", "2"),
Call: 3,
Return: 4,
},
},
},
},
persistedRequests: []model.EtcdRequest{
putRequest("a", "1"),
putRequest("b", "2"),
},
expectError: errBrokeOrdered.Error(),
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit c22121d

Please sign in to comment.