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

feat(testutil): add testutil.IsParallel()#14418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
johnstcn wants to merge2 commits intomainfromcj/detect-parallel-test
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletioncoderd/coderdtest/coderdtest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -269,7 +269,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
options.DeploymentValues = DeploymentValues(t)
}
// This value is not safe to run in parallel.
if options.DeploymentValues.DisableOwnerWorkspaceExec {
if options.DeploymentValues.DisableOwnerWorkspaceExec.Value() && testutil.IsParallel(t) {
t.Logf("WARNING: DisableOwnerWorkspaceExec is set, this is not safe in parallel tests!")
}

Expand Down
17 changes: 17 additions & 0 deletionstestutil/parallel.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
package testutil

import "testing"

// IsParallel determines whether the current test is running with parallel set.
// The Go standard library does not currently expose this. However, we can easily
// determine this using the fact that a call to t.Setenv() after t.Parallel() will panic.
func IsParallel(t testing.TB) (parallel bool) {
t.Helper()
defer func() {
if r := recover(); r != nil {
parallel = true
}
}()
t.Setenv(t.Name()+"_PARALLEL", "")
return parallel
}
19 changes: 19 additions & 0 deletionstestutil/parallel_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
package testutil_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/coder/coder/v2/testutil"
)

// nolint:paralleltest // this is the whole point
func Test_IsParallel_False(t *testing.T) {
require.False(t, testutil.IsParallel(t))
}

func Test_IsParallel_True(t *testing.T) {
t.Parallel()
require.True(t, testutil.IsParallel(t))
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp