mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
fix: avoid data racing
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package hrp
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -9,49 +8,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLocatePlugin(t *testing.T) {
|
||||
cwd, _ := os.Getwd()
|
||||
_, err := locatePlugin(cwd)
|
||||
if !assert.Error(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
_, err = locatePlugin("")
|
||||
if !assert.Error(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
startPath := "examples/debugtalk.so"
|
||||
_, err = locatePlugin(startPath)
|
||||
if !assert.Nil(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
startPath = "examples/demo.json"
|
||||
_, err = locatePlugin(startPath)
|
||||
if !assert.Nil(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
startPath = "examples/"
|
||||
_, err = locatePlugin(startPath)
|
||||
if !assert.Nil(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
startPath = "examples/plugin/debugtalk.go"
|
||||
_, err = locatePlugin(startPath)
|
||||
if !assert.Nil(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
startPath = "/abc"
|
||||
_, err = locatePlugin(startPath)
|
||||
if !assert.Error(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildURL(t *testing.T) {
|
||||
var url string
|
||||
url = buildURL("https://postman-echo.com", "/get")
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
fmt.Println("[TestMain] build go plugin")
|
||||
// flag -race is necessary in order to be consistent with go test
|
||||
cmd := exec.Command("go", "build", "-buildmode=plugin", `-race`, "-o=examples/debugtalk.so", "examples/plugin/debugtalk.go")
|
||||
if err := cmd.Run(); err != nil {
|
||||
panic(err)
|
||||
@@ -21,6 +22,49 @@ func TestMain(m *testing.M) {
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestLocatePlugin(t *testing.T) {
|
||||
cwd, _ := os.Getwd()
|
||||
_, err := locatePlugin(cwd)
|
||||
if !assert.Error(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
_, err = locatePlugin("")
|
||||
if !assert.Error(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
startPath := "examples/debugtalk.so"
|
||||
_, err = locatePlugin(startPath)
|
||||
if !assert.Nil(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
startPath = "examples/demo.json"
|
||||
_, err = locatePlugin(startPath)
|
||||
if !assert.Nil(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
startPath = "examples/"
|
||||
_, err = locatePlugin(startPath)
|
||||
if !assert.Nil(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
startPath = "examples/plugin/debugtalk.go"
|
||||
_, err = locatePlugin(startPath)
|
||||
if !assert.Nil(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
startPath = "/abc"
|
||||
_, err = locatePlugin(startPath)
|
||||
if !assert.Error(t, err) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallPluginFunction(t *testing.T) {
|
||||
parser := newParser()
|
||||
parser.loadPlugin("examples/debugtalk.so")
|
||||
|
||||
10
runner.go
10
runner.go
@@ -477,8 +477,16 @@ func (r *caseRunner) runStepTestCase(step *TStep) (stepResult *stepData, err err
|
||||
success: false,
|
||||
}
|
||||
testcase := step.TestCase
|
||||
|
||||
// copy testcase to avoid data racing
|
||||
copiedTestCase := &TestCase{}
|
||||
if err = copier.Copy(copiedTestCase, testcase); err != nil {
|
||||
log.Error().Err(err).Msg("copy testcase failed")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
err = r.hrpRunner.newCaseRunner(testcase).run()
|
||||
err = r.hrpRunner.newCaseRunner(copiedTestCase).run()
|
||||
stepResult.elapsed = time.Since(start).Milliseconds()
|
||||
if err != nil {
|
||||
return stepResult, err
|
||||
|
||||
Reference in New Issue
Block a user