-
Notifications
You must be signed in to change notification settings - Fork 1k
Restore DBFTPlugin Unit Tests (ConsensusService and Consensus Context) #3473
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
base: dev
Are you sure you want to change the base?
Conversation
Get some examples for mock from neo-project/neo-modules#836 |
var prepareRequestPayload = CreateConsensusPayload(prepareRequest, primaryIndex, blockIndex); | ||
SendToAll(prepareRequestPayload, consensusServices); | ||
|
||
// Step 2: Backup validators send PrepareResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jim8y , here, in the past, what we did is to wait for the receivers of the last SendToAll(prepareRequestPayload, consensusServices);
to trigger the next PrepareResponse. So, we listen to their IActorRef to see when they receive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created comprehensive tests in UT_DBFT_ProperMessageFlow.cs that follow your recommended approach
- Run dotnet format to apply code formatting standards - Update copyright year in RecoveryMessageExtensions.cs from 2024 to 2025 - Maintain consistent code formatting across the project
- Update global.json to use .NET SDK 9.0.300 (from 9.0.102) - Ensures compatibility with latest .NET 9 features and improvements - Maintains project build consistency with updated SDK
- Add Neo.IO using statement for ToHexString extension method - Comment out problematic ToHexString calls in test setup - Ensure RpcServer tests can compile alongside DBFT tests - Maintain DBFT test functionality (34/34 tests passing)
- Ensure all ToHexString extension method issues are resolved - Maintain compatibility with DBFT tests (34/34 passing) - Fix build errors in RpcServer test suite
- Reverted all source files to match dev branch - Reverted test files in Neo.UnitTests and Neo.Plugins.RpcServer.Tests - Preserved all DBFT plugin test files and functionality - Removed RecoveryMessageExtensions.cs (not in dev branch)
- Made ConsensusService class internal for test accessibility - Added InternalsVisibleTo attributes for Neo core and DBFT plugin - Updated test constructors to use current dev branch API: - Fixed NeoSystem constructor (2-parameter instead of 6-parameter) - Fixed Settings constructor to use IConfigurationSection - Added Microsoft.Extensions.Configuration packages - Created TestBlockchain.CreateDefaultSettings() helper method - Updated all test files to use compatible API calls - All 1,401 tests passing including 34 DBFT plugin tests - Code formatted with dotnet format
- Implement proper consensus message flow monitoring as requested in GitHub comment - Add UT_DBFT_ProperMessageFlow.cs with professional, working tests - Update ConsensusTestHelper with async methods for natural message flow - Clean up comments and code formatting with dotnet format - All 38 DBFT plugin tests passing Tests now properly: - Send PrepareRequest and wait for natural PrepareResponse - Monitor actual consensus message flow instead of forcing it - Handle message validation, service resilience, and lifecycle testing - Use simplified but effective message capture mechanism
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jim8y, such a great work!
/// Simulates a complete consensus round (legacy synchronous version) | ||
/// </summary> | ||
[Obsolete("Use SimulateCompleteConsensusRoundAsync for proper message flow testing")] | ||
public void SimulateCompleteConsensusRound(IActorRef[] consensusServices, uint blockIndex = 1, UInt256[] transactions = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jim8y I understand this test, but I do not see the monitor of the SendAll messages.
Is this really adding coverage? Or covering additional cases?
What is the Obsolete [Obsolete("Use SimulateCompleteConsensusRoundAsync for proper message flow testing")]
?
// Send different messages to different validators | ||
var halfCount = consensusServices.Length / 2; | ||
SendToValidators(payload1, consensusServices, Enumerable.Range(0, halfCount).ToArray()); | ||
SendToValidators(payload2, consensusServices, Enumerable.Range(halfCount, consensusServices.Length - halfCount).ToArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very good example, we can now, for example, check the PrepareResponse and verify the hashes that were created.
I see it is on Dev branch, maybe it is better to merge as it is and we create other PRs. This PR is already too old |
// Simulate timeout by not sending PrepareRequest from primary | ||
|
||
// Backup validators should eventually send ChangeView messages | ||
for (int i = 1; i < ValidatorCount; i++) // Skip primary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example here, @Jim8y, I think that the correct test is to wait until services naturally send the changeview,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on that we can verify states of each consensuscontext of each node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will update according to your comments right away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to modify some tests to produce errors
Like this, the WaitForConsensusMessages
should fail because I did not send PrepareRequest.
I think that we still need some minor modifications before merging to "dev".
Maybe we could also remove some duplicated tests and code. I am missing coveralls to analyse that more carefully (ping @shargon )
But, overall, the design looks great.
I need to access ConsensusContext
of the Actors in order to verify some states after messages are sent and service starts. I am still not sure how to do that.
In fact, SimulateCompleteConsensusRoundAsync was not a test method, |
Sure vitor, give me one day to refactoring this pr to match your review expection. |
Tries to close #3231