Skip to content

Commit c22121d

Browse files
committed
validate: Add test cases for linearizability watch validation
- Introduce new test cases to validate linearizability of watch events
1 parent f402504 commit c22121d

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

tests/robustness/validate/validate_test.go

+150
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222
"time"
2323

24+
"github.com/anishathalye/porcupine"
2425
"github.com/stretchr/testify/require"
2526
"go.uber.org/zap/zaptest"
2627

@@ -1835,6 +1836,155 @@ func TestValidateWatch(t *testing.T) {
18351836
},
18361837
expectError: errBrokeFilter.Error(),
18371838
},
1839+
{
1840+
name: "Linearizable - ordered events match linearization - pass",
1841+
reports: []report.ClientReport{
1842+
{
1843+
Watch: []model.WatchOperation{
1844+
{
1845+
Request: model.WatchRequest{
1846+
WithPrefix: true,
1847+
},
1848+
Responses: []model.WatchResponse{
1849+
{
1850+
Events: []model.WatchEvent{
1851+
putWatchEvent("a", "1", 2, true),
1852+
putWatchEvent("b", "2", 3, true),
1853+
},
1854+
},
1855+
},
1856+
},
1857+
},
1858+
KeyValue: []porcupine.Operation{
1859+
{
1860+
Input: putRequest("a", "1"),
1861+
Call: 1,
1862+
Return: 2,
1863+
},
1864+
{
1865+
Input: putRequest("b", "2"),
1866+
Call: 3,
1867+
Return: 4,
1868+
},
1869+
},
1870+
},
1871+
},
1872+
persistedRequests: []model.EtcdRequest{
1873+
putRequest("a", "1"),
1874+
putRequest("b", "2"),
1875+
},
1876+
},
1877+
{
1878+
name: "Linearizable - concurrent atomic txn - pass",
1879+
reports: []report.ClientReport{
1880+
{
1881+
Watch: []model.WatchOperation{
1882+
{
1883+
Request: model.WatchRequest{
1884+
WithPrefix: true,
1885+
},
1886+
Responses: []model.WatchResponse{
1887+
{
1888+
Events: []model.WatchEvent{
1889+
putWatchEvent("a", "1", 2, true),
1890+
putWatchEvent("b", "2", 2, true),
1891+
},
1892+
},
1893+
},
1894+
},
1895+
},
1896+
KeyValue: []porcupine.Operation{
1897+
{
1898+
Input: model.EtcdRequest{
1899+
Type: model.Txn,
1900+
Txn: &model.TxnRequest{
1901+
OperationsOnSuccess: []model.EtcdOperation{
1902+
{
1903+
Type: model.PutOperation,
1904+
Put: model.PutOptions{
1905+
Key: "a",
1906+
Value: model.ToValueOrHash("1"),
1907+
},
1908+
},
1909+
{
1910+
Type: model.PutOperation,
1911+
Put: model.PutOptions{
1912+
Key: "b",
1913+
Value: model.ToValueOrHash("2"),
1914+
},
1915+
},
1916+
},
1917+
},
1918+
},
1919+
Call: 1,
1920+
Return: 2,
1921+
},
1922+
},
1923+
},
1924+
},
1925+
persistedRequests: []model.EtcdRequest{
1926+
{
1927+
Type: model.Txn,
1928+
Txn: &model.TxnRequest{
1929+
OperationsOnSuccess: []model.EtcdOperation{
1930+
{
1931+
Type: model.PutOperation,
1932+
Put: model.PutOptions{
1933+
Key: "a",
1934+
Value: model.ToValueOrHash("1"),
1935+
},
1936+
},
1937+
{
1938+
Type: model.PutOperation,
1939+
Put: model.PutOptions{
1940+
Key: "b",
1941+
Value: model.ToValueOrHash("2"),
1942+
},
1943+
},
1944+
},
1945+
},
1946+
},
1947+
},
1948+
},
1949+
{
1950+
name: "Linearizable - non-atomic unordered events - fail",
1951+
reports: []report.ClientReport{
1952+
{
1953+
Watch: []model.WatchOperation{
1954+
{
1955+
Request: model.WatchRequest{
1956+
WithPrefix: true,
1957+
},
1958+
Responses: []model.WatchResponse{
1959+
{
1960+
Events: []model.WatchEvent{
1961+
putWatchEvent("b", "2", 3, true),
1962+
putWatchEvent("a", "1", 2, true),
1963+
},
1964+
},
1965+
},
1966+
},
1967+
},
1968+
KeyValue: []porcupine.Operation{
1969+
{
1970+
Input: putRequest("a", "1"),
1971+
Call: 1,
1972+
Return: 2,
1973+
},
1974+
{
1975+
Input: putRequest("b", "2"),
1976+
Call: 3,
1977+
Return: 4,
1978+
},
1979+
},
1980+
},
1981+
},
1982+
persistedRequests: []model.EtcdRequest{
1983+
putRequest("a", "1"),
1984+
putRequest("b", "2"),
1985+
},
1986+
expectError: errBrokeOrdered.Error(),
1987+
},
18381988
}
18391989
for _, tc := range tcs {
18401990
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)