import "github.com/cockroachdb/cockroach/pkg/testutils"
base.go bazel.go dir.go error.go files.go keys.go net.go pprof.go soon.go sort.go subtest.go trace.go
DefaultSucceedsSoonDuration is the maximum amount of time unittests will wait for a condition to become true. See SucceedsSoon().
AllocProfileDiff writes two alloc profiles, one before running closure and one after. This is similar in spirit to passing the -memprofile flag to a test or benchmark, but make it possible to subtract out setup code, which -memprofile does not.
Example usage:
setupCode() AllocProfileDiff(t, "mem.before", "mem.after", func() { interestingCode() })
The resulting profiles are then diffed via:
go tool pprof -base mem.before mem.after
FillCerts sets the certs on a base.Config.
IsError returns true if the error string matches the supplied regex. An empty regex is interpreted to mean that a nil error is expected.
IsPError returns true if pErr's message matches the supplied regex. An empty regex is interpreted to mean that a nil error is expected.
func MakeAmbientCtx() log.AmbientContext
MakeAmbientCtx creates an AmbientContext with a Tracer in it.
MakeKey makes a new key which is the concatenation of the given inputs, in order.
MatchInOrder matches interprets the given slice of strings as a slice of regular expressions and checks that they match, in order and without overlap, against the given string. For example, if s=abcdefg and res=ab,cd,fg no error is returned, whereas res=abc,cde would return a descriptive error about failing to match cde.
NewNodeTestBaseContext creates a base context for testing. This uses embedded certs and the default node user. The default node user has both server and client certificates.
func NewTestBaseContext(user security.SQLUsername) *base.Config
NewTestBaseContext creates a secure base context for user.
ReadAllFiles reads all of the files matching pattern, thus ensuring they are in the OS buffer cache.
RunTrueAndFalse calls the provided function in a subtest, first with the boolean argument set to false and next with the boolean argument set to true.
SortStructs sorts the given slice of structs using the given fields as the ordered sort keys.
SucceedsSoon fails the test (with t.Fatal) unless the supplied function runs without error within a preset maximum duration. The function is invoked immediately at first and then successively with an exponential backoff starting at 1ns and ending at around 1s.
SucceedsSoonError returns an error unless the supplied function runs without error within a preset maximum duration. The function is invoked immediately at first and then successively with an exponential backoff starting at 1ns and ending at around 1s.
TempDir creates a directory and a function to clean it up at the end of the test.
TestDataPath returns a path to the directory containing test data files.
Test files are usually checked into the repository under "testdata" directory. If we are not using bazel, then the test executes in the directory of the actual test, so the files can be referenced via "testdata/subdir/file" relative path.
However, if we are running under bazel, the data files are specified via go_test "data" attribute. These files, in turn, are available under RUNFILES directory. This helper attempts to construct appropriate path to the RUNFILES directory containing test data files, given the relative (to the test) path components.
TestSrcDir returns the path to the "source" tree.
If running under bazel, this will point to a private, *readonly* directory containing symlinks (or copies) of the test data dependencies. This directory must be treated readonly. It's an error to try to modify anything under this directory: though the operation may succeed, the test would not be hermetic, and may fail under other environments.
WriteProfile serialized the pprof profile with the given name to a file at the given path.
type PartitionableConn struct { // We embed a net.Conn so that we inherit the interface. Note that we override // Read() and Write(). // // This embedded Conn is half of a net.Pipe(). The other half is clientConn. net.Conn // contains filtered or unexported fields }
PartitionableConn is an implementation of net.Conn that allows the client->server and/or the server->client directions to be temporarily partitioned.
A PartitionableConn wraps a provided net.Conn (the serverConn member) and forwards every read and write to it. It interposes an arbiter in front of it that's used to block reads/writes while the PartitionableConn is in the partitioned mode.
While a direction is partitioned, data sent in that direction doesn't flow. A write while partitioned will block after an internal buffer gets filled. Data written to the conn after the partition has been established is not delivered to the remote party until the partition is lifted. At that time, all the buffered data is delivered. Since data is delivered async, data written before the partition is established may or may not be blocked by the partition; use application-level ACKs if that's important.
func NewPartitionableConn(serverConn net.Conn) *PartitionableConn
NewPartitionableConn wraps serverConn in a PartitionableConn.
func (c *PartitionableConn) Finish()
Finish removes any partitions that may exist so that blocked goroutines can finish. Finish() must be called if a connection may have been left in a partitioned state.
func (c *PartitionableConn) PartitionC2S()
PartitionC2S partitions the client-to-server direction. If UnpartitionC2S() is not called, Finish() must be called.
func (c *PartitionableConn) PartitionS2C()
PartitionS2C partitions the server-to-client direction. If UnpartitionS2C() is not called, Finish() must be called.
func (c *PartitionableConn) Read(b []byte) (n int, err error)
Read is part of the net.Conn interface.
func (c *PartitionableConn) UnpartitionC2S()
UnpartitionC2S lifts an existing client-to-server partition.
func (c *PartitionableConn) UnpartitionS2C()
UnpartitionS2C lifts an existing server-to-client partition.
func (c *PartitionableConn) Write(b []byte) (n int, err error)
Write is part of the net.Conn interface.
Path | Synopsis |
---|---|
buildutil | |
colcontainerutils | |
diagutils | |
distsqlutils | |
gossiputil | |
jobutils | |
keysutils | |
kvclientutils | |
lint | Package lint tests Go code for policy and style violations, as well as detecting suspicious constructs that are typically bugs. |
lint/passes/descriptormarshal | Package descriptormarshal defines an suite of Analyzers that detects correct setting of timestamps when unmarshaling table descriptors. |
lint/passes/errcmp | Package errcmp defines an Analyzer which checks for usage of errors.Is instead of direct ==/!= comparisons. |
lint/passes/fmtsafe | |
lint/passes/hash | Package hash defines an Analyzer that detects correct use of hash.Hash. |
lint/passes/nocopy | Package nocopy defines an Analyzer that detects invalid uses of util.NoCopy. |
lint/passes/passesutil | Package passesutil provides useful functionality for implementing passes. |
lint/passes/returnerrcheck | Package returnerrcheck defines an suite of Analyzers that detects conditionals which check for a non-nil error and then proceed to return a nil error. |
lint/passes/timer | Package timer defines an Analyzer that detects correct use of timeutil.Timer. |
lint/passes/unconvert | Package unconvert defines an Analyzer that detects unnecessary type conversions. |
localtestcluster | |
pgtest | |
physicalplanutils | |
reduce | Package reduce implements a reducer core for reducing the size of test failure cases. |
reduce/reducesql | |
serverutils | |
skip | |
sqlutils | |
storageutils | |
testcluster | |
zerofields |
Package testutils imports 31 packages (graph) and is imported by 127 packages. Updated 2021-01-23. Refresh now. Tools for package owners.