Skip to content

Commit 6b3c20b

Browse files
committed
testcontext: set DefaultTimeout from environment if available
Updates storj/storj#7217 Change-Id: I8d79906200fd16d08d3c62fcf693f24ae834fc4b
1 parent 47dfa83 commit 6b3c20b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

testcontext/context.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
// DefaultTimeout is the default timeout used by new context.
25-
const DefaultTimeout = 3 * time.Minute
25+
var DefaultTimeout = 3 * time.Minute
2626

2727
// Context is a context that has utility methods for testing and waiting for asynchronous errors.
2828
type Context struct {
@@ -66,26 +66,24 @@ type TB interface {
6666
Fatal(args ...interface{})
6767
}
6868

69-
func defaultTimeout() time.Duration {
70-
timeout := DefaultTimeout
69+
func init() {
7170
if timeoutEnv := os.Getenv("STORJ_TESTCONTEXT_TIMEOUT"); timeoutEnv != "" {
7271
var err error
73-
timeout, err = time.ParseDuration(timeoutEnv)
72+
DefaultTimeout, err = time.ParseDuration(timeoutEnv)
7473
if err != nil {
7574
panic(fmt.Sprintf("could not parse timeout %q: %v", timeoutEnv, err))
7675
}
7776
}
78-
return timeout
7977
}
8078

8179
// New creates a new test context with default timeout.
8280
func New(test TB) *Context {
83-
return NewWithContextAndTimeout(context.Background(), test, defaultTimeout())
81+
return NewWithContextAndTimeout(context.Background(), test, DefaultTimeout)
8482
}
8583

8684
// NewWithContext creates a new test context with a parent context.
8785
func NewWithContext(parentCtx context.Context, test TB) *Context {
88-
return NewWithContextAndTimeout(parentCtx, test, defaultTimeout())
86+
return NewWithContextAndTimeout(parentCtx, test, DefaultTimeout)
8987
}
9088

9189
// NewWithTimeout creates a new test context with a given timeout.

0 commit comments

Comments
 (0)