Skip to content

Commit e270169

Browse files
authored
Add -race Flag to GitHub Action and Fix Data Race in CreateTailscaleNodesInUser (#2038)
* Add -race flag to Makefile and integration tests; fix data race in CreateTailscaleNodesInUser * Fix data race in ExecuteCommand by using local buffers and mutex Signed-off-by: Dongjun Na <[email protected]> * lint Signed-off-by: Dongjun Na <[email protected]> --------- Signed-off-by: Dongjun Na <[email protected]>
1 parent 7d937c6 commit e270169

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ build:
2222
dev: lint test build
2323

2424
test:
25-
gotestsum -- -short -coverprofile=coverage.out ./...
25+
gotestsum -- -short -race -coverprofile=coverage.out ./...
2626

2727
test_integration:
2828
docker run \
@@ -33,7 +33,7 @@ test_integration:
3333
-v /var/run/docker.sock:/var/run/docker.sock \
3434
-v $$PWD/control_logs:/tmp/control \
3535
golang:1 \
36-
go run gotest.tools/gotestsum@latest -- -failfast ./... -timeout 120m -parallel 8
36+
go run gotest.tools/gotestsum@latest -- -race -failfast ./... -timeout 120m -parallel 8
3737

3838
lint:
3939
golangci-lint run --fix --timeout 10m

integration/dockertestutil/execute.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ type ExecuteCommandOption func(*ExecuteCommandConfig) error
2525
func ExecuteCommandTimeout(timeout time.Duration) ExecuteCommandOption {
2626
return ExecuteCommandOption(func(conf *ExecuteCommandConfig) error {
2727
conf.timeout = timeout
28-
2928
return nil
3029
})
3130
}
@@ -67,6 +66,7 @@ func ExecuteCommand(
6766
StdErr: &stderr,
6867
},
6968
)
69+
7070
resultChan <- result{exitCode, err}
7171
}()
7272

@@ -88,7 +88,6 @@ func ExecuteCommand(
8888

8989
return stdout.String(), stderr.String(), nil
9090
case <-time.After(execConfig.timeout):
91-
9291
return stdout.String(), stderr.String(), fmt.Errorf("command failed, stderr: %s: %w", stderr.String(), ErrDockertestCommandTimeout)
9392
}
9493
}

integration/scenario.go

+4
Original file line numberDiff line numberDiff line change
@@ -372,18 +372,22 @@ func (s *Scenario) CreateTailscaleNodesInUser(
372372
cert := headscale.GetCert()
373373
hostname := headscale.GetHostname()
374374

375+
s.mu.Lock()
375376
opts = append(opts,
376377
tsic.WithCACert(cert),
377378
tsic.WithHeadscaleName(hostname),
378379
)
380+
s.mu.Unlock()
379381

380382
user.createWaitGroup.Go(func() error {
383+
s.mu.Lock()
381384
tsClient, err := tsic.New(
382385
s.pool,
383386
version,
384387
s.network,
385388
opts...,
386389
)
390+
s.mu.Unlock()
387391
if err != nil {
388392
return fmt.Errorf(
389393
"failed to create tailscale (%s) node: %w",

0 commit comments

Comments
 (0)