cweill / gotests

Automatically generate Go test boilerplate from your source code.
Apache License 2.0
4.95k stars 345 forks source link

race condition in tests #154

Closed butuzov closed 3 years ago

butuzov commented 3 years ago

While adding tests for the named* feature runnned into the race condition in tests.

go test -v ./... -count 10

can end up as...

1) if #151 merged:

go test -v ./... -count 10 | grep TestGenerateTests/Entire_testdata_directory -A20 -B20

=== RUN   TestGenerateTests/Entire_testdata_directory
fatal error: concurrent map read and map write

2) if #151 not merged:

 go test -v ./... -count 10 | grep TestGenerateTests/Entire_testdata_directory -A20 -B20

=== RUN   TestGenerateTests/Entire_testdata_directory
    gotests_test.go:846: "Entire testdata directory". GenerateTests(testdata/) error = output.Process: render.Header: template: no template "header" associated with template "render", wantErr false
--- FAIL: TestGenerateTests/Entire_testdata_directory (0.76s)
---------------------------------------------------------------
=== RUN   TestGenerateTests/Entire_testdata_directory
    gotests_test.go:846: "Entire testdata directory". GenerateTests(testdata/) error = output.Process: render.TestFunction: template: no template "function" associated with template "render", wantErr false
--- FAIL: TestGenerateTests/Entire_testdata_directory (0.64s)
---------------------------------------------------------------
=== RUN   TestGenerateTests/Entire_testdata_directory
--- PASS: TestGenerateTests/Entire_testdata_directory (2.49s)
---------------------------------------------------------------
=== RUN   TestGenerateTests/Entire_testdata_directory
    gotests_test.go:846: "Entire testdata directory". GenerateTests(testdata/) error = output.Process: render.TestFunction: template: no template "function" associated with template "render", wantErr false
--- FAIL: TestGenerateTests/Entire_testdata_directory (0.32s)
---------------------------------------------------------------
=== RUN   TestGenerateTests/Entire_testdata_directory
    gotests_test.go:846: "Entire testdata directory". GenerateTests(testdata/) error = output.Process: render.TestFunction: template: no template "function" associated with template "render", wantErr false
--- FAIL: TestGenerateTests/Entire_testdata_directory (0.36s)
---------------------------------------------------------------
=== RUN   TestGenerateTests/Entire_testdata_directory
    gotests_test.go:846: "Entire testdata directory". GenerateTests(testdata/) error = output.Process: render.Header: template: no template "header" associated with template "render", wantErr false
--- FAIL: TestGenerateTests/Entire_testdata_directory (0.37s)
---------------------------------------------------------------
=== RUN   TestGenerateTests/Entire_testdata_directory
    gotests_test.go:846: "Entire testdata directory". GenerateTests(testdata/) error = output.Process: render.Header: template: no template "header" associated with template "render", wantErr false
--- FAIL: TestGenerateTests/Entire_testdata_directory (0.72s)
---------------------------------------------------------------
=== RUN   TestGenerateTests/Entire_testdata_directory
    gotests_test.go:846: "Entire testdata directory". GenerateTests(testdata/) error = output.Process: render.Header: template: no template "header" associated with template "render", wantErr false
--- FAIL: TestGenerateTests/Entire_testdata_directory (0.98s)
---------------------------------------------------------------
=== RUN   TestGenerateTests/Entire_testdata_directory
    gotests_test.go:846: "Entire testdata directory". GenerateTests(testdata/) error = output.Process: render.Header: template: no template "header" associated with template "render", wantErr false
--- FAIL: TestGenerateTests/Entire_testdata_directory (0.69s)
---------------------------------------------------------------
=== RUN   TestGenerateTests/Entire_testdata_directory
    gotests_test.go:846: "Entire testdata directory". GenerateTests(testdata/) error = output.Process: render.TestFunction: template: render:65:15: executing "function" at <{{template "results" $f}}>: template "results" not defined, wantErr false
--- FAIL: TestGenerateTests/Entire_testdata_directory (1.08s)

Both happen for different reasons. #151 will fix the second part but not the first one.