test: Make sure tests that change global state are not executed concurrently.

This commit is contained in:
Joachim Bauch 2024-05-14 16:51:20 +02:00
parent a50d637107
commit 4603b2b290
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
3 changed files with 5 additions and 2 deletions

View file

@ -28,6 +28,9 @@ import (
)
func UpdateCertificateCheckIntervalForTest(t *testing.T, interval time.Duration) {
t.Helper()
// Make sure test is not executed with "t.Parallel()"
t.Setenv("PARALLEL_CHECK", "1")
old := deduplicateWatchEvents.Load()
t.Cleanup(func() {
deduplicateWatchEvents.Store(old)

View file

@ -98,7 +98,6 @@ func NewGrpcServerForTest(t *testing.T) (server *GrpcServer, addr string) {
}
func Test_GrpcServer_ReloadCerts(t *testing.T) {
t.Parallel()
CatchLogForTest(t)
key, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {
@ -180,7 +179,6 @@ func Test_GrpcServer_ReloadCerts(t *testing.T) {
}
func Test_GrpcServer_ReloadCA(t *testing.T) {
t.Parallel()
CatchLogForTest(t)
serverKey, err := rsa.GenerateKey(rand.Reader, 1024)
if err != nil {

View file

@ -36,6 +36,8 @@ var listenSignalOnce sync.Once
func ensureNoGoroutinesLeak(t *testing.T, f func(t *testing.T)) {
t.Helper()
// Make sure test is not executed with "t.Parallel()"
t.Setenv("PARALLEL_CHECK", "1")
// The signal package will start a goroutine the first time "signal.Notify"
// is called. Do so outside the function under test so the signal goroutine