mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-18 14:07:34 +00:00
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 <kmu5544616@gmail.com> * lint Signed-off-by: Dongjun Na <kmu5544616@gmail.com> --------- Signed-off-by: Dongjun Na <kmu5544616@gmail.com>
This commit is contained in:
parent
7d937c6bd0
commit
e270169c13
4
Makefile
4
Makefile
@ -22,7 +22,7 @@ build:
|
|||||||
dev: lint test build
|
dev: lint test build
|
||||||
|
|
||||||
test:
|
test:
|
||||||
gotestsum -- -short -coverprofile=coverage.out ./...
|
gotestsum -- -short -race -coverprofile=coverage.out ./...
|
||||||
|
|
||||||
test_integration:
|
test_integration:
|
||||||
docker run \
|
docker run \
|
||||||
@ -33,7 +33,7 @@ test_integration:
|
|||||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||||
-v $$PWD/control_logs:/tmp/control \
|
-v $$PWD/control_logs:/tmp/control \
|
||||||
golang:1 \
|
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:
|
lint:
|
||||||
golangci-lint run --fix --timeout 10m
|
golangci-lint run --fix --timeout 10m
|
||||||
|
@ -25,7 +25,6 @@ type ExecuteCommandOption func(*ExecuteCommandConfig) error
|
|||||||
func ExecuteCommandTimeout(timeout time.Duration) ExecuteCommandOption {
|
func ExecuteCommandTimeout(timeout time.Duration) ExecuteCommandOption {
|
||||||
return ExecuteCommandOption(func(conf *ExecuteCommandConfig) error {
|
return ExecuteCommandOption(func(conf *ExecuteCommandConfig) error {
|
||||||
conf.timeout = timeout
|
conf.timeout = timeout
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -67,6 +66,7 @@ func ExecuteCommand(
|
|||||||
StdErr: &stderr,
|
StdErr: &stderr,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
resultChan <- result{exitCode, err}
|
resultChan <- result{exitCode, err}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -88,7 +88,6 @@ func ExecuteCommand(
|
|||||||
|
|
||||||
return stdout.String(), stderr.String(), nil
|
return stdout.String(), stderr.String(), nil
|
||||||
case <-time.After(execConfig.timeout):
|
case <-time.After(execConfig.timeout):
|
||||||
|
|
||||||
return stdout.String(), stderr.String(), fmt.Errorf("command failed, stderr: %s: %w", stderr.String(), ErrDockertestCommandTimeout)
|
return stdout.String(), stderr.String(), fmt.Errorf("command failed, stderr: %s: %w", stderr.String(), ErrDockertestCommandTimeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -372,18 +372,22 @@ func (s *Scenario) CreateTailscaleNodesInUser(
|
|||||||
cert := headscale.GetCert()
|
cert := headscale.GetCert()
|
||||||
hostname := headscale.GetHostname()
|
hostname := headscale.GetHostname()
|
||||||
|
|
||||||
|
s.mu.Lock()
|
||||||
opts = append(opts,
|
opts = append(opts,
|
||||||
tsic.WithCACert(cert),
|
tsic.WithCACert(cert),
|
||||||
tsic.WithHeadscaleName(hostname),
|
tsic.WithHeadscaleName(hostname),
|
||||||
)
|
)
|
||||||
|
s.mu.Unlock()
|
||||||
|
|
||||||
user.createWaitGroup.Go(func() error {
|
user.createWaitGroup.Go(func() error {
|
||||||
|
s.mu.Lock()
|
||||||
tsClient, err := tsic.New(
|
tsClient, err := tsic.New(
|
||||||
s.pool,
|
s.pool,
|
||||||
version,
|
version,
|
||||||
s.network,
|
s.network,
|
||||||
opts...,
|
opts...,
|
||||||
)
|
)
|
||||||
|
s.mu.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"failed to create tailscale (%s) node: %w",
|
"failed to create tailscale (%s) node: %w",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user