Documentation ¶
Index ¶
- func AllEqual[T comparable](elems ...T) bool
- func AssertJSONEqual(t tests.TestingT, x []byte, y []byte)
- func BatchSplit[T any](list []T, max int) (out [][]T, err error)
- func Context(t *testing.T) context.Contextdeprecated
- func ContextFromChan(chStop <-chan struct{}) (context.Context, context.CancelFunc)
- func ContextWithDeadlineFn(ctx context.Context, deadlineFn func(orig time.Time) time.Time) (context.Context, context.CancelFunc)
- func GetRandomPort() string
- func HashReport(ctx types.ReportContext, r types.Report) ([]byte, error)
- func IsPortOpen(t *testing.T, port string) bool
- func IsZero[C comparable](val C) bool
- func JustError(_ interface{}, err error) error
- func MustRandomPort(t *testing.T) string
- func RawReportContext(repctx types.ReportContext) [3][32]byte
- func WaitGroupChan(wg *sync.WaitGroup) <-chan struct{}
- func WithJitter(d time.Duration) time.Duration
- func WrapIfError(err *error, msg string)
- type DependentAwaiter
- type Durationdeprecated
- type LazyLoad
- type SleeperTask
- type StartStopOnce
- type Subprocesses
- type URLdeprecated
- func MustParseURL(s string) *URLdeprecated
- func ParseURL(s string) (*URL, error)deprecated
- type Worker
- type WorkerCtx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllEqual ¶
func AllEqual[T comparable](elems ...T) bool
AllEqual returns true iff all the provided elements are equal to each other.
func AssertJSONEqual ¶
AssertJSONEqual is a helper function to assert that two JSON objects are equal.
When they are not equal, it fails the test and provides a helpful diff.
func BatchSplit ¶
BatchSplit splits an slices into an slices of slicess with a maximum length
func ContextFromChan ¶
func ContextFromChan(chStop <-chan struct{}) (context.Context, context.CancelFunc)
ContextFromChan creates a context that finishes when the provided channel receives or is closed. When channel closes, the ctx.Err() will always be context.Canceled NOTE: Spins up a goroutine that exits on cancellation. REMEMBER TO CALL CANCEL OTHERWISE IT CAN LEAD TO MEMORY BCF-3067 LEAKS
func ContextWithDeadlineFn ¶
func ContextWithDeadlineFn(ctx context.Context, deadlineFn func(orig time.Time) time.Time) (context.Context, context.CancelFunc)
ContextWithDeadlineFn returns a copy of the parent context with the deadline modified by deadlineFn. deadlineFn will only be called if the parent has a deadline. The new deadline must be sooner than the old to have an effect.
func GetRandomPort ¶
func GetRandomPort() string
func HashReport ¶
HashReport returns a report digest using SHA256 hash.
func IsZero ¶
func IsZero[C comparable](val C) bool
func MustRandomPort ¶
func RawReportContext ¶
func RawReportContext(repctx types.ReportContext) [3][32]byte
RawReportContext is a copy of evmutil.RawReportContext to avoid importing go-ethereum. github.com/smartcontractkit/libocr/offchainreporting2plus/chains/evmutil#RawReportContext
func WaitGroupChan ¶
WaitGroupChan creates a channel that closes when the provided sync.WaitGroup is done.
func WithJitter ¶
WithJitter adds +/- 10% to a duration. Deprecated: use timeutil.WithJitter
func WrapIfError ¶
WrapIfError decorates an error with the given message. It is intended to be used with `defer` statements, like so:
func SomeFunction() (err error) { defer WrapIfError(&err, "error in SomeFunction:") ... }
Types ¶
type DependentAwaiter ¶
type DependentAwaiter interface { AwaitDependents() <-chan struct{} AddDependents(n int) DependentReady() }
DependentAwaiter contains Dependent funcs
func NewDependentAwaiter ¶
func NewDependentAwaiter() DependentAwaiter
NewDependentAwaiter creates a new DependentAwaiter
type Duration
deprecated
type LazyLoad ¶
type LazyLoad[T any] struct { // contains filtered or unexported fields }
func NewLazyLoad ¶
type SleeperTask ¶
type SleeperTask struct { services.StateMachine // contains filtered or unexported fields }
SleeperTask represents a task that waits in the background to process some work.
func NewSleeperTask ¶
func NewSleeperTask(w Worker) *SleeperTask
NewSleeperTask takes a worker and returns a SleeperTask.
SleeperTask is guaranteed to call Work on the worker at least once for every WakeUp call. If the Worker is busy when WakeUp is called, the Worker will be called again immediately after it is finished. For this reason you should take care to make sure that Worker is idempotent. WakeUp does not block.
func NewSleeperTaskCtx ¶ added in v0.4.0
func NewSleeperTaskCtx(w WorkerCtx) *SleeperTask
NewSleeperTaskCtx is like NewSleeperTask but accepts a WorkerCtx with a context.Context.
func (*SleeperTask) WakeUp ¶
func (s *SleeperTask) WakeUp()
WakeUp wakes up the sleeper task, asking it to execute its Worker.
func (*SleeperTask) WakeUpIfStarted ¶
func (s *SleeperTask) WakeUpIfStarted() bool
func (*SleeperTask) WorkDone ¶
func (s *SleeperTask) WorkDone() <-chan struct{}
WorkDone isn't part of the SleeperTask interface, but can be useful in tests to assert that the work has been done.
type StartStopOnce ¶
type StartStopOnce = services.StateMachine
StartStopOnce can be embedded in a struct to help implement types.Service. Deprecated: use services.StateMachine
type Subprocesses ¶
type Subprocesses struct {
// contains filtered or unexported fields
}
Subprocesses is an abstraction over the following pattern of sync.WaitGroup:
var wg sync.Subprocesses wg.Add(1) go func() { defer wg.Done() ... }() Which becomes: var subs utils.Subprocesses subs.Go(func() { ... })
Note that it's important to not call Subprocesses.Wait() when there are no `Go()`ed functions in progress. This will panic. There are two cases when this can happen:
- all the `Go()`ed functions started before the call to `Wait()` have already returned, maybe because a system-wide error or an already cancelled context.
- Wait() gets called before any function is executed with `Go()`.
Reusing a Subprocesses instance is discouraged. See mode details here https://pkg.go.dev/sync#WaitGroup.Add
func (*Subprocesses) Go ¶
func (s *Subprocesses) Go(f func())
Go calls the given function in a new goroutine.
func (*Subprocesses) Wait ¶
func (s *Subprocesses) Wait()
Wait blocks until all function calls from the Go method have returned.
type Worker ¶
type Worker interface { Work() Name() string }
Worker is a simple interface that represents some work to do repeatedly
func SleeperFuncTask ¶
SleeperFuncTask returns a Worker to execute the given work function.