Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6d36dda

Browse files
committed
feat(testutil): add testutil.IsParallel()
1 parentd4adfa3 commit6d36dda

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

‎coderd/coderdtest/coderdtest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
269269
options.DeploymentValues=DeploymentValues(t)
270270
}
271271
// This value is not safe to run in parallel.
272-
ifoptions.DeploymentValues.DisableOwnerWorkspaceExec {
273-
t.Logf("WARNING:DisableOwnerWorkspaceExec is set, this is not safe in parallel tests!")
272+
ifoptions.DeploymentValues.DisableOwnerWorkspaceExec.Value()&&testutil.IsParallel(t) {
273+
t.Fatal("DisableOwnerWorkspaceExec is set, this is not safe in parallel tests!")
274274
}
275275

276276
// If no ratelimits are set, disable all rate limiting for tests.

‎testutil/parallel.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package testutil
2+
3+
import"testing"
4+
5+
// IsParallel determines whether the current test is running with parallel set.
6+
// The Go standard library does not currently expose this. However, we can easily
7+
// determine this using the fact that a call to t.Setenv() after t.Parallel() will panic.
8+
funcIsParallel(t testing.TB) (parallelbool) {
9+
t.Helper()
10+
deferfunc() {
11+
ifr:=recover();r!=nil {
12+
parallel=true
13+
}
14+
}()
15+
t.Setenv(t.Name()+"_PARALLEL","")
16+
returnparallel
17+
}

‎testutil/parallel_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package testutil_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/require"
7+
8+
"github.com/coder/coder/v2/testutil"
9+
)
10+
11+
// nolint:paralleltest // this is the whole point
12+
funcTest_IsParallel_False(t*testing.T) {
13+
require.False(t,testutil.IsParallel(t))
14+
}
15+
16+
funcTest_IsParallel_True(t*testing.T) {
17+
t.Parallel()
18+
require.True(t,testutil.IsParallel(t))
19+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp