Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data race при прогонке тестов #133

Closed
NikolayOskin opened this issue Apr 5, 2022 · 1 comment
Closed

Data race при прогонке тестов #133

NikolayOskin opened this issue Apr 5, 2022 · 1 comment

Comments

@NikolayOskin
Copy link
Contributor

При прогонке тестов возник data-race. Версия gonkey v1.12.0.

Привожу записи из лога:

build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m WARNING: DATA RACE
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m Write at 0x00c000609890 by goroutine 40:
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m github.com/lamoda/gonkey/mocks.(*ServiceMock).ServeHTTP()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /go/pkg/mod/github.com/lamoda/[email protected]/mocks/service_mock.go:64 +0x1f3
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m net/http.serverHandler.ServeHTTP()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /usr/local/go/src/net/http/server.go:2878 +0x89a
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m net/http.(*conn).serve()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /usr/local/go/src/net/http/server.go:1929 +0x12e4
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m net/http.(*Server).Serve- dwrap- 82()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /usr/local/go/src/net/http/server.go:3033 +0x58
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m Previous read at 0x00c000609890 by goroutine 62:
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m github.com/lamoda/gonkey/mocks.(*ServiceMock).EndRunningContext()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /go/pkg/mod/github.com/lamoda/[email protected]/mocks/service_mock.go:88 +0x84
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m github.com/lamoda/gonkey/mocks.(*Mocks).EndRunningContext()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /go/pkg/mod/github.com/lamoda/[email protected]/mocks/mocks.go:85 +0x124
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m github.com/lamoda/gonkey/runner.(*Runner).executeTest()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /go/pkg/mod/github.com/lamoda/[email protected]/runner/runner.go:180 +0x995
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m github.com/lamoda/gonkey/runner.(*Runner).Run()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /go/pkg/mod/github.com/lamoda/[email protected]/runner/runner.go:75 +0x1f0
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m github.com/lamoda/gonkey/runner.RunWithTesting()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /go/pkg/mod/github.com/lamoda/[email protected]/runner/runner_testing.go:98 +0x10fc
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m stash.lamoda.ru/payment/payment-gate/tests/gonkey.TestRunner.Run()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /app/tests/gonkey/test_runner.go:101 +0xbb9
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m stash.lamoda.ru/payment/payment-gate/tests/gonkey.TestRefundNeg()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /app/tests/gonkey/commandbox_test.go:49 +0x204
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m testing.tRunner()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /usr/local/go/src/testing/testing.go:1259 +0x22f
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m testing.(*T).Run- dwrap- 21()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /usr/local/go/src/testing/testing.go:1306 +0x47
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m Goroutine 40 (running) created at:
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m net/http.(*Server).Serve()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /usr/local/go/src/net/http/server.go:3033 +0x847
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m github.com/lamoda/gonkey/mocks.(*ServiceMock).StartServerWithAddr- dwrap- 3()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /go/pkg/mod/github.com/lamoda/[email protected]/mocks/service_mock.go:40 +0x58
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m Goroutine 62 (running) created at:
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m testing.(*T).Run()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /usr/local/go/src/testing/testing.go:1306 +0x726
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m testing.runTests.func1()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /usr/local/go/src/testing/testing.go:1598 +0x99
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m testing.tRunner()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /usr/local/go/src/testing/testing.go:1259 +0x22f
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m testing.runTests()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /usr/local/go/src/testing/testing.go:1596 +0x7ca
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m testing.(*M).Run()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m /usr/local/go/src/testing/testing.go:1504 +0x9d1
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m main.main()
build 01-Apr-2022 15:14:49 [36mpayment-gate-test |[0m _testmain.go:149 +0x324

В методе (*mocks.ServiceMock).ServeHTTP() происходит перезапись слайса m.errors.

func (m *ServiceMock) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	m.Lock()
	defer m.Unlock()

	if m.mock != nil {
		errs := m.mock.Execute(w, r)
		m.errors = append(m.errors, errs...)
	}
}

А в методе (*mocks.ServiceMock).EndRunningContext(), происходит чтение из m.errors слайса. И оно мьютексом не закрыто. Получается race condition.

func (m *ServiceMock) EndRunningContext() []error {
	errs := append(m.errors, m.mock.EndRunningContext()...)
	for i, e := range errs {
		errs[i] = &Error{
			error:       e,
			ServiceName: m.ServiceName,
		}
	}
	return errs
}
architectv added a commit to architectv/gonkey that referenced this issue May 11, 2022
Cdayz pushed a commit that referenced this issue May 12, 2022
@fetinin
Copy link
Contributor

fetinin commented Jan 9, 2023

Fixed in #155

@fetinin fetinin closed this as completed Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants