mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
fix: avoid data racing
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package hrp
|
package hrp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -9,49 +8,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestBuildURL(t *testing.T) {
|
||||||
var url string
|
var url string
|
||||||
url = buildURL("https://postman-echo.com", "/get")
|
url = buildURL("https://postman-echo.com", "/get")
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
fmt.Println("[TestMain] build go plugin")
|
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")
|
cmd := exec.Command("go", "build", "-buildmode=plugin", `-race`, "-o=examples/debugtalk.so", "examples/plugin/debugtalk.go")
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -21,6 +22,49 @@ func TestMain(m *testing.M) {
|
|||||||
os.Exit(m.Run())
|
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) {
|
func TestCallPluginFunction(t *testing.T) {
|
||||||
parser := newParser()
|
parser := newParser()
|
||||||
parser.loadPlugin("examples/debugtalk.so")
|
parser.loadPlugin("examples/debugtalk.so")
|
||||||
|
|||||||
@@ -477,8 +477,16 @@ func (r *caseRunner) runStepTestCase(step *TStep) (stepResult *stepData, err err
|
|||||||
success: false,
|
success: false,
|
||||||
}
|
}
|
||||||
testcase := step.TestCase
|
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()
|
start := time.Now()
|
||||||
err = r.hrpRunner.newCaseRunner(testcase).run()
|
err = r.hrpRunner.newCaseRunner(copiedTestCase).run()
|
||||||
stepResult.elapsed = time.Since(start).Milliseconds()
|
stepResult.elapsed = time.Since(start).Milliseconds()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return stepResult, err
|
return stepResult, err
|
||||||
|
|||||||
Reference in New Issue
Block a user