Skip to content

Commit

Permalink
IGNITE-24162 .NET: Fix ComputeTests on Windows (#5033)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptupitsyn authored Jan 13, 2025
1 parent f0ef09f commit 86fd823
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public async Task TestDelayedJobExecutionThrowsWhenConnectionFails()
public async Task TestJobExecutionStatusExecuting()
{
const int sleepMs = 3000;
var beforeStart = SystemClock.Instance.GetCurrentInstant();
var beforeStart = GetCurrentInstant();

var jobExecution = await Client.Compute.SubmitAsync(await GetNodeAsync(1), SleepJob, sleepMs);

Expand All @@ -610,7 +610,7 @@ public async Task TestJobExecutionStatusExecuting()
public async Task TestJobExecutionStatusCompleted()
{
const int sleepMs = 1;
var beforeStart = SystemClock.Instance.GetCurrentInstant();
var beforeStart = GetCurrentInstant();

var jobExecution = await Client.Compute.SubmitAsync(await GetNodeAsync(1), SleepJob, sleepMs);
await jobExecution.GetResultAsync();
Expand All @@ -621,7 +621,7 @@ public async Task TestJobExecutionStatusCompleted()
[Test]
public async Task TestJobExecutionStatusFailed()
{
var beforeStart = SystemClock.Instance.GetCurrentInstant();
var beforeStart = GetCurrentInstant();

var jobExecution = await Client.Compute.SubmitAsync(await GetNodeAsync(1), ErrorJob, "unused");
Assert.CatchAsync(async () => await jobExecution.GetResultAsync());
Expand All @@ -644,7 +644,7 @@ public async Task TestJobExecutionStatusNull()
public async Task TestJobExecutionCancel()
{
const int sleepMs = 5000;
var beforeStart = SystemClock.Instance.GetCurrentInstant();
var beforeStart = GetCurrentInstant();

var jobExecution = await Client.Compute.SubmitAsync(await GetNodeAsync(1), SleepJob, sleepMs);
await jobExecution.CancelAsync();
Expand Down Expand Up @@ -722,7 +722,7 @@ public async Task TestBigDecimalPropagation(string number, int scale)
[Test]
public async Task TestMapReduceNodeNameTask()
{
Instant beforeStart = SystemClock.Instance.GetCurrentInstant();
Instant beforeStart = GetCurrentInstant();

ITaskExecution<string> taskExec = await Client.Compute.SubmitMapReduceAsync(NodeNameTask, "+arg");

Expand All @@ -747,9 +747,9 @@ public async Task TestMapReduceNodeNameTask()
Assert.IsNotNull(state);
Assert.AreEqual(TaskStatus.Completed, state.Status);
Assert.AreEqual(taskExec.Id, state.Id);
Assert.That(state.CreateTime, Is.GreaterThan(beforeStart));
Assert.That(state.StartTime, Is.GreaterThan(state.CreateTime));
Assert.That(state.FinishTime, Is.GreaterThan(state.StartTime));
Assert.That(state.CreateTime, Is.GreaterThanOrEqualTo(beforeStart));
Assert.That(state.StartTime, Is.GreaterThanOrEqualTo(state.CreateTime));
Assert.That(state.FinishTime, Is.GreaterThanOrEqualTo(state.StartTime));

// Job states.
IList<JobState?> jobStates = await taskExec.GetJobStatesAsync();
Expand Down Expand Up @@ -894,19 +894,29 @@ private static async Task AssertJobStatus<T>(IJobExecution<T> jobExecution, JobS
Assert.IsNotNull(state);
Assert.AreEqual(jobExecution.Id, state!.Id);
Assert.AreEqual(status, state.Status);
Assert.Greater(state.CreateTime, beforeStart);
Assert.Greater(state.StartTime, state.CreateTime);
Assert.That(state.CreateTime, Is.GreaterThanOrEqualTo(beforeStart));
Assert.That(state.StartTime, Is.GreaterThanOrEqualTo(state.CreateTime));

if (status is JobStatus.Canceled or JobStatus.Completed or JobStatus.Failed)
{
Assert.Greater(state.FinishTime, state.StartTime);
Assert.That(state.FinishTime, Is.GreaterThanOrEqualTo(state.StartTime));
}
else
{
Assert.IsNull(state.FinishTime);
}
}

private static Instant GetCurrentInstant()
{
var instant = SystemClock.Instance.GetCurrentInstant();

// Subtract 1 milli to account for OS-specific time resolution differences in .NET and Java.
return OperatingSystem.IsWindows()
? instant.Minus(Duration.FromMilliseconds(1))
: instant;
}

private async Task<IJobTarget<IClusterNode>> GetNodeAsync(int index) =>
JobTarget.Node(
(await Client.GetClusterNodesAsync()).OrderBy(n => n.Name).Skip(index).First());
Expand Down

0 comments on commit 86fd823

Please sign in to comment.