open-nomad/api/internal/testutil/slow.go
Seth Hoenig 3943dd1e16 ci: use serial testing for api in CI
This is a followup to running tests in serial in CI.
Since the API package cannot import anything outside of api/,
copy the ci.Parallel function into api/internal/testutil, and
have api tests use that.
2022-03-17 08:35:01 -05:00

31 lines
701 B
Go

package testutil
import (
"os"
"strconv"
"testing"
)
// Copy of ci/slow.go for API.
// SkipSlow skips a slow test unless NOMAD_SLOW_TEST is set to a true value.
func SkipSlow(t *testing.T, reason string) {
value := os.Getenv("NOMAD_SLOW_TEST")
run, err := strconv.ParseBool(value)
if !run || err != nil {
t.Skipf("Skipping slow test: %s", reason)
}
}
// Parallel runs t in parallel, unless CI is set to a true value.
//
// In CI (CircleCI / GitHub Actions) we get better performance by running tests
// in serial while not restricting GOMAXPROCS.
func Parallel(t *testing.T) {
value := os.Getenv("CI")
isCI, err := strconv.ParseBool(value)
if !isCI || err != nil {
t.Parallel()
}
}