traPtitech / Jomon

Account Support System for traP
7 stars 3 forks source link

modelのtestでdata race #773

Open H1rono opened 5 days ago

H1rono commented 5 days ago

https://github.com/traPtitech/Jomon/actions/runs/9711575171/job/26804587744#step:8:1

テスト失敗時のログ一部 ``` github.com/traPtitech/Jomon coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/comment coverage: 0.0% of statements github.com/traPtitech/Jomon/ent coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/groupbudget coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/enttest coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/file coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/group coverage: 0.0% of statements ? github.com/traPtitech/Jomon/ent/predicate [no test files] github.com/traPtitech/Jomon/ent/hook coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/migrate coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/request coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/requeststatus coverage: 0.0% of statements ? github.com/traPtitech/Jomon/ent/runtime [no test files] github.com/traPtitech/Jomon/ent/requesttarget coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/schema coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/tag coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/transaction coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/transactiondetail coverage: 0.0% of statements github.com/traPtitech/Jomon/ent/user coverage: 0.0% of statements github.com/traPtitech/Jomon/logging coverage: 0.0% of statements github.com/traPtitech/Jomon/model/mock_model coverage: 0.0% of statements github.com/traPtitech/Jomon/storage coverage: 0.0% of statements github.com/traPtitech/Jomon/service coverage: 0.0% of statements github.com/traPtitech/Jomon/storage/mock_storage coverage: 0.0% of statements github.com/traPtitech/Jomon/testutil coverage: 0.0% of statements github.com/traPtitech/Jomon/testutil/random coverage: 0.0% of statements ================== WARNING: DATA RACE Write at 0x000001bb2040 by goroutine 1945: entgo.io/ent/dialect/sql/schema.(*Atlas).setupTables() /home/runner/go/pkg/mod/entgo.io/ent@v0.[13](https://github.com/traPtitech/Jomon/actions/runs/9711575171/job/26804587744#step:8:14).1/dialect/sql/schema/atlas.go:1060 +0x5be entgo.io/ent/dialect/sql/schema.(*Atlas).Create() /home/runner/go/pkg/mod/entgo.io/ent@v0.13.1/dialect/sql/schema/atlas.go:107 +0x7b github.com/traPtitech/Jomon/ent/migrate.Create() /home/runner/work/Jomon/Jomon/ent/migrate/migrate.go:54 +0x1e8 github.com/traPtitech/Jomon/ent/migrate.(*Schema).Create() /home/runner/work/Jomon/Jomon/ent/migrate/migrate.go:45 +0xe5 github.com/traPtitech/Jomon/model.SetupTestEntClient() /home/runner/work/Jomon/Jomon/model/model_test.go:41 +0xa71 github.com/traPtitech/Jomon/model.TestEntRepository_GetTransactions() /home/runner/work/Jomon/Jomon/model/transaction_impl_test.go:17 +0x65 testing.tRunner() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:1689 +0x21e testing.(*T).Run.gowrap1() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:1742 +0x44 Previous write at 0x000001bb21c0 by goroutine 1945: entgo.io/ent/dialect/sql/schema.(*Atlas).setupTables() /home/runner/go/pkg/mod/entgo.io/ent@v0.13.1/dialect/sql/schema/atlas.go:1060 +0x5be entgo.io/ent/dialect/sql/schema.(*Atlas).Create() /home/runner/go/pkg/mod/entgo.io/ent@v0.13.1/dialect/sql/schema/atlas.go:107 +0x7b github.com/traPtitech/Jomon/ent/migrate.Create() /home/runner/work/Jomon/Jomon/ent/migrate/migrate.go:54 +0x1e8 github.com/traPtitech/Jomon/ent/migrate.(*Schema).Create() /home/runner/work/Jomon/Jomon/ent/migrate/migrate.go:45 +0xe5 github.com/traPtitech/Jomon/model.SetupTestEntClient() /home/runner/work/Jomon/Jomon/model/model_test.go:41 +0xa71 github.com/traPtitech/Jomon/model.setup() /home/runner/work/Jomon/Jomon/model/repository_test.go:18 +0x79 github.com/traPtitech/Jomon/model.TestEntRepository_UpdateTransaction() /home/runner/work/Jomon/Jomon/model/transaction_impl_test.go:635 +0x52 testing.tRunner() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:1689 +0x21e testing.(*T).Run.gowrap1() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:1742 +0x44 Goroutine 1942 (running) created at: testing.(*T).Run() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:1742 +0x825 testing.runTests.func1() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:2161 +0x85 testing.tRunner() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:1689 +0x21e testing.runTests() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:2[15](https://github.com/traPtitech/Jomon/actions/runs/9711575171/job/26804587744#step:8:16)9 +0x8be testing.(*M).Run() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:2027 +0xf17 main.main() _testmain.go:[16](https://github.com/traPtitech/Jomon/actions/runs/9711575171/job/26804587744#step:8:17)7 +0x2e4 Goroutine 1945 (running) created at: testing.(*T).Run() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:[17](https://github.com/traPtitech/Jomon/actions/runs/9711575171/job/26804587744#step:8:18)42 +0x825 testing.runTests.func1() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:2161 +0x85 testing.tRunner() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:1689 +0x21e testing.runTests() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:2159 +0x8be testing.(*M).Run() /opt/hostedtoolcache/go/1.22.3/x64/src/testing/testing.go:[20](https://github.com/traPtitech/Jomon/actions/runs/9711575171/job/26804587744#step:8:21)27 +0xf17 main.main() _testmain.go:167 +0x2e4 ================== --- FAIL: TestEntRepository_GetTransaction (0.31s) ... --- FAIL: TestEntRepository_CreateTransaction (0.26s) ... --- FAIL: TestEntRepository_UpdateTransaction (0.30s) ... --- FAIL: TestEntRepository_GetTransactions (2.28s) ... FAIL coverage: 25.9% of statements FAIL github.com/traPtitech/Jomon/model 14.889s ok github.com/traPtitech/Jomon/router 1.313s coverage: 6.6% of statements FAIL ```
H1rono commented 3 days ago

https://github.com/traPtitech/Jomon/blob/372aea3831a2bb268e387fed3a1a3346aea85d4f/model/transaction_impl_test.go#L17

https://github.com/traPtitech/Jomon/blob/372aea3831a2bb268e387fed3a1a3346aea85d4f/model/repository_test.go#L16-L18

https://github.com/traPtitech/Jomon/blob/372aea3831a2bb268e387fed3a1a3346aea85d4f/model/model_test.go#L15-L43

https://github.com/traPtitech/Jomon/blob/372aea3831a2bb268e387fed3a1a3346aea85d4f/ent/migrate/migrate.go#L44-L46

https://github.com/traPtitech/Jomon/blob/372aea3831a2bb268e387fed3a1a3346aea85d4f/ent/migrate/migrate.go#L49-L55

最後のmigrate.Createmigrate.Tablesへの書き込みが発生している

H1rono commented 3 days ago

端的に言うと、setupが排他的に呼ばれる必要がある