synctestutil

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

README

Package cloudeng.io/sync/synctestutil

CircleCI Go Report Card

import cloudeng.io/sync/synctestutil

Functions

Func AssertNoGoroutines
func AssertNoGoroutines(t Errorf) func()

AssertNoGoroutines is used to detect goroutine leaks.

Usage is as shown below:

func TestExample(t *testing.T) {
	defer synctestutil.AssertNoGoroutines(t, time.Second)()
	...
}

Note that in the example above AssertNoGoroutines returns a function that is immediately defered. The call to AssertNoGoroutines records the currently goroutines and the returned function will compare that initial set to those running when it is invoked. Hence, the above example is equivalent to:

func TestExample(t *testing.T) {
	fn := synctestutil.AssertNoGoroutines(t, time.Second)
	...
	fn()
}
Func AssertNoGoroutinesRacy
func AssertNoGoroutinesRacy(t Errorf, wait time.Duration) func()

AssertNoGoroutinesRacy is like AssertNoGoroutines but allows for a grace period for goroutines to terminate.

Types

Type Errorf
type Errorf interface {
	Errorf(format string, args ...interface{})
}

Errorf is called when an error is encountered and is defined so that testing.T and testing.B implement Errorf.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertNoGoroutines

func AssertNoGoroutines(t Errorf) func()

AssertNoGoroutines is used to detect goroutine leaks.

Usage is as shown below:

func TestExample(t *testing.T) {
	defer synctestutil.AssertNoGoroutines(t, time.Second)()
	...
}

Note that in the example above AssertNoGoroutines returns a function that is immediately defered. The call to AssertNoGoroutines records the currently goroutines and the returned function will compare that initial set to those running when it is invoked. Hence, the above example is equivalent to:

func TestExample(t *testing.T) {
	fn := synctestutil.AssertNoGoroutines(t, time.Second)
	...
	fn()
}

func AssertNoGoroutinesRacy

func AssertNoGoroutinesRacy(t Errorf, wait time.Duration) func()

AssertNoGoroutinesRacy is like AssertNoGoroutines but allows for a grace period for goroutines to terminate.

Types

type Errorf

type Errorf interface {
	Errorf(format string, args ...interface{})
}

Errorf is called when an error is encountered and is defined so that testing.T and testing.B implement Errorf.

Jump to

Keyboard shortcuts

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