-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add a test which checks for proper finish of Bodies/Receipts on mutliple tries #28
Open
kamilchodola
wants to merge
20
commits into
main
Choose a base branch
from
kch/addReceiptsandBodiesCheck
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7bbf58b
Fix pruning test
kamilchodola 324da6e
Bodies and receipts verify
kamilchodola 1af1d1d
Fix path
kamilchodola 314600f
logs
kamilchodola cf3279a
More logs
kamilchodola 340e95c
Fix path
kamilchodola b5304ee
Fix build issue
kamilchodola 1ab7beb
Add node ready condition
kamilchodola 8e67e62
Add restore
kamilchodola b553b42
Add restore
kamilchodola e10798a
Add compose recreate
kamilchodola edfe813
Fix params order
kamilchodola e9f5645
cp flag change
kamilchodola 6a1e268
Fix moment of fetching data dir
kamilchodola bdba900
Wait for proper stage before proceeding
kamilchodola b1041d1
Fix policy
kamilchodola 931dbed
Change to constant waiting startegy
kamilchodola 499eccb
Change verification
kamilchodola b623024
Add recreate force to cleanup logs in container
kamilchodola 43e4fe3
Add removal of DB
kamilchodola 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 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 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 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,55 @@ | ||
using YamlDotNet.Serialization; | ||
using YamlDotNet.Serialization.NamingConventions; | ||
|
||
namespace NethermindNode.Core.Helpers | ||
{ | ||
public static class DockerComposeHelper | ||
{ | ||
public static Dictionary<string, object> ReadDockerCompose(string filePath) | ||
{ | ||
var deserializer = new DeserializerBuilder() | ||
.WithNamingConvention(UnderscoredNamingConvention.Instance) | ||
.Build(); | ||
|
||
using var reader = new StreamReader(filePath); | ||
var yaml = reader.ReadToEnd(); | ||
var result = deserializer.Deserialize<Dictionary<string, object>>(yaml); | ||
|
||
return result; | ||
} | ||
|
||
public static void WriteDockerCompose(Dictionary<string, object> compose, string filePath) | ||
{ | ||
var serializer = new SerializerBuilder() | ||
.WithNamingConvention(UnderscoredNamingConvention.Instance) | ||
.Build(); | ||
|
||
var yaml = serializer.Serialize(compose); | ||
using var writer = new StreamWriter(filePath); | ||
Console.WriteLine("Writing at path: " + filePath); | ||
writer.Write(yaml); | ||
} | ||
|
||
public static void RemoveCommandFlag(Dictionary<string, object> dockerCompose, string serviceName, string flagToRemove) | ||
{ | ||
var services = (Dictionary<object, object>)dockerCompose["services"]; | ||
if (services.ContainsKey(serviceName)) | ||
{ | ||
var service = (Dictionary<object, object>)services[serviceName]; | ||
var command = (List<object>)service["command"]; | ||
command.Remove(flagToRemove); | ||
} | ||
} | ||
|
||
public static void AddCommandFlag(Dictionary<string, object> dockerCompose, string serviceName, string flagToAdd) | ||
{ | ||
var services = (Dictionary<object, object>)dockerCompose["services"]; | ||
if (services.ContainsKey(serviceName)) | ||
{ | ||
var service = (Dictionary<object, object>)services[serviceName]; | ||
var command = (List<object>)service["command"]; | ||
command.Add(flagToAdd); | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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 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
108 changes: 108 additions & 0 deletions
108
NethermindNode.Tests/Tests/SyncingNode/BodiesAndReceiptsFinalization.cs
This file contains 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,108 @@ | ||
using NethermindNode.Core.Helpers; | ||
using Polly; | ||
using Polly.Contrib.WaitAndRetry; | ||
|
||
namespace NethermindNode.Tests.SyncingNode | ||
{ | ||
[TestFixture] | ||
public class BodiesAndReceiptsTests : BaseTest | ||
{ | ||
|
||
private static readonly NLog.Logger Logger = NLog.LogManager.GetLogger(TestContext.CurrentContext.Test.Name); | ||
|
||
[TestCase(10)] | ||
[Category("BodiesAndReceipts")] | ||
[Description( | ||
""" | ||
!!!!! Test to be used when NonValidator mode is true. !!!!! | ||
|
||
1. Wait for node to be synced (eth_syncing returns false) | ||
2. Stop a execution node | ||
3. Create a backup of database | ||
4. Restart node but without NonValidator node flags | ||
5. Wait until end of sync (eth_syncing returns false) | ||
6. Check if logs "Fast blocks bodies task completed." and "Fast blocks receipts task completed." are there - those two should always been present meaning that tasks are properly finished. | ||
7. Stop a node, restore backup, redo steps 5 and 6 | ||
|
||
WHY? | ||
If there is no such logs, there is high chance we "lost" something and we should investigate what is missing | ||
""" | ||
)] | ||
public void ShouldResyncBodiesAndReceiptsAfterNonValidator(int repeatCount) | ||
{ | ||
Logger.Info("***Starting test: ShouldResyncBodiesAndReceiptsAfterNonValidator***"); | ||
|
||
// 1 | ||
NodeInfo.WaitForNodeToBeReady(Logger); | ||
|
||
var delay = Backoff.ConstantBackoff(TimeSpan.FromSeconds(3), retryCount: 100); | ||
|
||
var retryPolicy = Policy | ||
.HandleResult<string>(s => !s.Contains("SnapSync") && !s.Contains("StateNodes")) | ||
.WaitAndRetry(delay); | ||
|
||
string result = retryPolicy.Execute(() => NodeInfo.GetCurrentStage(Logger)); | ||
|
||
NodeInfo.WaitForNodeToBeSynced(Logger); | ||
|
||
// 2 | ||
DockerCommands.StopDockerContainer(ConfigurationHelper.Instance["execution-container-name"], Logger); | ||
|
||
// 3 | ||
var execPath = DockerCommands.GetExecutionDataPath(Logger); | ||
CommandExecutor.BackupDirectory(execPath + "/nethermind_db", execPath + "/nethermind_db_backup" , Logger); | ||
|
||
// 4 | ||
string[] flagsToRemove = | ||
{ | ||
"--Sync.NonValidatorNode=true", | ||
"--Sync.DownloadBodiesInFastSync=false", | ||
"--Sync.DownloadReceiptsInFastSync=false" | ||
}; | ||
|
||
Logger.Info("Reading docker compose file at path: " + execPath + "/../docker-compose.yml"); | ||
var dockerCompose = DockerComposeHelper.ReadDockerCompose(execPath + "/../docker-compose.yml"); | ||
foreach (var flag in flagsToRemove) | ||
{ | ||
Console.WriteLine("Removing: " + flag); | ||
DockerComposeHelper.RemoveCommandFlag(dockerCompose, "execution", flag); | ||
} | ||
DockerComposeHelper.WriteDockerCompose(dockerCompose, execPath + "/../docker-compose.yml"); | ||
DockerCommands.RecreateDockerCompose("execution", execPath + "/../docker-compose.yml", Logger); | ||
DockerCommands.StartDockerContainer(ConfigurationHelper.Instance["execution-container-name"], Logger); | ||
|
||
// 5-6-7 | ||
for (int i = 0; i < repeatCount; i++) | ||
{ | ||
NodeInfo.WaitForNodeToBeReady(Logger); | ||
NodeInfo.WaitForNodeToBeSynced(Logger); | ||
var bodiesLine = DockerCommands.GetDockerLogs(ConfigurationHelper.Instance["execution-container-name"], "Fast blocks bodies task completed."); | ||
var receiptsLine = DockerCommands.GetDockerLogs(ConfigurationHelper.Instance["execution-container-name"], "Fast blocks receipts task completed."); | ||
|
||
Assert.IsTrue(bodiesLine.Count() > 0, "Bodies log line missing - verify with getBlockByNumber."); | ||
Assert.IsTrue(receiptsLine.Count() > 0, "Receipts log line missing - verify with getReceipt"); | ||
|
||
DockerCommands.StopDockerContainer(ConfigurationHelper.Instance["execution-container-name"], Logger); | ||
|
||
CommandExecutor.RemoveDirectory(execPath + "/nethermind_db", Logger); | ||
CommandExecutor.BackupDirectory(execPath + "/nethermind_db_backup", execPath + "/nethermind_db", Logger); | ||
|
||
// For logs cleanup purpose only | ||
DockerCommands.RecreateDockerCompose("execution", execPath + "/../docker-compose.yml", Logger); | ||
|
||
DockerCommands.StartDockerContainer(ConfigurationHelper.Instance["execution-container-name"], Logger); | ||
} | ||
|
||
// Restore to previous state | ||
foreach (var flag in flagsToRemove) | ||
{ | ||
Console.WriteLine("Adding: " + flag); | ||
DockerComposeHelper.AddCommandFlag(dockerCompose, "execution", flag); | ||
} | ||
DockerComposeHelper.WriteDockerCompose(dockerCompose, execPath + "/../docker-compose.yml"); | ||
DockerCommands.RecreateDockerCompose("execution", execPath + "/../docker-compose.yml", Logger); | ||
DockerCommands.StopDockerContainer(ConfigurationHelper.Instance["execution-container-name"], Logger); | ||
DockerCommands.StartDockerContainer(ConfigurationHelper.Instance["execution-container-name"], Logger); | ||
} | ||
} | ||
} |
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.
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.
Probably
BackupDirectory
is not the best name. MaybeCopyDirectory
will work better?