Browse Source

test: add miniClusterMutex to prevent race conditions

- Introduce sync.Mutex to protect global state (os.Args, os.Chdir)
- Ensure serialized initialization of the mini cluster runner
- Fix intermittent race conditions during parallel test execution
pull/8147/head
Chris Lu 4 days ago
parent
commit
6fc170c645
  1. 10
      test/s3tables/s3tables_integration_test.go

10
test/s3tables/s3tables_integration_test.go

@ -12,6 +12,8 @@ import (
"testing" "testing"
"time" "time"
"sync"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -21,6 +23,10 @@ import (
flag "github.com/seaweedfs/seaweedfs/weed/util/fla9" flag "github.com/seaweedfs/seaweedfs/weed/util/fla9"
) )
var (
miniClusterMutex sync.Mutex
)
func TestS3TablesIntegration(t *testing.T) { func TestS3TablesIntegration(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("Skipping integration test in short mode") t.Skip("Skipping integration test in short mode")
@ -366,6 +372,10 @@ func startMiniCluster(t *testing.T) (*TestCluster, error) {
go func() { go func() {
defer cluster.wg.Done() defer cluster.wg.Done()
// Protect global state mutation with a mutex
miniClusterMutex.Lock()
defer miniClusterMutex.Unlock()
// Save current directory and args // Save current directory and args
oldDir, _ := os.Getwd() oldDir, _ := os.Getwd()
oldArgs := os.Args oldArgs := os.Args

Loading…
Cancel
Save