Merge branch 'master' into plugin-refactor
# Conflicts: # DistTestCore/CodexStarter.cs # DistTestCore/GethStarter.cs # ProjectPlugins/CodexPlugin/CodexContainerRecipe.cs # ProjectPlugins/CodexPlugin/CodexSetup.cs # ProjectPlugins/CodexPlugin/CodexStartupConfig.cs
This commit is contained in:
commit
01b2ff2181
|
@ -10,6 +10,8 @@
|
|||
|
||||
public long SizeInBytes { get; }
|
||||
|
||||
public const double DefaultSecondsPerMB = 10.0;
|
||||
|
||||
public long ToMB()
|
||||
{
|
||||
return SizeInBytes / (1024 * 1024);
|
||||
|
@ -36,6 +38,12 @@
|
|||
{
|
||||
return Formatter.FormatByteSize(SizeInBytes);
|
||||
}
|
||||
|
||||
public TimeSpan ToTimeSpan(double secsPerMB = DefaultSecondsPerMB)
|
||||
{
|
||||
var filesizeInMb = SizeInBytes / (1024 * 1024);
|
||||
return TimeSpan.FromSeconds(filesizeInMb * secsPerMB);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ByteSizeIntExtensions
|
||||
|
@ -91,5 +99,6 @@
|
|||
{
|
||||
return Convert.ToInt64(i).TB();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ namespace CodexPlugin
|
|||
private readonly MarketplaceStarter marketplaceStarter = new MarketplaceStarter();
|
||||
|
||||
private const string DefaultDockerImage = "codexstorage/nim-codex:latest-dist-tests";
|
||||
|
||||
public const string MetricsPortTag = "metrics_port";
|
||||
public const string DiscoveryPortTag = "discovery-port";
|
||||
|
||||
|
@ -18,7 +17,7 @@ namespace CodexPlugin
|
|||
|
||||
public override string AppName => "codex";
|
||||
public override string Image { get; }
|
||||
|
||||
|
||||
public CodexContainerRecipe()
|
||||
{
|
||||
Image = GetDockerImage();
|
||||
|
@ -26,8 +25,8 @@ namespace CodexPlugin
|
|||
|
||||
protected override void Initialize(StartupConfig startupConfig)
|
||||
{
|
||||
//SetResourcesRequest(milliCPUs: 1000, memory: 6.GB());
|
||||
//SetResourceLimits(milliCPUs: 4000, memory: 12.GB());
|
||||
SetResourcesRequest(milliCPUs: 100, memory: 100.MB());
|
||||
SetResourceLimits(milliCPUs: 4000, memory: 12.GB());
|
||||
|
||||
var config = startupConfig.Get<CodexStartupConfig>();
|
||||
|
||||
|
@ -39,7 +38,7 @@ namespace CodexPlugin
|
|||
AddVolume($"codex/{dataDir}", GetVolumeCapacity(config));
|
||||
|
||||
AddInternalPortAndVar("CODEX_DISC_PORT", DiscoveryPortTag);
|
||||
AddEnvVar("CODEX_LOG_LEVEL", config.LogLevel.ToString()!.ToUpperInvariant());
|
||||
AddEnvVar("CODEX_LOG_LEVEL", config.LogLevelWithTopics());
|
||||
|
||||
// This makes the node announce itself to its local (pod) IP address.
|
||||
AddEnvVar("NAT_IP_AUTO", "true");
|
||||
|
@ -77,6 +76,11 @@ namespace CodexPlugin
|
|||
AddPodAnnotation("prometheus.io/port", metricsPort.Number.ToString());
|
||||
}
|
||||
|
||||
if (config.SimulateProofFailures != null)
|
||||
{
|
||||
AddEnvVar("CODEX_SIMULATE_PROOF_FAILURES", config.SimulateProofFailures.ToString()!);
|
||||
}
|
||||
|
||||
if (config.MarketplaceConfig != null)
|
||||
{
|
||||
var mconfig = config.MarketplaceConfig;
|
||||
|
@ -97,10 +101,15 @@ namespace CodexPlugin
|
|||
|
||||
if (config.MarketplaceConfig.IsValidator)
|
||||
{
|
||||
AddEnvVar("CODEX_VALIDATOR", "true");
|
||||
AddEnvVar("CODEX_VALIDATOR", "true");
|
||||
}
|
||||
}
|
||||
|
||||
if(!string.IsNullOrEmpty(config.NameOverride))
|
||||
{
|
||||
AddEnvVar("CODEX_NODENAME", config.NameOverride);
|
||||
}
|
||||
|
||||
AddPodLabel("codexid", Image);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,18 +7,27 @@ namespace CodexPlugin
|
|||
{
|
||||
public interface ICodexSetup
|
||||
{
|
||||
ICodexSetup WithLogLevel(CodexLogLevel logLevel);
|
||||
ICodexSetup WithName(string name);
|
||||
ICodexSetup At(Location location);
|
||||
ICodexSetup WithBootstrapNode(ICodexNode node);
|
||||
ICodexSetup WithLogLevel(CodexLogLevel level);
|
||||
/// <summary>
|
||||
/// Sets the log level for codex. The default level is INFO and the
|
||||
/// log level is applied only to the supplied topics.
|
||||
/// </summary>
|
||||
ICodexSetup WithLogLevel(CodexLogLevel level, params string[] topics);
|
||||
ICodexSetup WithStorageQuota(ByteSize storageQuota);
|
||||
ICodexSetup WithBlockTTL(TimeSpan duration);
|
||||
ICodexSetup WithBlockMaintenanceInterval(TimeSpan duration);
|
||||
ICodexSetup WithBlockMaintenanceNumber(int numberOfBlocks);
|
||||
ICodexSetup EnableMetrics();
|
||||
ICodexSetup EnableMarketplace(IGethNode gethNode, ICodexContracts codexContracts, Ether initialEth, TestToken initialTokens, bool isValidator = false);
|
||||
/// <summary>
|
||||
/// Provides an invalid proof every N proofs
|
||||
/// </summary>
|
||||
ICodexSetup WithSimulateProofFailures(uint failEveryNProofs);
|
||||
}
|
||||
|
||||
|
||||
public class CodexSetup : CodexStartupConfig, ICodexSetup
|
||||
{
|
||||
public int NumberOfNodes { get; }
|
||||
|
@ -28,12 +37,6 @@ namespace CodexPlugin
|
|||
NumberOfNodes = numberOfNodes;
|
||||
}
|
||||
|
||||
public ICodexSetup WithLogLevel(CodexLogLevel logLevel)
|
||||
{
|
||||
LogLevel = logLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ICodexSetup WithName(string name)
|
||||
{
|
||||
NameOverride = name;
|
||||
|
@ -52,6 +55,19 @@ namespace CodexPlugin
|
|||
return this;
|
||||
}
|
||||
|
||||
public ICodexSetup WithLogLevel(CodexLogLevel level)
|
||||
{
|
||||
LogLevel = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ICodexSetup WithLogLevel(CodexLogLevel level, params string[] topics)
|
||||
{
|
||||
LogLevel = level;
|
||||
LogTopics = topics;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ICodexSetup WithStorageQuota(ByteSize storageQuota)
|
||||
{
|
||||
StorageQuota = storageQuota;
|
||||
|
@ -88,6 +104,12 @@ namespace CodexPlugin
|
|||
return this;
|
||||
}
|
||||
|
||||
public ICodexSetup WithSimulateProofFailures(uint failEveryNProofs)
|
||||
{
|
||||
SimulateProofFailures = failEveryNProofs;
|
||||
return this;
|
||||
}
|
||||
|
||||
public string Describe()
|
||||
{
|
||||
var args = string.Join(',', DescribeArgs());
|
||||
|
@ -96,9 +118,11 @@ namespace CodexPlugin
|
|||
|
||||
private IEnumerable<string> DescribeArgs()
|
||||
{
|
||||
yield return $"LogLevel={LogLevel}";
|
||||
yield return $"LogLevel={LogLevelWithTopics()}";
|
||||
if (BootstrapSpr != null) yield return $"BootstrapNode={BootstrapSpr}";
|
||||
if (StorageQuota != null) yield return $"StorageQuote={StorageQuota}";
|
||||
if (StorageQuota != null) yield return $"StorageQuota={StorageQuota}";
|
||||
if (SimulateProofFailures != null) yield return $"SimulateProofFailures={SimulateProofFailures}";
|
||||
if (MarketplaceConfig != null) yield return $"IsValidator={MarketplaceConfig.IsValidator}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,25 @@ namespace CodexPlugin
|
|||
public string? NameOverride { get; set; }
|
||||
public Location Location { get; set; }
|
||||
public CodexLogLevel LogLevel { get; set; }
|
||||
public string[]? LogTopics { get; set; }
|
||||
public ByteSize? StorageQuota { get; set; }
|
||||
public bool MetricsEnabled { get; set; }
|
||||
public MarketplaceInitialConfig? MarketplaceConfig { get; set; }
|
||||
public string? BootstrapSpr { get; set; }
|
||||
public int? BlockTTL { get; set; }
|
||||
public uint? SimulateProofFailures { get; set; }
|
||||
public bool? EnableValidator { get; set; }
|
||||
public TimeSpan? BlockMaintenanceInterval { get; set; }
|
||||
public int? BlockMaintenanceNumber { get; set; }
|
||||
|
||||
public string LogLevelWithTopics()
|
||||
{
|
||||
var level = LogLevel.ToString()!.ToUpperInvariant();
|
||||
if (LogTopics != null && LogTopics.Count() > 0)
|
||||
{
|
||||
level = $"INFO;{level}: {string.Join(",", LogTopics.Where(s => !string.IsNullOrEmpty(s)))}";
|
||||
}
|
||||
return level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,6 +151,18 @@ namespace CodexPlugin
|
|||
WaitForStorageContractState(timeout, "finished");
|
||||
}
|
||||
|
||||
public void WaitForStorageContractFinished(ByteSize contractFileSize)
|
||||
{
|
||||
if (!contractStartUtc.HasValue)
|
||||
{
|
||||
WaitForStorageContractStarted(contractFileSize.ToTimeSpan());
|
||||
}
|
||||
var gracePeriod = TimeSpan.FromSeconds(10);
|
||||
var currentContractTime = DateTime.UtcNow - contractStartUtc!.Value;
|
||||
var timeout = (ContractDuration - currentContractTime) + gracePeriod;
|
||||
WaitForStorageContractState(timeout, "finished");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for contract to start. Max timeout depends on contract filesize. Allows more time for larger files.
|
||||
/// </summary>
|
||||
|
|
|
@ -5,10 +5,6 @@
|
|||
<RootNamespace>DistTestCore</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsArm64 Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">true</IsArm64>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsArm64)'=='true'">
|
||||
<DefineConstants>Arm64</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -10,8 +10,11 @@ namespace DistTestCore.Helpers
|
|||
{
|
||||
try
|
||||
{
|
||||
var c = constraint.Resolve();
|
||||
Time.WaitUntil(() => c.ApplyTo(actual()).IsSuccess);
|
||||
|
||||
Time.WaitUntil(() => {
|
||||
var c = constraint.Resolve();
|
||||
return c.ApplyTo(actual()).IsSuccess;
|
||||
});
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue