kvtest

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package kvtest provides some utilities to help test packages that use kv.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deflake

func Deflake(t *testing.T, test func(kv.Txn))

Deflake calls test repeatedly to check that all errors returned from kv.Txn methods produce failures in the test.

Deflake(t, test) will pass if and only if: test completes when given a well-behaved kv.Txn that never returns errors, and test panics when given a kv.Txn that returns errors "unpredictably".

The test func must use panic to communicate failures. It might be nice to use a *testing.T like sane people do, but this approach requires a test that can succeed successfully when the kv.Txn doesn't return any errors, and fail successfully when it does return an error. Unfortunately, the testing package doesn't support this, and we have to panic instead.

func DumpDB

func DumpDB(w io.Writer, db kv.DB)

DumpDB writes a mostly human-readable representation of the entire contents of db to w.

func New

New returns a new kv.Txn suitable for use in a unit test.

It's still important to call Close() in order to delete any temporary files created by the kv.Txn.

func NewDB

func NewDB(t *testing.T) kv.DB

NewDB returns a new kv.DB suitable for use in a unit test.

It's still important to call Close() in order to delete any temporary files created by the kv.Txn.

Types

type Flake

type Flake int

Flake is the type of error returned by a Flaky store.

func (Flake) Error

func (f Flake) Error() string

Error returns a simple human-readable string describing this flake.

type Flaky

type Flaky struct {
	kv.Txn
	// contains filtered or unexported fields
}

Flaky is a kv.Txn implemention that

Flaky counts each call to any method that could return an error as another error check. When, during a call to such a method, the number of error checks reaches a preset value, then that call will return an error.

Usage might involve running a test once with failAtCount set to zero to test the successful case and count the number of error checks, and then to run it again for each possible value of failAtCount from 1 to the number of error checks, to make sure all errors are handled appropriately.

func NewFlaky

func NewFlaky(t *testing.T, failAtCount int) *Flaky

NewFlaky returns a new Flaky that wraps the given a kv.Txn and will fail when the count of error checks reaches failAtCount.

If failAtCount is zero, the resulting Flaky will never deliberately return an error.

func (*Flaky) Alloc

func (s *Flaky) Alloc() (kv.Entity, error)

Alloc fails if the count of error checks has reached failAtCount.

func (*Flaky) ErrCheckCount

func (s *Flaky) ErrCheckCount() int

ErrCheckCount returns the total number of error checks this Flaky has counted so far.

func (*Flaky) Get

func (s *Flaky) Get(k []byte, f func([]byte) error) error

Get fails if the count of error checks has reached failAtCount.

func (*Flaky) Set

func (s *Flaky) Set(k, v []byte) error

Set fails if the count of error checks has reached failAtCount.

func (*Flaky) StackTrace

func (s *Flaky) StackTrace() string

StackTrace returns a formatted stacktrace taken from the moment an error was returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL