From d67764e49c2310e9104f2c266369260f239cdd4f Mon Sep 17 00:00:00 2001 From: xucong053 Date: Mon, 4 Jul 2022 17:14:39 +0800 Subject: [PATCH] fix: data race --- go.mod | 3 +-- go.sum | 5 +---- hrp/boomer.go | 5 +++++ hrp/runner.go | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 1bc11398..9f476f80 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/httprunner/httprunner/v4 -go 1.18 +go 1.16 require ( github.com/andybalholm/brotli v1.0.4 @@ -17,7 +17,6 @@ require ( github.com/jmespath/go-jmespath v0.4.0 github.com/json-iterator/go v1.1.12 github.com/maja42/goval v1.2.1 - github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mitchellh/mapstructure v1.4.1 github.com/olekukonko/tablewriter v0.0.5 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index a36ed4ad..97bee3a8 100644 --- a/go.sum +++ b/go.sum @@ -335,9 +335,8 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= -github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= @@ -408,8 +407,6 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= -github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= diff --git a/hrp/boomer.go b/hrp/boomer.go index 87c6c809..0f66c1ff 100644 --- a/hrp/boomer.go +++ b/hrp/boomer.go @@ -289,6 +289,9 @@ func (b *HRPBoomer) convertBoomerTask(testcase *TestCase, rendezvousList []*Rend // reset start time only once once := sync.Once{} + // update session variables mutex + mutex := sync.Mutex{} + return &boomer.Task{ Name: testcase.Config.Name, Weight: testcase.Config.Weight, @@ -299,9 +302,11 @@ func (b *HRPBoomer) convertBoomerTask(testcase *TestCase, rendezvousList []*Rend // init session runner sessionRunner := caseRunner.newSession() + mutex.Lock() if parametersIterator.HasNext() { sessionRunner.updateSessionVariables(parametersIterator.Next()) } + mutex.Unlock() startTime := time.Now() for _, step := range testcase.TestSteps { diff --git a/hrp/runner.go b/hrp/runner.go index 63a3098a..60389d03 100644 --- a/hrp/runner.go +++ b/hrp/runner.go @@ -281,7 +281,7 @@ func (r *HRPRunner) newCaseRunner(testcase *TestCase) (*testCaseRunner, error) { timeout := time.Duration(runner.testCase.Config.Timeout*1000) * time.Millisecond runner.hrpRunner.SetTimeout(timeout) } - if plugin.Path() != "" { + if plugin != nil { pluginContent, err := builtin.ReadFile(plugin.Path()) if err != nil { return nil, err