-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor instance tests around a network harness #508
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
Open
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8a2ea4c
Move TestParseBlockSizeMatchesBytes into external_test.go
samliok 86c4be9
Delete the instance tests
samliok 5372de5
Delete the test helpers the rewrite does not use
samliok ea08f41
Rename instance_test.go to instance_helpers_test.go
samliok f8e9a03
Update the shared instance test helpers
samliok 8fcc089
Add the network harness helpers
samliok e25483a
Add the instance tests
samliok b1c88c8
Update the remaining callers of the instance test helpers
samliok f2d5683
merge conflicts
samliok c06829f
comments
samliok 672f3db
consistent time
samliok 9c4e363
speedup test, and ensure block notification is not dropped with offli…
samliok 289da30
add validator set interpolation
samliok 808edee
use var group
samliok b00b420
wait until validators are running
samliok 1d6f03d
lint
samliok 9240656
review comments
samliok 4d6dd6f
added check
samliok 42e5881
queue instead of spawn go-routine
samliok 1f3d9a9
remove mock storage
samliok 854e215
start all instance tests from zero block
samliok 81af48c
lint
samliok 6418585
oops, missed a test
samliok 48563fc
remove start method, only keep sync
samliok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package simplex | ||
|
|
||
| import ( | ||
| "sync" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/ava-labs/simplex/common" | ||
| metadata "github.com/ava-labs/simplex/msm" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestParseBlockSizeMatchesBytes(t *testing.T) { | ||
| // Case 1: Bytes() first, Size() second, size returns the cached length. | ||
| pb := &ParsedBlock{ | ||
| StateMachineBlock: metadata.StateMachineBlock{ | ||
| Metadata: metadata.StateMachineMetadata{ | ||
| SimplexProtocolMetadata: common.ProtocolMetadata{ | ||
| Version: 1, | ||
| Prev: common.Digest{}, | ||
| Round: 1, | ||
| Epoch: 4, | ||
| Seq: 2, | ||
| }, | ||
| SimplexBlacklist: common.Blacklist{ | ||
| Updates: common.BlacklistUpdates{{NodeIndex: 1, Type: 1}}, | ||
| NodeCount: 2, | ||
| }, | ||
| PChainHeight: 6, | ||
| }, | ||
| InnerBlock: &testInnerBlock{ | ||
| Height_: 7, | ||
| TS: time.UnixMilli(8), | ||
| Payload: []byte("payload"), | ||
| }, | ||
| }, | ||
| } | ||
| bytes := pb.Bytes() | ||
| require.Equal(t, len(bytes), pb.Size()) | ||
|
|
||
| // Case 2: Size() first on a non serialized block. it will | ||
| // compute the size and match a later Byte() call. | ||
| pb2 := &ParsedBlock{ | ||
| StateMachineBlock: metadata.StateMachineBlock{ | ||
| Metadata: metadata.StateMachineMetadata{ | ||
| SimplexProtocolMetadata: common.ProtocolMetadata{ | ||
| Version: 1, | ||
| Prev: common.Digest{}, | ||
| Round: 1, | ||
| Epoch: 4, | ||
| Seq: 2, | ||
| }, | ||
| SimplexBlacklist: common.Blacklist{ | ||
| Updates: common.BlacklistUpdates{{NodeIndex: 1, Type: 1}}, | ||
| NodeCount: 2, | ||
| }, | ||
| PChainHeight: 6, | ||
| }, | ||
| InnerBlock: &testInnerBlock{ | ||
| Height_: 9, | ||
| TS: time.UnixMilli(10), | ||
| Payload: []byte("other payload"), | ||
| }, | ||
| }, | ||
| } | ||
| size := pb2.Size() | ||
| require.NotZero(t, size) | ||
| bytes2 := pb2.Bytes() | ||
| require.Equal(t, len(bytes2), size) | ||
|
|
||
| // case 3: concurrent Size() calls on a block that was never serialized. | ||
| // the goroutines rase to compute the size, the lock must make this | ||
| // safe and every call must return the correct value | ||
|
|
||
| pb3 := &ParsedBlock{ | ||
| StateMachineBlock: metadata.StateMachineBlock{ | ||
| Metadata: metadata.StateMachineMetadata{ | ||
| SimplexProtocolMetadata: common.ProtocolMetadata{ | ||
| Version: 1, | ||
| Prev: common.Digest{}, | ||
| Round: 1, | ||
| Epoch: 4, | ||
| Seq: 2, | ||
| }, | ||
| SimplexBlacklist: common.Blacklist{ | ||
| Updates: common.BlacklistUpdates{{NodeIndex: 1, Type: 1}}, | ||
| NodeCount: 2, | ||
| }, | ||
| PChainHeight: 6, | ||
| }, | ||
| InnerBlock: &testInnerBlock{ | ||
| Height_: 11, | ||
| TS: time.UnixMilli(12), | ||
| Payload: []byte("concurrent"), | ||
| }, | ||
| }, | ||
| } | ||
| var wg sync.WaitGroup | ||
| sizes := make([]int, 4) | ||
| for i := range sizes { | ||
| wg.Add(1) | ||
| go func() { | ||
| defer wg.Done() | ||
| sizes[i] = pb3.Size() | ||
| }() | ||
| } | ||
| wg.Wait() | ||
| bytes3 := pb3.Bytes() | ||
| for _, size := range sizes { | ||
| require.Equal(t, len(bytes3), size) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.