util

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertSpyWaitGroupNormalUsage

func AssertSpyWaitGroupNormalUsage(t *testing.T, wg *SpyWaitGroup, threadCount int)

func IsPossiblyNegative added in v0.7.0

func IsPossiblyNegative(n int) bool

IsPossiblyNegative checks whether the integer could be a negative int32, unless its value is bigger than int32.max.

Types

type SpyWaitGroup

type SpyWaitGroup struct {
	Deltas        []int
	DeltaGoids    []int
	Awaited       bool
	AwaitedByGoid int
	// contains filtered or unexported fields
}

SpyWaitGroup provides an ability to assess whether the usage of the WaitGroup was correct. It records the sequence of calls as an array of deltas, arguments to the WaitGroup.Add() function. Additionally, it records the goid of the goroutines that performed the calls. SpyWaitGroup uses sync.WaitGroup under the hood and is thread-safe.

func (*SpyWaitGroup) Add

func (wg *SpyWaitGroup) Add(delta int)

Add remembers the delta and the goid of caller and forwards the call to sync.WaitGroup.

func (*SpyWaitGroup) Done

func (wg *SpyWaitGroup) Done()

Done is equivalent to Add(-1)

func (*SpyWaitGroup) Wait

func (wg *SpyWaitGroup) Wait()

Wait remembers the goid of the caller and sets Awaited to true. It consequently, calls sync.WaitGroup.Wait().

type WaitGroup

type WaitGroup interface {
	Add(int)
	Done()
	Wait()
}

WaitGroup allows its users to inject custom implementations that conform to sync.WaitGroup API.

Jump to

Keyboard shortcuts

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