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

fix: fix race conditions from #14332 #14402

Merged
merged 11 commits into from
Dec 26, 2022
11 changes: 4 additions & 7 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ test-integration:
test-integration-cov:
go test ./integration/... -timeout 30m -coverpkg=../... -coverprofile=integration-profile.out -covermode=atomic

test-e2e: test-e2e-server
go test ./e2e/... -mod=readonly -timeout 30m -tags='e2e'
test-e2e:
go test ./e2e/... -mod=readonly -timeout 30m -race -tags='e2e'

test-e2e-cov: test-e2e-server
go test ./e2e/... -mod=readonly -timeout 30m -race -tags='e2e' -coverpkg=../... -coverprofile=e2e-profile.out -covermode=atomic

test-e2e-server:
go test ./e2e/server -mod=readonly -timeout 30m -tags='e2e' -coverpkg=../... -coverprofile=e2e-server-profile.out -covermode=atomic
test-e2e-cov:
go test ./e2e/... -mod=readonly -timeout 30m -race -tags='e2e' -coverpkg=../... -coverprofile=e2e-profile.out -covermode=atomic
4 changes: 2 additions & 2 deletions tests/e2e/server/export_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !race
// +build !race
//go:build e2e
// +build e2e

package server_test

Expand Down
13 changes: 7 additions & 6 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,22 +395,23 @@ func (m *Manager) ExportGenesisForModules(ctx sdk.Context, cdc codec.JSONCodec,
panic(err)
}

channels := make([]chan json.RawMessage, len(modulesToExport))
channels := make(map[string]chan json.RawMessage)
modulesWithGenesis := make([]string, 0, len(modulesToExport))
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

for i, moduleName := range modulesToExport {
for _, moduleName := range modulesToExport {
if module, ok := m.Modules[moduleName].(HasGenesis); ok {
channels[i] = make(chan json.RawMessage)
channels[moduleName] = make(chan json.RawMessage)
modulesWithGenesis = append(modulesWithGenesis, moduleName)

go func(module HasGenesis, ch chan json.RawMessage) {
ctx := ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) // avoid race conditions
ch <- module.ExportGenesis(ctx, cdc)
}(module, channels[i])
}(module, channels[moduleName])
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
}
}

for i, moduleName := range modulesWithGenesis {
genesisData[moduleName] = <-channels[i]
for _, moduleName := range modulesWithGenesis {
genesisData[moduleName] = <-channels[moduleName]
}

return genesisData
Expand Down