Skip to content

Commit 8b0d6b2

Browse files
authored
Merge pull request #8027 from onflow/bastian/parallelize-fvm-tests
Parallelize tests in FVM and execution
2 parents a745d4e + ae03439 commit 8b0d6b2

File tree

10 files changed

+80
-0
lines changed

10 files changed

+80
-0
lines changed

engine/execution/block_result_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ func makeBlockExecutionResultFixture(serviceEventsPerChunk []int) *BlockExecutio
2626

2727
// Tests that ServiceEventCountForChunk method works as expected under various circumstances:
2828
func TestBlockExecutionResult_ServiceEventCountForChunk(t *testing.T) {
29+
t.Parallel()
30+
2931
t.Run("no service events", func(t *testing.T) {
3032
nChunks := rand.Intn(10) + 1 // always contains at least system chunk
3133
blockResult := makeBlockExecutionResultFixture(make([]int, nChunks))

engine/execution/computation/execution_verification_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ var chain = flow.Emulator.Chain()
5656
// This is not relevant to the test, as only the non-system transactions are tested.
5757

5858
func Test_ExecutionMatchesVerification(t *testing.T) {
59+
60+
t.Parallel()
61+
5962
t.Run("empty block", func(t *testing.T) {
6063
executeBlockAndVerify(t,
6164
[][]*flow.TransactionBody{},
@@ -339,6 +342,7 @@ func Test_ExecutionMatchesVerification(t *testing.T) {
339342
}
340343

341344
func TestTransactionFeeDeduction(t *testing.T) {
345+
t.Parallel()
342346

343347
type testCase struct {
344348
name string

engine/execution/computation/manager_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ import (
5151
var scriptLogThreshold = 1 * time.Second
5252

5353
func TestComputeBlockWithStorage(t *testing.T) {
54+
t.Parallel()
55+
5456
chain := flow.Mainnet.Chain()
5557

5658
vm := fvm.NewVirtualMachine()
@@ -180,6 +182,7 @@ func TestComputeBlockWithStorage(t *testing.T) {
180182
}
181183

182184
func TestComputeBlock_Uploader(t *testing.T) {
185+
t.Parallel()
183186

184187
noopCollector := &metrics.NoopCollector{}
185188

@@ -230,6 +233,7 @@ func TestComputeBlock_Uploader(t *testing.T) {
230233
}
231234

232235
func TestExecuteScript(t *testing.T) {
236+
t.Parallel()
233237

234238
logger := zerolog.Nop()
235239

@@ -296,6 +300,7 @@ func TestExecuteScript(t *testing.T) {
296300
// Balance script used to swallow errors, which meant that even if the view was empty, a script that did nothing but get
297301
// the balance of an account would succeed and return 0.
298302
func TestExecuteScript_BalanceScriptFailsIfViewIsEmpty(t *testing.T) {
303+
t.Parallel()
299304

300305
logger := zerolog.Nop()
301306

@@ -361,6 +366,7 @@ func TestExecuteScript_BalanceScriptFailsIfViewIsEmpty(t *testing.T) {
361366
}
362367

363368
func TestExecuteScripPanicsAreHandled(t *testing.T) {
369+
t.Parallel()
364370

365371
ctx := fvm.NewContext()
366372

@@ -411,6 +417,7 @@ func TestExecuteScripPanicsAreHandled(t *testing.T) {
411417
}
412418

413419
func TestExecuteScript_LongScriptsAreLogged(t *testing.T) {
420+
t.Parallel()
414421

415422
ctx := fvm.NewContext()
416423

@@ -464,6 +471,7 @@ func TestExecuteScript_LongScriptsAreLogged(t *testing.T) {
464471
}
465472

466473
func TestExecuteScript_ShortScriptsAreNotLogged(t *testing.T) {
474+
t.Parallel()
467475

468476
ctx := fvm.NewContext()
469477

@@ -647,6 +655,7 @@ func (f *FakeBlockComputer) ExecuteBlock(
647655
}
648656

649657
func TestExecuteScriptTimeout(t *testing.T) {
658+
t.Parallel()
650659

651660
timeout := 1 * time.Millisecond
652661
manager, err := New(
@@ -694,6 +703,7 @@ func TestExecuteScriptTimeout(t *testing.T) {
694703
}
695704

696705
func TestExecuteScriptCancelled(t *testing.T) {
706+
t.Parallel()
697707

698708
timeout := 30 * time.Second
699709
manager, err := New(
@@ -750,6 +760,7 @@ func TestExecuteScriptCancelled(t *testing.T) {
750760
}
751761

752762
func Test_EventEncodingFailsOnlyTxAndCarriesOn(t *testing.T) {
763+
t.Parallel()
753764

754765
chain := flow.Mainnet.Chain()
755766
vm := fvm.NewVirtualMachine()
@@ -908,6 +919,7 @@ func (e *testingEventEncoder) Encode(event cadence.Event) ([]byte, error) {
908919
}
909920

910921
func TestScriptStorageMutationsDiscarded(t *testing.T) {
922+
t.Parallel()
911923

912924
timeout := 10 * time.Second
913925
chain := flow.Mainnet.Chain()

engine/execution/computation/programs_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const (
4040
)
4141

4242
func TestPrograms_TestContractUpdates(t *testing.T) {
43+
t.Parallel()
44+
4345
chain := flow.Mainnet.Chain()
4446
vm := fvm.NewVirtualMachine()
4547
execCtx := fvm.NewContext(fvm.WithChain(chain))
@@ -215,6 +217,8 @@ func (b blockProvider) ByHeightFrom(height uint64, _ *flow.Header) (*flow.Header
215217
// -> Block121 (emit event - version should be 2)
216218
// -> Block1211 (emit event - version should be 2)
217219
func TestPrograms_TestBlockForks(t *testing.T) {
220+
t.Parallel()
221+
218222
block := unittest.BlockFixture()
219223
chain := flow.Emulator.Chain()
220224
vm := fvm.NewVirtualMachine()

engine/execution/execution_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func sendBlock(exeNode *testmock.ExecutionNode, from flow.Identifier, proposal *
3838
// create another child block which will trigger the parent
3939
// block to be incorporated and be passed to the ingestion engine
4040
func TestExecutionFlow(t *testing.T) {
41+
t.Parallel()
42+
4143
hub := stub.NewNetworkHub()
4244

4345
chainID := flow.Testnet
@@ -383,6 +385,8 @@ func makeSuccessBlock(t *testing.T, conID *flow.Identity, colID *flow.Identity,
383385
// Test a successful tx should change the statecommitment,
384386
// but a failed Tx should not change the statecommitment.
385387
func TestFailedTxWillNotChangeStateCommitment(t *testing.T) {
388+
t.Parallel()
389+
386390
hub := stub.NewNetworkHub()
387391

388392
chainID := flow.Emulator
@@ -547,6 +551,8 @@ func mockCollectionEngineToReturnCollections(t *testing.T, collectionNode *testm
547551

548552
// Test the receipt will be sent to multiple verification nodes
549553
func TestBroadcastToMultipleVerificationNodes(t *testing.T) {
554+
t.Parallel()
555+
550556
hub := stub.NewNetworkHub()
551557

552558
chainID := flow.Emulator

fvm/accounts_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ func newAccountKey(
360360

361361
func TestCreateAccount(t *testing.T) {
362362

363+
t.Parallel()
364+
363365
options := []fvm.Option{
364366
fvm.WithAuthorizationChecksEnabled(false),
365367
fvm.WithSequenceNumberCheckAndIncrementEnabled(false),
@@ -469,6 +471,8 @@ func TestCreateAccount(t *testing.T) {
469471

470472
func TestCreateAccount_WithRestrictedAccountCreation(t *testing.T) {
471473

474+
t.Parallel()
475+
472476
options := []fvm.Option{
473477
fvm.WithAuthorizationChecksEnabled(false),
474478
fvm.WithSequenceNumberCheckAndIncrementEnabled(false),
@@ -614,6 +618,8 @@ func TestCreateAccount_WithRestrictedAccountCreation(t *testing.T) {
614618

615619
func TestAddAccountKey(t *testing.T) {
616620

621+
t.Parallel()
622+
617623
options := []fvm.Option{
618624
fvm.WithAuthorizationChecksEnabled(false),
619625
fvm.WithSequenceNumberCheckAndIncrementEnabled(false),
@@ -932,6 +938,8 @@ func TestAddAccountKey(t *testing.T) {
932938

933939
func TestRemoveAccountKey(t *testing.T) {
934940

941+
t.Parallel()
942+
935943
options := []fvm.Option{
936944
fvm.WithAuthorizationChecksEnabled(false),
937945
fvm.WithSequenceNumberCheckAndIncrementEnabled(false),
@@ -1211,6 +1219,8 @@ func TestRemoveAccountKey(t *testing.T) {
12111219

12121220
func TestGetAccountKey(t *testing.T) {
12131221

1222+
t.Parallel()
1223+
12141224
options := []fvm.Option{
12151225
fvm.WithAuthorizationChecksEnabled(false),
12161226
fvm.WithSequenceNumberCheckAndIncrementEnabled(false),
@@ -1483,6 +1493,9 @@ func byteSliceToCadenceArrayLiteral(bytes []byte) string {
14831493
}
14841494

14851495
func TestAccountBalanceFields(t *testing.T) {
1496+
1497+
t.Parallel()
1498+
14861499
t.Run("Get balance works",
14871500
newVMTest().withContextOptions(
14881501
fvm.WithAuthorizationChecksEnabled(false),
@@ -1725,6 +1738,9 @@ func TestAccountBalanceFields(t *testing.T) {
17251738
}
17261739

17271740
func TestGetStorageCapacity(t *testing.T) {
1741+
1742+
t.Parallel()
1743+
17281744
t.Run("Get storage capacity",
17291745
newVMTest().withContextOptions(
17301746
fvm.WithAuthorizationChecksEnabled(false),

fvm/environment/programs_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ func getTestContract(
147147
}
148148

149149
func Test_Programs(t *testing.T) {
150+
t.Parallel()
151+
150152
vm := fvm.NewVirtualMachine()
151153
derivedBlockData := derived.NewEmptyDerivedBlockData(0)
152154

fvm/fvm_blockcontext_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,8 @@ func TestBlockContext_GetAccount(t *testing.T) {
17511751
}
17521752

17531753
func TestBlockContext_Random(t *testing.T) {
1754+
t.Parallel()
1755+
17541756
chain, vm := createChainAndVm(flow.Mainnet)
17551757
header := &flow.Header{HeaderBody: flow.HeaderBody{Height: 42}}
17561758
source := testutil.EntropyProviderFixture(nil)
@@ -1906,6 +1908,8 @@ func TestBlockContext_ExecuteTransaction_CreateAccount_WithMonotonicAddresses(t
19061908
}
19071909

19081910
func TestBlockContext_ExecuteTransaction_FailingTransactions(t *testing.T) {
1911+
t.Parallel()
1912+
19091913
getBalance := func(
19101914
vm fvm.VM,
19111915
chain flow.Chain,

fvm/fvm_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ func TestWithServiceAccount(t *testing.T) {
474474
}
475475

476476
func TestEventLimits(t *testing.T) {
477+
t.Parallel()
478+
477479
chain, vm := createChainAndVm(flow.Mainnet)
478480

479481
ctx := fvm.NewContext(
@@ -579,6 +581,7 @@ func TestEventLimits(t *testing.T) {
579581
// TestHappyPathSigning checks that a signing a transaction with `Sign` doesn't produce an error.
580582
// Transaction verification tests are in `TestVerifySignatureFromTransaction`.
581583
func TestHappyPathTransactionSigning(t *testing.T) {
584+
t.Parallel()
582585

583586
newVMTest().run(
584587
func(t *testing.T, vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree) {
@@ -620,6 +623,8 @@ func TestHappyPathTransactionSigning(t *testing.T) {
620623
}
621624

622625
func TestTransactionFeeDeduction(t *testing.T) {
626+
t.Parallel()
627+
623628
getBalance := func(vm fvm.VM, chain flow.Chain, ctx fvm.Context, snapshotTree snapshot.SnapshotTree, address flow.Address) uint64 {
624629
sc := systemcontracts.SystemContractsForChain(chain.ChainID())
625630
code := []byte(fmt.Sprintf(
@@ -1098,6 +1103,7 @@ func TestTransactionFeeDeduction(t *testing.T) {
10981103
}
10991104

11001105
func TestSettingExecutionWeights(t *testing.T) {
1106+
t.Parallel()
11011107

11021108
// change the chain so that the metering settings are read from the service account
11031109
chain := flow.Emulator.Chain()
@@ -1837,6 +1843,8 @@ func TestEnforcingComputationLimit(t *testing.T) {
18371843
}
18381844

18391845
func TestStorageCapacity(t *testing.T) {
1846+
t.Parallel()
1847+
18401848
t.Run("Storage capacity updates on FLOW transfer", newVMTest().
18411849
withContextOptions(
18421850
fvm.WithAuthorizationChecksEnabled(false),
@@ -2328,6 +2336,9 @@ func TestScriptExecutionLimit(t *testing.T) {
23282336
}
23292337

23302338
func TestInteractionLimit(t *testing.T) {
2339+
2340+
t.Parallel()
2341+
23312342
type testCase struct {
23322343
name string
23332344
interactionLimit uint64
@@ -2497,6 +2508,7 @@ func TestInteractionLimit(t *testing.T) {
24972508
}
24982509

24992510
func TestAttachments(t *testing.T) {
2511+
t.Parallel()
25002512

25012513
newVMTest().
25022514
withBootstrapProcedureOptions().
@@ -2531,6 +2543,8 @@ func TestAttachments(t *testing.T) {
25312543
}
25322544

25332545
func TestCapabilityControllers(t *testing.T) {
2546+
t.Parallel()
2547+
25342548
test := func(t *testing.T) {
25352549
newVMTest().
25362550
withBootstrapProcedureOptions().
@@ -2800,6 +2814,8 @@ func TestStorageIterationWithBrokenValues(t *testing.T) {
28002814
}
28012815

28022816
func TestEntropyCallOnlyOkIfAllowed(t *testing.T) {
2817+
t.Parallel()
2818+
28032819
source := testutil.EntropyProviderFixture(nil)
28042820

28052821
test := func(t *testing.T, allowed bool) {
@@ -2859,6 +2875,8 @@ func TestEntropyCallOnlyOkIfAllowed(t *testing.T) {
28592875
}
28602876

28612877
func TestEntropyCallExpectsNoParameters(t *testing.T) {
2878+
t.Parallel()
2879+
28622880
source := testutil.EntropyProviderFixture(nil)
28632881
newVMTest().
28642882
withBootstrapProcedureOptions().
@@ -2902,6 +2920,7 @@ func TestEntropyCallExpectsNoParameters(t *testing.T) {
29022920
}
29032921

29042922
func TestTransientNetworkCoreContractAddresses(t *testing.T) {
2923+
t.Parallel()
29052924

29062925
// This test ensures that the transient networks have the correct core contract addresses.
29072926
newVMTest().
@@ -2927,6 +2946,8 @@ func TestTransientNetworkCoreContractAddresses(t *testing.T) {
29272946
}
29282947

29292948
func TestFlowCallbackScheduler(t *testing.T) {
2949+
t.Parallel()
2950+
29302951
ctxOpts := []fvm.Option{
29312952
fvm.WithScheduleCallbacksEnabled(true),
29322953
}
@@ -2975,6 +2996,8 @@ func TestFlowCallbackScheduler(t *testing.T) {
29752996
}
29762997

29772998
func TestEVM(t *testing.T) {
2999+
t.Parallel()
3000+
29783001
blocks := new(envMock.Blocks)
29793002
block1 := unittest.BlockFixture()
29803003
blocks.On("ByHeightFrom",
@@ -3244,6 +3267,8 @@ func TestEVM(t *testing.T) {
32443267
}
32453268

32463269
func TestVMBridge(t *testing.T) {
3270+
t.Parallel()
3271+
32473272
blocks := new(envMock.Blocks)
32483273
block1 := unittest.BlockFixture()
32493274
blocks.On("ByHeightFrom",
@@ -3812,6 +3837,7 @@ func TestVMBridge(t *testing.T) {
38123837
}
38133838

38143839
func TestAccountCapabilitiesGetEntitledRejection(t *testing.T) {
3840+
t.Parallel()
38153841

38163842
// Note: This cannot be tested anymore using a transaction,
38173843
// because publish method also aborts when trying to publish an entitled capability.
@@ -3874,6 +3900,7 @@ func TestAccountCapabilitiesGetEntitledRejection(t *testing.T) {
38743900
}
38753901

38763902
func TestAccountCapabilitiesPublishEntitledRejection(t *testing.T) {
3903+
t.Parallel()
38773904

38783905
t.Run("entitled capability", newVMTest().
38793906
run(func(
@@ -4131,6 +4158,7 @@ func TestCrypto(t *testing.T) {
41314158
}
41324159

41334160
func Test_BlockHashListShouldWriteOnPush(t *testing.T) {
4161+
t.Parallel()
41344162

41354163
chain := flow.Emulator.Chain()
41364164
sc := systemcontracts.SystemContractsForChain(chain.ChainID())

0 commit comments

Comments
 (0)