forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_helpers.go
32 lines (25 loc) · 1.04 KB
/
context_helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package tests
import (
"context"
"time"
"github.com/ava-labs/avalanchego/wallet/subnet/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))
}