2023-06-21 07:27:59 +00:00
|
|
|
|
using DistTestCore;
|
|
|
|
|
using DistTestCore.Codex;
|
2023-08-24 07:33:46 +00:00
|
|
|
|
using DistTestCore.Logs;
|
|
|
|
|
using KubernetesWorkflow;
|
2023-06-21 07:27:59 +00:00
|
|
|
|
using Logging;
|
|
|
|
|
|
|
|
|
|
namespace ContinuousTests
|
|
|
|
|
{
|
|
|
|
|
public abstract class ContinuousTestLongTimeouts : ContinuousTest
|
|
|
|
|
{
|
|
|
|
|
public override ITimeSet TimeSet => new LongTimeSet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class ContinuousTest
|
|
|
|
|
{
|
2023-06-23 09:38:30 +00:00
|
|
|
|
protected const int Zero = 0;
|
2023-06-25 08:50:01 +00:00
|
|
|
|
protected const int MinuteOne = 60;
|
|
|
|
|
protected const int MinuteFive = MinuteOne * 5;
|
|
|
|
|
protected const int HourOne = MinuteOne * 60;
|
2023-06-26 13:37:16 +00:00
|
|
|
|
protected const int HourThree = HourOne * 3;
|
2023-06-23 09:38:30 +00:00
|
|
|
|
protected const int DayOne = HourOne * 24;
|
|
|
|
|
protected const int DayThree = DayOne * 3;
|
|
|
|
|
|
2023-06-21 07:27:59 +00:00
|
|
|
|
private const string UploadFailedMessage = "Unable to store block";
|
|
|
|
|
|
2023-06-29 14:07:49 +00:00
|
|
|
|
public void Initialize(CodexAccess[] nodes, BaseLog log, FileManager fileManager, Configuration configuration, CancellationToken cancelToken)
|
2023-06-21 07:27:59 +00:00
|
|
|
|
{
|
|
|
|
|
Nodes = nodes;
|
|
|
|
|
Log = log;
|
|
|
|
|
FileManager = fileManager;
|
2023-06-26 13:37:16 +00:00
|
|
|
|
Configuration = configuration;
|
2023-06-28 14:19:37 +00:00
|
|
|
|
CancelToken = cancelToken;
|
2023-06-28 09:48:05 +00:00
|
|
|
|
|
|
|
|
|
if (nodes != null)
|
|
|
|
|
{
|
2023-06-28 10:01:20 +00:00
|
|
|
|
NodeRunner = new NodeRunner(Nodes, configuration, TimeSet, Log, CustomK8sNamespace, EthereumAccountIndex);
|
2023-06-28 09:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NodeRunner = null!;
|
|
|
|
|
}
|
2023-06-21 07:27:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-29 14:07:49 +00:00
|
|
|
|
public CodexAccess[] Nodes { get; private set; } = null!;
|
2023-06-21 07:27:59 +00:00
|
|
|
|
public BaseLog Log { get; private set; } = null!;
|
|
|
|
|
public IFileManager FileManager { get; private set; } = null!;
|
2023-06-26 13:37:16 +00:00
|
|
|
|
public Configuration Configuration { get; private set; } = null!;
|
2023-06-21 07:27:59 +00:00
|
|
|
|
public virtual ITimeSet TimeSet { get { return new DefaultTimeSet(); } }
|
2023-06-29 08:23:04 +00:00
|
|
|
|
public CancellationToken CancelToken { get; private set; } = new CancellationToken();
|
2023-06-28 09:48:05 +00:00
|
|
|
|
public NodeRunner NodeRunner { get; private set; } = null!;
|
2023-06-21 07:27:59 +00:00
|
|
|
|
|
|
|
|
|
public abstract int RequiredNumberOfNodes { get; }
|
2023-06-25 07:53:10 +00:00
|
|
|
|
public abstract TimeSpan RunTestEvery { get; }
|
|
|
|
|
public abstract TestFailMode TestFailMode { get; }
|
2023-06-28 09:01:10 +00:00
|
|
|
|
public virtual int EthereumAccountIndex { get { return -1; } }
|
|
|
|
|
public virtual string CustomK8sNamespace { get { return string.Empty; } }
|
2023-06-21 07:27:59 +00:00
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return GetType().Name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-29 14:07:49 +00:00
|
|
|
|
public ContentId? UploadFile(CodexAccess node, TestFile file)
|
2023-06-21 07:27:59 +00:00
|
|
|
|
{
|
|
|
|
|
using var fileStream = File.OpenRead(file.Filename);
|
|
|
|
|
|
|
|
|
|
var logMessage = $"Uploading file {file.Describe()}...";
|
|
|
|
|
var response = Stopwatch.Measure(Log, logMessage, () =>
|
|
|
|
|
{
|
|
|
|
|
return node.UploadFile(fileStream);
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-11 06:19:14 +00:00
|
|
|
|
if (string.IsNullOrEmpty(response)) return null;
|
|
|
|
|
if (response.StartsWith(UploadFailedMessage)) return null;
|
|
|
|
|
|
2023-06-21 07:27:59 +00:00
|
|
|
|
Log.Log($"Uploaded file. Received contentId: '{response}'.");
|
|
|
|
|
return new ContentId(response);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-29 14:07:49 +00:00
|
|
|
|
public TestFile DownloadFile(CodexAccess node, ContentId contentId, string fileLabel = "")
|
2023-06-21 07:27:59 +00:00
|
|
|
|
{
|
|
|
|
|
var logMessage = $"Downloading for contentId: '{contentId.Id}'...";
|
|
|
|
|
var file = FileManager.CreateEmptyTestFile(fileLabel);
|
|
|
|
|
Stopwatch.Measure(Log, logMessage, () => DownloadToFile(node, contentId.Id, file));
|
|
|
|
|
Log.Log($"Downloaded file {file.Describe()} to '{file.Filename}'.");
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-24 07:33:46 +00:00
|
|
|
|
public IDownloadedLog DownloadContainerLog(RunningContainer container, int? tailLines = null)
|
|
|
|
|
{
|
|
|
|
|
var nodeRunner = new NodeRunner(Nodes, Configuration, TimeSet, Log, Configuration.CodexDeployment.Metadata.KubeNamespace, EthereumAccountIndex);
|
|
|
|
|
return nodeRunner.DownloadLog(container, tailLines);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-29 14:07:49 +00:00
|
|
|
|
private void DownloadToFile(CodexAccess node, string contentId, TestFile file)
|
2023-06-21 07:27:59 +00:00
|
|
|
|
{
|
|
|
|
|
using var fileStream = File.OpenWrite(file.Filename);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using var downloadStream = node.DownloadFile(contentId);
|
|
|
|
|
downloadStream.CopyTo(fileStream);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
Log.Log($"Failed to download file '{contentId}'.");
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-06-25 07:53:10 +00:00
|
|
|
|
|
|
|
|
|
public enum TestFailMode
|
|
|
|
|
{
|
|
|
|
|
StopAfterFirstFailure,
|
|
|
|
|
AlwaysRunAllMoments
|
|
|
|
|
}
|
2023-06-21 07:27:59 +00:00
|
|
|
|
}
|