Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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 deletion coderd/coderdtest/coderdtest.go
Original file line number Diff line number Diff 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 deletions testutil/parallel.go
Original file line number Diff line number Diff 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 deletions testutil/parallel_test.go
Original file line number Diff line number Diff 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