Skip to content

Commit

Permalink
Add -race Flag to GitHub Action and Fix Data Race in CreateTailscaleN…
Browse files Browse the repository at this point in the history
…odesInUser (#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 <kmu5544616@gmail.com>

* lint

Signed-off-by: Dongjun Na <kmu5544616@gmail.com>

---------

Signed-off-by: Dongjun Na <kmu5544616@gmail.com>
  • Loading branch information
nadongjun authored Dec 17, 2024
1 parent 7d937c6 commit e270169
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ build:
dev: lint test build

test:
gotestsum -- -short -coverprofile=coverage.out ./...
gotestsum -- -short -race -coverprofile=coverage.out ./...

test_integration:
docker run \
Expand All @@ -33,7 +33,7 @@ test_integration:
-v /var/run/docker.sock:/var/run/docker.sock \
-v $$PWD/control_logs:/tmp/control \
golang:1 \
go run gotest.tools/gotestsum@latest -- -failfast ./... -timeout 120m -parallel 8
go run gotest.tools/gotestsum@latest -- -race -failfast ./... -timeout 120m -parallel 8

lint:
golangci-lint run --fix --timeout 10m
Expand Down
3 changes: 1 addition & 2 deletions integration/dockertestutil/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type ExecuteCommandOption func(*ExecuteCommandConfig) error
func ExecuteCommandTimeout(timeout time.Duration) ExecuteCommandOption {
return ExecuteCommandOption(func(conf *ExecuteCommandConfig) error {
conf.timeout = timeout

return nil
})
}
Expand Down Expand Up @@ -67,6 +66,7 @@ func ExecuteCommand(
StdErr: &stderr,
},
)

resultChan <- result{exitCode, err}
}()

Expand All @@ -88,7 +88,6 @@ func ExecuteCommand(

return stdout.String(), stderr.String(), nil
case <-time.After(execConfig.timeout):

return stdout.String(), stderr.String(), fmt.Errorf("command failed, stderr: %s: %w", stderr.String(), ErrDockertestCommandTimeout)
}
}
4 changes: 4 additions & 0 deletions integration/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,18 +372,22 @@ func (s *Scenario) CreateTailscaleNodesInUser(
cert := headscale.GetCert()
hostname := headscale.GetHostname()

s.mu.Lock()
opts = append(opts,
tsic.WithCACert(cert),
tsic.WithHeadscaleName(hostname),
)
s.mu.Unlock()

user.createWaitGroup.Go(func() error {
s.mu.Lock()
tsClient, err := tsic.New(
s.pool,
version,
s.network,
opts...,
)
s.mu.Unlock()
if err != nil {
return fmt.Errorf(
"failed to create tailscale (%s) node: %w",
Expand Down

0 comments on commit e270169

Please sign in to comment.