mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests/robustness: Provide a response diff in model test to make debugging easier
Signed-off-by: Marek Siarkowicz <serathius@users.noreply.github.com>
This commit is contained in:
parent
a708bed336
commit
f410c6e6df
@ -15,8 +15,11 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"go.etcd.io/etcd/api/v3/mvccpb"
|
||||
)
|
||||
|
||||
@ -26,14 +29,22 @@ func TestModelDeterministic(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
state := DeterministicModel.Init()
|
||||
for _, op := range tc.operations {
|
||||
t.Logf("state: %v", state)
|
||||
ok, newState := DeterministicModel.Step(state, op.req, op.resp)
|
||||
if op.expectFailure == ok {
|
||||
t.Logf("state: %v", state)
|
||||
t.Errorf("Unexpected operation result, expect: %v, got: %v, operation: %s", !op.expectFailure, ok, DeterministicModel.DescribeOperation(op.req, op.resp))
|
||||
var loadedState etcdState
|
||||
err := json.Unmarshal([]byte(state.(string)), &loadedState)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to load state: %v", err)
|
||||
}
|
||||
_, resp := loadedState.step(op.req)
|
||||
t.Errorf("Response diff: %s", cmp.Diff(op.resp, resp))
|
||||
break
|
||||
}
|
||||
if ok {
|
||||
state = newState
|
||||
t.Logf("state: %v", state)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -15,9 +15,11 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -322,6 +324,16 @@ func TestModelNonDeterministic(t *testing.T) {
|
||||
if ok != !op.expectFailure {
|
||||
t.Logf("state: %v", state)
|
||||
t.Errorf("Unexpected operation result, expect: %v, got: %v, operation: %s", !op.expectFailure, ok, NonDeterministicModel.DescribeOperation(op.req, op.resp))
|
||||
var loadedState nonDeterministicState
|
||||
err := json.Unmarshal([]byte(state.(string)), &loadedState)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to load state: %v", err)
|
||||
}
|
||||
for i, s := range loadedState {
|
||||
_, resp := s.step(op.req)
|
||||
t.Errorf("For state %d, response diff: %s", i, cmp.Diff(op.resp.EtcdResponse, resp))
|
||||
}
|
||||
break
|
||||
}
|
||||
if ok {
|
||||
state = newState
|
||||
|
Loading…
x
Reference in New Issue
Block a user