sync_testing

package module
v0.0.0-...-575d6b3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

README

Synchronous testing utilities.

License

This software is licensed under Apache License, Version 2.0. Please see LICENSE for more information.

Copyright© 2016, Flux Factory Inc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaximizeContention

func MaximizeContention(N int, f ...func())

MaximizeContention starts N goroutines, each performing one of the provided functions, and executes all of them as concurrently as possible. If 3 functions are provided, then each function is run N/3 times.

func MaximizeContentionWithErrors

func MaximizeContentionWithErrors(N int, f ...func() error) error

MaximizeContentionWithErrors operates identically to MaximizeContention but returns a multierror with all non-nil errors.

Types

type ParallelOpTracker

type ParallelOpTracker struct {
	// contains filtered or unexported fields
}

ParallelOpTracker is a utility structure designed to help detect operations that execute in parallel. Typical usage is:

N := 1000  // approximate number of operations.
ops := NewParallelOpTracker(N)

ops.Do("sync-op")                     // never be done in parallel with other ops
MaximizeContention(N,
   func() { ops.Do("something") },    // may be done in parallel
   func() { ops.Do("other thing") })  // may be done in parallel
ops.Do("sync-op")                     // never be done in parallel with other ops

So(ops.During("sync-op"), ShouldNotContainKey, "something")
So(ops.During("sync-op"), ShouldNotContainKey, "other thing")
So(ops.During("sync-op"), ShouldNotContainKey, "sync-op")

func NewParallelOpTracker

func NewParallelOpTracker(expectedNumOps int) *ParallelOpTracker

NewParallelOpTracker returns an initialized ParallelOpTracker for the approximate number of events.

func (*ParallelOpTracker) Do

func (o *ParallelOpTracker) Do(op string)

Do performs an operation. All calls to Do() must be performed before any calls to Events() or During().

func (*ParallelOpTracker) During

func (o *ParallelOpTracker) During(op string) map[string]int

During returns a map of events that occurred during a particular op.

func (*ParallelOpTracker) Events

func (o *ParallelOpTracker) Events() []string

Events returns the ordered list of events that occurred.

Jump to

Keyboard shortcuts

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