From 6995cbfb23fb63d971484ff065b5d7344a32ad37 Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 9 May 2024 09:38:04 +0200 Subject: [PATCH] hacky way to download container logs while retries are failing. --- Framework/Utils/Time.cs | 7 +++++++ Tests/CodexLongTests/BasicTests/LargeFileTests.cs | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Framework/Utils/Time.cs b/Framework/Utils/Time.cs index f1a109d..85cfb1a 100644 --- a/Framework/Utils/Time.cs +++ b/Framework/Utils/Time.cs @@ -144,6 +144,12 @@ namespace Utils return $"Attempt {index} took {FormatDuration(info.Item2)} and failed with exception {info.Item1}."; } + private static Action failedCallback = i => { }; + public static void SetRetryFailedCallback(Action onRetryFailed) + { + failedCallback = onRetryFailed; + } + public static T Retry(Func action, TimeSpan maxTimeout, TimeSpan retryTime, string description) { var start = DateTime.UtcNow; @@ -165,6 +171,7 @@ namespace Utils catch (Exception ex) { exceptions.Add(ex); + failedCallback(tries); tries++; } diff --git a/Tests/CodexLongTests/BasicTests/LargeFileTests.cs b/Tests/CodexLongTests/BasicTests/LargeFileTests.cs index 0470e35..d182ed8 100644 --- a/Tests/CodexLongTests/BasicTests/LargeFileTests.cs +++ b/Tests/CodexLongTests/BasicTests/LargeFileTests.cs @@ -50,6 +50,8 @@ namespace CodexLongTests.BasicTests var node = StartCodex(s => s.WithStorageQuota((size + 10).MB())); + Time.SetRetryFailedCallback(i => OnFailed(i, node)); + var uploadStart = DateTime.UtcNow; var cid = node.UploadFile(expectedFile); var downloadStart = DateTime.UtcNow; @@ -60,6 +62,17 @@ namespace CodexLongTests.BasicTests AssertTimeConstraint(uploadStart, downloadStart, downloadFinished, size); } + private void OnFailed(int tries, ICodexNode node) + { + if (tries < 5) return; + + if (tries % 10 == 0) + { + Log($"After try {tries}, downloading node log."); + Ci.DownloadLog(node); + } + } + private void AssertTimeConstraint(DateTime uploadStart, DateTime downloadStart, DateTime downloadFinished, long size) { float sizeInMB = size;