Skip to content

Commit

Permalink
[Xharness] Clean test task code. (#14857)
Browse files Browse the repository at this point in the history
We are going to be changing code in xharness. Is a good time to clean
things a little, make code more modern then enable nullability.

Try to get as much help from the new features and try to clean alittle
debt we have from the last time we moved code.
  • Loading branch information
mandel-macaque authored Apr 30, 2022
1 parent f2d9d31 commit 7a69d08
Showing 1 changed file with 47 additions and 69 deletions.
116 changes: 47 additions & 69 deletions tests/xharness/Jenkins/TestTasks/TestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,27 @@
namespace Xharness.Jenkins.TestTasks {
public abstract class TestTasks : IEnvManager, IEventLogger, ITestTask {
static int counter;
static DriveInfo RootDrive;
static DriveInfo rootDrive;

protected readonly Stopwatch waitingDuration = new();

#region Private vars

ILog testLog;
bool? supportsParallelExecution;
string testName;
Task executeTask;

#endregion

#region Public vars

public Dictionary<string, string> Environment = new Dictionary<string, string> ();
public Dictionary<string, string> Environment = new ();
public Func<Task> Dependency; // a task that's feteched and awaited before this task's ExecuteAsync method
public Task InitialTask { get; set; } // a task that's executed before this task's ExecuteAsync method.
public Task CompletedTask; // a task that's executed after this task's ExecuteAsync method.
public List<Resource> Resources = new List<Resource> ();

public List<Resource> Resources = new ();
#endregion

#region Properties
Expand All @@ -37,7 +48,7 @@ public abstract class TestTasks : IEnvManager, IEventLogger, ITestTask {

protected static string Timestamp => Harness.Helpers.Timestamp;
public string ProjectFile => TestProject?.Path;
public bool HasCustomTestName => test_name != null;
public bool HasCustomTestName => testName != null;

public bool NotStarted => (ExecutionResult & TestExecutingResult.StateMask) == TestExecutingResult.NotStarted;
public bool InProgress => (ExecutionResult & TestExecutingResult.InProgress) == TestExecutingResult.InProgress;
Expand Down Expand Up @@ -66,38 +77,23 @@ public bool Ignored {
public bool BuildFailure => (ExecutionResult & TestExecutingResult.BuildFailure) == TestExecutingResult.BuildFailure;
public bool HarnessException => (ExecutionResult & TestExecutingResult.HarnessException) == TestExecutingResult.HarnessException;

public Stopwatch DurationStopWatch { get; } = new Stopwatch ();
public TimeSpan Duration {
get {
return DurationStopWatch.Elapsed;
}
}
public Stopwatch DurationStopWatch { get; } = new ();
public TimeSpan Duration => DurationStopWatch.Elapsed;

string failure_message;
string failureMessage;
public string FailureMessage {
get { return failure_message; }
get { return failureMessage; }
set {
failure_message = value;
MainLog.WriteLine (failure_message);
failureMessage = value;
MainLog.WriteLine (failureMessage);
}
}


ILog test_log;
public ILog MainLog {
get {
if (test_log == null)
test_log = Logs.Create ($"main-{Timestamp}.log", "Main log");
return test_log;
}
}
public ILog MainLog
=> testLog ??= Logs.Create ($"main-{Timestamp}.log", "Main log");

ILogs logs;
public ILogs Logs {
get {
return logs ?? (logs = new Logs (LogDirectory));
}
}
public ILogs Logs => logs ??= new Logs (LogDirectory);

IEnumerable<string> referencedNunitAndXunitTestAssemblies;
public IEnumerable<string> ReferencedNunitAndXunitTestAssemblies {
Expand All @@ -114,7 +110,7 @@ public IEnumerable<string> ReferencedNunitAndXunitTestAssemblies {
csproj.LoadWithoutNetworkAccess (ProjectFile.Replace ("\\", "/"));
referencedNunitAndXunitTestAssemblies = csproj.GetNunitAndXunitTestReferences ();
} catch (Exception e) {
referencedNunitAndXunitTestAssemblies = new string [] { $"Exception: {e.Message}", $"Filename: {ProjectFile}" };
referencedNunitAndXunitTestAssemblies = new [] { $"Exception: {e.Message}", $"Filename: {ProjectFile}" };
}
} else {
referencedNunitAndXunitTestAssemblies = Enumerable.Empty<string> ();
Expand Down Expand Up @@ -146,26 +142,23 @@ public IEnumerable<string> ReferencedNunitAndXunitTestAssemblies {
public virtual string Mode { get; set; }
public virtual string Variation { get; set; }


bool? supports_parallel_execution;
public virtual bool SupportsParallelExecution {
get => supports_parallel_execution ?? true;
set => supports_parallel_execution = value;
get => supportsParallelExecution ?? true;
set => supportsParallelExecution = value;
}

public virtual IEnumerable<ILog> AggregatedLogs => Logs;

TestExecutingResult execution_result;
TestExecutingResult executionResult;
public virtual TestExecutingResult ExecutionResult {
get => execution_result;
set => execution_result = value;
get => executionResult;
set => executionResult = value;
}

string test_name;
public virtual string TestName {
get {
if (test_name != null)
return test_name;
if (testName != null)
return testName;

var rv = Path.GetFileNameWithoutExtension (ProjectFile);
if (rv == null)
Expand Down Expand Up @@ -193,7 +186,7 @@ public virtual string TestName {
}
}
set {
test_name = value;
testName = value;
}
}

Expand All @@ -203,15 +196,14 @@ protected virtual void PropagateResults () { }

public virtual void Reset ()
{
test_log = null;
failure_message = null;
testLog = null;
failureMessage = null;
logs = null;
DurationStopWatch.Reset ();
execution_result = TestExecutingResult.NotStarted;
execute_task = null;
executionResult = TestExecutingResult.NotStarted;
executeTask = null;
}


#endregion

public TestTasks ()
Expand All @@ -221,22 +213,18 @@ public TestTasks ()

// VerifyRun is called in RunInternalAsync/ExecuteAsync to verify that the task can be executed/run.
// Typically used to fail tasks that don't have an available device, or if there's not enough disk space.
public virtual Task VerifyRunAsync ()
{
return VerifyDiskSpaceAsync ();
}
public virtual Task VerifyRunAsync () => VerifyDiskSpaceAsync ();

protected Task VerifyDiskSpaceAsync ()
{
if (Finished)
return Task.CompletedTask;

if (RootDrive == null)
RootDrive = new DriveInfo ("/");
var afs = RootDrive.AvailableFreeSpace;
rootDrive ??= new("/");
var afs = rootDrive.AvailableFreeSpace;
const long minSpaceRequirement = 1024 * 1024 * 1024; /* 1 GB */
if (afs < minSpaceRequirement) {
FailureMessage = $"Not enough space on the root drive '{RootDrive.Name}': {afs / (1024.0 * 1024):#.##} MB left of {minSpaceRequirement / (1024.0 * 1024):#.##} MB required";
FailureMessage = $"Not enough space on the root drive '{rootDrive.Name}': {afs / (1024.0 * 1024):#.##} MB left of {minSpaceRequirement / (1024.0 * 1024):#.##} MB required";
ExecutionResult = TestExecutingResult.Failed;
}
return Task.CompletedTask;
Expand All @@ -255,10 +243,8 @@ public void CloneTestProject (ILog log, IProcessManager processManager, TestProj
InitialTask = TestProject.CreateCopyAsync (log, processManager, this, rootDirectory);
}

protected Stopwatch waitingDuration = new Stopwatch ();
public TimeSpan WaitingDuration => waitingDuration.Elapsed;

Task execute_task;
async Task RunInternalAsync ()
{
if (Finished)
Expand All @@ -279,8 +265,8 @@ async Task RunInternalAsync ()

DurationStopWatch.Start ();

execute_task = ExecuteAsync ();
await execute_task;
executeTask = ExecuteAsync ();
await executeTask;

if (CompletedTask != null) {
if (CompletedTask.Status == TaskStatus.Created)
Expand All @@ -307,18 +293,10 @@ async Task RunInternalAsync ()
}

public Task RunAsync ()
{
if (execute_task == null)
execute_task = RunInternalAsync ();
return execute_task;
}

=> executeTask ??= RunInternalAsync ();

public override string ToString ()
{
return ExecutionResult.ToString ();
}

=> ExecutionResult.ToString ();

protected void AddCILogFiles (StreamReader stream)
{
Expand Down Expand Up @@ -381,7 +359,7 @@ public async Task<IAcquiredResource> NotifyBlockingWaitAsync (Task<IAcquiredReso
return rv;
}

class BlockingWait : IAcquiredResource, IDisposable {
class BlockingWait : IAcquiredResource {
public IAcquiredResource Wrapped;
public Action OnDispose;

Expand Down

11 comments on commit 7a69d08

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 [CI Build] API Diff 📋

API Current PR diff

✅ API Diff (from PR only) (no change)

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

API diff

✅ API Diff from stable

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

Generator diff

Generator Diff (no change)

Pipeline on Agent XAMMINI-054.Monterey
Hash: 7a69d08cf05baf0e9763fc73201c509291876321

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) passed 💻

All tests on macOS M1 - Mac Big Sur (11.5) passed.

Pipeline on Agent
Hash: 7a69d08cf05baf0e9763fc73201c509291876321

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💻 [CI Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: 7a69d08cf05baf0e9763fc73201c509291876321

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📚 [CI Build] Artifacts 📚

Artifacts were not provided.

Pipeline on Agent XAMMINI-052.Monterey
Hash: 7a69d08cf05baf0e9763fc73201c509291876321

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ [CI Build] Tests passed on VSTS: simulator tests iOS. ✅

Tests passed on VSTS: simulator tests iOS.

🎉 All 234 tests passed 🎉

Pipeline on Agent XAMBOT-1108.Monterey'
[Xharness] Clean test task code. (#14857)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Tests failed catastrophically on VSTS: device tests iOS32b (no summary found). 🔥

Result file D:\a\1\s\Reports\TestSummary-iOS32b\TestSummary.md not found.

Pipeline on Agent
[Xharness] Clean test task code. (#14857)

We are going to be changing code in xharness. Is a good time to clean
things a little, make code more modern then enable nullability.

Try to get as much help from the new features and try to clean alittle
debt we have from the last time we moved code.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 [CI Build] API Diff 📋

API Current PR diff

✅ API Diff (from PR only) (no change)

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

API diff

✅ API Diff from stable

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

Generator diff

Generator Diff (no change)

Pipeline on Agent XAMMINI-053.Monterey'
Hash: 7a69d08cf05baf0e9763fc73201c509291876321

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests on macOS Mac Catalina (10.15) failed ❌

Failed tests are:

  • linksdk
  • linkall

Pipeline on Agent
Hash: 7a69d08cf05baf0e9763fc73201c509291876321

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌

Failed tests are:

  • linksdk

Pipeline on Agent
Hash: 7a69d08cf05baf0e9763fc73201c509291876321

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌

Tests failed on VSTS: simulator tests iOS.

Test results

9 tests failed, 96 tests passed.

Failed tests

  • link sdk/Mac [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 117 Passed: 107 Inconclusive: 0 Failed: 1 Ignored: 9)
  • link sdk/Mac [dotnet]/Release [dotnet]: Failed (Test run failed.
    Tests run: 117 Passed: 106 Inconclusive: 0 Failed: 1 Ignored: 10)
  • link sdk/Mac Catalyst [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 129 Passed: 119 Inconclusive: 0 Failed: 1 Ignored: 9)
  • link sdk/Mac Catalyst [dotnet]/Release [dotnet]: Failed (Test run failed.
    Tests run: 129 Passed: 117 Inconclusive: 0 Failed: 2 Ignored: 10)
  • link sdk/iOS Unified 64-bits - simulator/Debug: Failed
  • trimmode link/Mac [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 117 Passed: 106 Inconclusive: 0 Failed: 2 Ignored: 9)
  • trimmode link/Mac [dotnet]/Release [dotnet]: Failed (Test run failed.
    Tests run: 117 Passed: 106 Inconclusive: 0 Failed: 1 Ignored: 10)
  • trimmode link/Mac Catalyst [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 129 Passed: 119 Inconclusive: 0 Failed: 1 Ignored: 9)
  • trimmode link/Mac Catalyst [dotnet]/Release [dotnet]: Failed (Test run failed.
    Tests run: 129 Passed: 118 Inconclusive: 0 Failed: 1 Ignored: 10)

Pipeline on Agent XAMBOT-1108.Monterey
[Xharness] Clean test task code. (#14857)

We are going to be changing code in xharness. Is a good time to clean
things a little, make code more modern then enable nullability.

Try to get as much help from the new features and try to clean alittle
debt we have from the last time we moved code.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📚 [CI Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMMINI-061.Monterey'
Hash: 7a69d08cf05baf0e9763fc73201c509291876321

Please sign in to comment.