Merge pull request #16046 from serathius/robusness-test-diff

tests/robustness: Provide a response diff in model test to make debugging easier
dependabot/go_modules/github.com/prometheus/procfs-0.11.0
Marek Siarkowicz 2023-06-12 10:15:43 +02:00 committed by GitHub
commit b366cda70f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -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)
}
}
})

View File

@ -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