featureBreaker

package
v0.0.0-...-01cd1ea Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0, Apache-2.0 Imports: 14 Imported by: 2

Documentation

Overview

Package featureBreaker contains filters for dynamically disabling/breaking API features at test-time.

In particular, it can be used to cause specific service methods to start returning specific errors during the test.

Index

Constants

This section is empty.

Variables

View Source
var DatastoreFeatures = []string{
	"AllocateIDs",
	"DecodeCursor",
	"Run",
	"Count",
	"BeginTransaction",
	"CommitTransaction",
	"DeleteMulti",
	"GetMulti",
	"PutMulti",
}

DatastoreFeatures is a list of datastore features that can be "broken".

Functions

This section is empty.

Types

type BreakFeatureCallback

type BreakFeatureCallback func(ctx context.Context, feature string) error

BreakFeatureCallback can be used to break features at the time of the call.

If it return an error, this error will be returned by the corresponding API call as is. If returns nil, the call will be performed as usual.

It receives a derivative of a context passed to the original API call which can be used to extract any contextual information, if necessary.

The callback will be called often and concurrently. Provide your own synchronization if necessary.

type FeatureBreaker

type FeatureBreaker interface {
	// BreakFeatures allows you to set an error that should be returned by the
	// corresponding functions.
	//
	// For example
	//   m.BreakFeatures(memcache.ErrServerError, "Add")
	//
	// would make memcache.Add return memcache.ErrServerError. You can reverse
	// this by calling UnbreakFeatures("Add").
	//
	// The only exception to this rule is two "fake" functions that can be used
	// to simulate breaking "RunInTransaction" in a more detailed way:
	//   * Use "BeginTransaction" as a feature name to simulate breaking of a new
	//     transaction attempt. It is called before each individual retry.
	//   * Use "CommitTransaction" as a feature name to simulate breaking the
	//     transaction commit RPC. It is called after the transaction body
	//     completes. Returning datastore.ErrConcurrentTransaction here will cause
	//     a retry.
	//
	// "RunInTransaction" itself is not breakable. Break "BeginTransaction" or
	// "CommitTransaction" instead.
	BreakFeatures(err error, feature ...string)

	// BreakFeaturesWithCallback is like BreakFeatures, except it allows you to
	// decide whether to return an error or not at the time the function call is
	// happening.
	//
	// The callback will be called often and concurrently. Provide your own
	// synchronization if necessary.
	//
	// You may use a callback returned by flaky.Errors(...) to emulate randomly
	// occurring errors.
	//
	// Note that the default error passed to Filter* functions are ignored when
	// using callbacks.
	BreakFeaturesWithCallback(cb BreakFeatureCallback, feature ...string)

	// UnbreakFeatures is the inverse of BreakFeatures/BreakFeaturesWithCallback,
	// and will return the named features back to their original functionality.
	UnbreakFeatures(feature ...string)
}

FeatureBreaker is the state-access interface for all Filter* functions in this package. A feature is the Name of some method on the filtered service.

So if you had:

c, fb := FilterMC(...)
mc := gae.GetMC(c)

you could do:

fb.BreakFeatures(memcache.ErrServerError, "Add", "Set")

and then

mc.Add(...) and mc.Set(...)

would return the error.

You may also pass nil as the error for BreakFeatures, and the fake will provide the DefaultError which you passed to the Filter function.

This interface can only break features which return errors.

func FilterGI

func FilterGI(c context.Context, defaultError error) (context.Context, FeatureBreaker)

FilterGI installs a featureBreaker info filter in the context.

func FilterMC

func FilterMC(c context.Context, defaultError error) (context.Context, FeatureBreaker)

FilterMC installs a featureBreaker mc filter in the context.

func FilterMail

func FilterMail(c context.Context, defaultError error) (context.Context, FeatureBreaker)

FilterMail installs a featureBreaker mail filter in the context.

func FilterModule

func FilterModule(c context.Context, defaultError error) (context.Context, FeatureBreaker)

FilterModule installs a featureBreaker module filter in the context.

func FilterRDS

func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureBreaker)

FilterRDS installs a featureBreaker datastore filter in the context.

func FilterTQ

func FilterTQ(c context.Context, defaultError error) (context.Context, FeatureBreaker)

FilterTQ installs a featureBreaker TaskQueue filter in the context.

func FilterUser

func FilterUser(c context.Context, defaultError error) (context.Context, FeatureBreaker)

FilterUser installs a featureBreaker user filter in the context.

Directories

Path Synopsis
Package flaky can be used to emulate flaky GAE errors that happen randomly with some probability.
Package flaky can be used to emulate flaky GAE errors that happen randomly with some probability.

Jump to

Keyboard shortcuts

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