Skip to content

Commit

Permalink
Moving test timeout management to UITestExecutionSession
Browse files Browse the repository at this point in the history
  • Loading branch information
Piedone committed Jan 3, 2025
1 parent 3ca6fc6 commit 6a0fac4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
27 changes: 26 additions & 1 deletion Lombiq.Tests.UI/Services/UITestExecutionSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.Json.Nodes;
Expand Down Expand Up @@ -104,7 +105,31 @@ public async Task<bool> ExecuteAsync(int retryCount, string dumpRootPath)

if (_context.IsBrowserConfigured) _context.SetDefaultBrowserSize();

await _testManifest.TestAsync(_context);
var timeout = _configuration.TimeoutConfiguration.TestRunTimeout;

var timeoutTask = Task.Delay(timeout, _configuration.TestCancellationToken);
Debug.WriteLine("Timeout task created: " + timeoutTask.GetHashCode());
var testTask = _testManifest.TestAsync(_context);

await Task.WhenAny(testTask, timeoutTask);

if (timeoutTask.IsCompleted)
{
// If the EnterInteractiveModeAsync() extension method has been used, then timeout should be ignored to
// make the debugging experience smoother. Note that EnterInteractiveModeAsync() should never be used in
// committed tests.
if (!ShortcutsUITestContextExtensions.InteractiveModeHasBeenUsed)
{
throw new TimeoutException($"The time allotted for the test ({timeout}) was exceeded.");
}

await testTask;
}

// Since the timeout task is not yet completed but the Task.WhenAny has finished, the test task is done in
// some way. So it's safe to await it here. It's also necessary to cleanly propagate any exceptions that may
// have been thrown inside it.
await testTask;

await _context.AssertLogsAsync();

Expand Down
25 changes: 1 addition & 24 deletions Lombiq.Tests.UI/UITestBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Models;
using Lombiq.Tests.UI.Services;
using Lombiq.Tests.UI.Services.GitHub;
Expand All @@ -22,7 +21,6 @@ protected async Task ExecuteOrchardCoreTestAsync(
OrchardCoreUITestExecutorConfiguration configuration)
{
var originalTestOutputHelper = _testOutputHelper;
var timeout = configuration.TimeoutConfiguration.TestRunTimeout;

Action afterTest = null;
if (configuration.ExtendGitHubActionsOutput &&
Expand All @@ -39,31 +37,10 @@ protected async Task ExecuteOrchardCoreTestAsync(

try
{
var testTask = UITestExecutor.ExecuteOrchardCoreTestAsync(
await UITestExecutor.ExecuteOrchardCoreTestAsync(
webApplicationInstanceFactory,
testManifest,
configuration);
var timeoutTask = Task.Delay(timeout, configuration.TestCancellationToken);

await Task.WhenAny(testTask, timeoutTask);

if (timeoutTask.IsCompleted)
{
// If the EnterInteractiveModeAsync() extension method has been used, then timeout should be ignored to
// make the debugging experience smoother. Note that EnterInteractiveModeAsync() should never be used in
// committed tests.
if (!ShortcutsUITestContextExtensions.InteractiveModeHasBeenUsed)
{
throw new TimeoutException($"The time allotted for the test ({timeout}) was exceeded.");
}

await testTask;
}

// Since the timeout task is not yet completed but the Task.WhenAny has finished, the test task is done in
// some way. So it's safe to await it here. It's also necessary to cleanly propagate any exceptions that may
// have been thrown inside it.
await testTask;
}
finally
{
Expand Down

0 comments on commit 6a0fac4

Please sign in to comment.