Merge pull request #16046 from serathius/robusness-test-diff
tests/robustness: Provide a response diff in model test to make debugging easierdependabot/go_modules/github.com/prometheus/procfs-0.11.0
commit
b366cda70f
|
@ -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…
Reference in New Issue