Skip to content

Commit f8005f8

Browse files
committed
resolve issues with goroutine
1 parent 1921179 commit f8005f8

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

internal/api/lib_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -845,22 +845,33 @@ func Benchmark100ConcurrentContractCalls(b *testing.B) {
845845
b.ResetTimer()
846846
for n := 0; n < b.N; n++ {
847847
var wg sync.WaitGroup
848+
errChan := make(chan error, callCount)
849+
resChan := make(chan []byte, callCount)
848850
wg.Add(callCount)
851+
testMutex.Lock()
852+
info = MockInfoBin(b, "fred")
853+
testMutex.Unlock()
849854
for i := 0; i < callCount; i++ {
850855
go func() {
856+
defer wg.Done()
851857
gasMeter2 := NewMockGasMeter(TESTING_GAS_LIMIT)
852858
igasMeter2 := types.GasMeter(gasMeter2)
853859
store.SetGasMeter(gasMeter2)
854-
info = MockInfoBin(b, "fred")
855860
msg := []byte(`{"allocate_large_memory":{"pages":0}}`) // replace with noop once we have it
856861
res, _, err = Execute(cache, checksum, env, info, msg, &igasMeter2, store, api, &querier, TESTING_GAS_LIMIT, TESTING_PRINT_DEBUG)
857-
require.NoError(b, err)
858-
requireOkResponse(b, res, 0)
859-
860-
wg.Done()
862+
errChan <- err
863+
resChan <- res
861864
}()
862865
}
863866
wg.Wait()
867+
close(errChan)
868+
close(resChan)
869+
870+
// Now check results in the main test goroutine
871+
for i := 0; i < callCount; i++ {
872+
require.NoError(b, <-errChan)
873+
requireOkResponse(b, <-resChan, 0)
874+
}
864875
}
865876
}
866877

@@ -1312,10 +1323,6 @@ func TestCustomReflectQuerier(t *testing.T) {
13121323
// https://github.com/CosmWasm/cosmwasm/blob/v0.11.0-alpha3/contracts/reflect/src/msg.rs#L18-L28
13131324
}
13141325

1315-
type CapitalizedResponse struct {
1316-
Text string `json:"text"`
1317-
}
1318-
13191326
cache, cleanup := withCache(t)
13201327
defer cleanup()
13211328
checksum := createReflectContract(t, cache)
@@ -1354,6 +1361,10 @@ func TestCustomReflectQuerier(t *testing.T) {
13541361
require.Equal(t, "SMALL FRYS :)", response.Text)
13551362
}
13561363

1364+
type CapitalizedResponse struct {
1365+
Text string `json:"text"`
1366+
}
1367+
13571368
// TestFloats is a port of the float_instrs_are_deterministic test in cosmwasm-vm
13581369
func TestFloats(t *testing.T) {
13591370
type Value struct {

0 commit comments

Comments
 (0)