Skip to content

Commit

Permalink
fix: fix race conditions from #14332
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Dec 23, 2022
1 parent 2a93ce9 commit 6c2bc3f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
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))

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])
}
}

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

return genesisData
Expand Down

0 comments on commit 6c2bc3f

Please sign in to comment.