From 8eb91d0e155427c1d4fa2d89a40177cac5af5bcc Mon Sep 17 00:00:00 2001 From: Akshay Nanavare Date: Tue, 14 May 2024 17:52:27 +0530 Subject: [PATCH] add error constants in validate pkg Signed-off-by: Akshay Nanavare --- tests/robustness/validate/operations.go | 10 ++++++++-- tests/robustness/validate/operations_test.go | 10 +++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/robustness/validate/operations.go b/tests/robustness/validate/operations.go index 6504ebfb4..a2cc10d41 100644 --- a/tests/robustness/validate/operations.go +++ b/tests/robustness/validate/operations.go @@ -15,6 +15,7 @@ package validate import ( + "errors" "fmt" "time" @@ -26,6 +27,11 @@ import ( "go.etcd.io/etcd/tests/v3/robustness/report" ) +var ( + errRespNotMatched = errors.New("response didn't match expected") + errFutureRevRespRequested = errors.New("request about a future rev with response") +) + func validateLinearizableOperationsAndVisualize(lg *zap.Logger, operations []porcupine.Operation, timeout time.Duration) (result porcupine.CheckResult, visualize func(basepath string) error) { lg.Info("Validating linearizable operations", zap.Duration("timeout", timeout)) start := time.Now() @@ -86,14 +92,14 @@ func validateSerializableRead(lg *zap.Logger, replay *model.EtcdReplay, request return nil } lg.Error("Failed validating serializable operation", zap.Any("request", request), zap.Any("response", response)) - return fmt.Errorf("request about a future rev with response") + return errFutureRevRespRequested } _, expectResp := state.Step(request) if diff := cmp.Diff(response.EtcdResponse.Range, expectResp.Range); diff != "" { lg.Error("Failed validating serializable operation", zap.Any("request", request), zap.String("diff", diff)) - return fmt.Errorf("response didn't match expected") + return errRespNotMatched } return nil } diff --git a/tests/robustness/validate/operations_test.go b/tests/robustness/validate/operations_test.go index 14f9f6a9c..3117322c7 100644 --- a/tests/robustness/validate/operations_test.go +++ b/tests/robustness/validate/operations_test.go @@ -121,7 +121,7 @@ func TestValidateSerializableOperations(t *testing.T) { ), }, }, - expectError: "response didn't match expected", + expectError: errRespNotMatched.Error(), }, { name: "Invalid count", @@ -136,7 +136,7 @@ func TestValidateSerializableOperations(t *testing.T) { Output: rangeResponse(1), }, }, - expectError: "response didn't match expected", + expectError: errRespNotMatched.Error(), }, { name: "Invalid keys", @@ -153,7 +153,7 @@ func TestValidateSerializableOperations(t *testing.T) { ), }, }, - expectError: "response didn't match expected", + expectError: errRespNotMatched.Error(), }, { name: "Invalid revision", @@ -171,7 +171,7 @@ func TestValidateSerializableOperations(t *testing.T) { ), }, }, - expectError: "response didn't match expected", + expectError: errRespNotMatched.Error(), }, { name: "Error", @@ -218,7 +218,7 @@ func TestValidateSerializableOperations(t *testing.T) { Output: rangeResponse(0), }, }, - expectError: "request about a future rev with response", + expectError: errFutureRevRespRequested.Error(), }, { name: "Future rev failure",