Skip to content

Commit

Permalink
poison: add test for PoisonedError
Browse files Browse the repository at this point in the history
Release justification: testing only change
Release note: None
  • Loading branch information
tbg committed Mar 7, 2022
1 parent 68566b6 commit 227fbe7
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ ALL_TESTS = [
"//pkg/kv/kvserver/closedts/sidetransport:sidetransport_test",
"//pkg/kv/kvserver/closedts/tracker:tracker_test",
"//pkg/kv/kvserver/closedts:closedts_test",
"//pkg/kv/kvserver/concurrency/poison:poison_test",
"//pkg/kv/kvserver/concurrency:concurrency_test",
"//pkg/kv/kvserver/gc:gc_test",
"//pkg/kv/kvserver/idalloc:idalloc_test",
Expand Down
19 changes: 18 additions & 1 deletion pkg/kv/kvserver/concurrency/poison/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
Expand Down Expand Up @@ -42,3 +42,20 @@ go_library(
"@com_github_cockroachdb_errors//:errors",
],
)

go_test(
name = "poison_test",
srcs = ["error_test.go"],
data = glob(["testdata/**"]),
deps = [
":poison",
"//pkg/keys",
"//pkg/roachpb",
"//pkg/testutils/echotest",
"//pkg/util/hlc",
"//pkg/util/leaktest",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_redact//:redact",
"@com_github_stretchr_testify//require",
],
)
3 changes: 0 additions & 3 deletions pkg/kv/kvserver/concurrency/poison/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,3 @@ func (e *PoisonedError) Format(s fmt.State, verb rune) { errors.FormatError(e, s
func (e *PoisonedError) Error() string {
return fmt.Sprint(e)
}

// TODO(tbg): need similar init() function that ReplicaUnavailableError has,
// or PoisonError will not survive network round-trips.
39 changes: 39 additions & 0 deletions pkg/kv/kvserver/concurrency/poison/error_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package poison_test

import (
"context"
"path/filepath"
"testing"

_ "github.com/cockroachdb/cockroach/pkg/keys" // to init roachpb.PrettyPrintRange
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/poison"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/testutils/echotest"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/redact"
"github.com/stretchr/testify/require"
)

func TestPoisonedError(t *testing.T) {
defer leaktest.AfterTest(t)()
ctx := context.Background()
err := errors.DecodeError(ctx, errors.EncodeError(ctx, poison.NewPoisonedError(
roachpb.Span{Key: roachpb.Key("a")}, hlc.Timestamp{WallTime: 1},
)))
require.True(t, errors.HasType(err, (*poison.PoisonedError)(nil)), "%+v", err)
var buf redact.StringBuilder
buf.Printf("%s", err)
echotest.Require(t, string(buf.RedactableString()), filepath.Join("testdata", "poisoned_error.txt"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
echo
----
encountered poisoned latch ‹a›@0.000000001,0

0 comments on commit 227fbe7

Please sign in to comment.