Add `WaitForStorageContractFinished` for marketplace tests
This commit is contained in:
parent
ef2c18c599
commit
f2ad9e1198
|
@ -187,6 +187,18 @@ namespace DistTestCore.Marketplace
|
|||
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>
|
||||
|
@ -208,7 +220,7 @@ namespace DistTestCore.Marketplace
|
|||
{
|
||||
var lastState = "";
|
||||
var waitStart = DateTime.UtcNow;
|
||||
|
||||
|
||||
log.Log($"Waiting for {Time.FormatDuration(timeout)} for contract '{PurchaseId}' to reach state '{desiredState}'.");
|
||||
while (lastState != desiredState)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue