gae: github.com/luci/gae/filter/featureBreaker Index | Files | Directories

package featureBreaker

import "github.com/luci/gae/filter/featureBreaker"

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

Package Files

doc.go featurebreaker.go gi.go mail.go mc.go mod.go rds.go tq.go user.go

Variables

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

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

func FilterGI Uses

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

FilterGI installs a featureBreaker info filter in the context.

func FilterMC Uses

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

FilterMC installs a featureBreaker mc filter in the context.

func FilterMail Uses

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

FilterMail installs a featureBreaker mail filter in the context.

func FilterModule Uses

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

FilterModule installs a featureBreaker module filter in the context.

func FilterRDS Uses

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

FilterRDS installs a featureBreaker datastore filter in the context.

func FilterTQ Uses

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

FilterTQ installs a featureBreaker TaskQueue filter in the context.

func FilterUser Uses

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

FilterUser installs a featureBreaker user filter in the context.

type BreakFeatureCallback Uses

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 Uses

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.

Directories

PathSynopsis
flakyPackage flaky can be used to emulate flaky GAE errors that happen randomly with some probability.

Package featureBreaker imports 14 packages (graph). Updated 2017-10-21. Refresh now. Tools for package owners.