mirror of
https://github.com/luxfi/node.git
synced 2026-07-27 03:39:39 +00:00
33 lines
1.0 KiB
Go
33 lines
1.0 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package tests
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/luxfi/node/wallet/network/primary/common"
|
|
)
|
|
|
|
// A long default timeout used to timeout failed operations but unlikely to induce
|
|
// flaking due to unexpected resource contention.
|
|
const DefaultTimeout = 2 * time.Minute
|
|
|
|
// Helper simplifying use of a timed context by canceling the context with the test context.
|
|
func ContextWithTimeout(tc TestContext, duration time.Duration) context.Context {
|
|
ctx, cancel := context.WithTimeout(context.Background(), duration)
|
|
tc.DeferCleanup(cancel)
|
|
return ctx
|
|
}
|
|
|
|
// Helper simplifying use of a timed context configured with the default timeout.
|
|
func DefaultContext(tc TestContext) context.Context {
|
|
return ContextWithTimeout(tc, DefaultTimeout)
|
|
}
|
|
|
|
// Helper simplifying use via an option of a timed context configured with the default timeout.
|
|
func WithDefaultContext(tc TestContext) common.Option {
|
|
return common.WithContext(DefaultContext(tc))
|
|
}
|