Skip to content

Commit e5a572b

Browse files
committed
Fix for when an async block throws
1 parent c0453ff commit e5a572b

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

IntelliTect.TestTools.TestFramework.Tests/TestCaseTests/TestFailureTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using IntelliTect.TestTools.TestFramework.Tests.TestData.Dependencies;
22
using IntelliTect.TestTools.TestFramework.Tests.TestData.TestBlocks;
3+
using Microsoft.Playwright;
34
using System;
45
using System.Threading.Tasks;
56
using Xunit;
@@ -41,5 +42,19 @@ public async Task DependencyWithMissingDependencyThrowsOriginalError()
4142
Assert.IsType<InvalidOperationException>(ex.InnerException);
4243
Assert.Contains("oops", ex.InnerException!.Message, StringComparison.InvariantCultureIgnoreCase);
4344
}
45+
46+
[Fact]
47+
public async Task CgiIssue()
48+
{
49+
TestCase tc = new TestBuilder()
50+
.AddAsyncTestBlock<PlaywrightError>()
51+
.Build();
52+
53+
var ex = await Assert.ThrowsAsync<TestCaseException>(() => tc.ExecuteAsync());
54+
Assert.False(tc.Passed);
55+
Assert.NotNull(ex.InnerException);
56+
Assert.IsType<InvalidOperationException>(ex.InnerException);
57+
Assert.Contains("oops", ex.InnerException!.Message, StringComparison.InvariantCultureIgnoreCase);
58+
}
4459
}
4560
}

IntelliTect.TestTools.TestFramework.Tests/TestData/TestBlocks/SingleDependencyBlocks.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using IntelliTect.TestTools.TestFramework.Tests.TestData.Dependencies;
2+
using Microsoft.Playwright;
23
using System;
4+
using System.Threading.Tasks;
35
using Xunit;
46

57
namespace IntelliTect.TestTools.TestFramework.Tests.TestData.TestBlocks
@@ -70,4 +72,17 @@ public bool Execute(SomeDependency dep)
7072
return true;
7173
}
7274
}
75+
76+
public class PlaywrightError : TestBlock
77+
{
78+
public async Task Execute()
79+
{
80+
await Task.Delay(1);
81+
throw new InvalidOperationException("Oops");
82+
//using IPlaywright pw = await Playwright.CreateAsync();
83+
//IAPIRequestContext context = await pw.APIRequest.NewContextAsync();
84+
//await context.GetAsync("http://bad.url.com");
85+
// Playwright exception thrown for ENOTFOUND
86+
}
87+
}
7388
}

IntelliTect.TestTools.TestFramework/TestCase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,14 @@ private async Task<bool> TryRunBlock(Block block, object blockInstance, List<obj
422422
() => FinallyBlockExceptions.Add(ex)
423423
);
424424
}
425+
catch (Exception ex)
426+
{
427+
HandleFinallyBlock(
428+
block,
429+
() => TestBlockException = ex,
430+
() => FinallyBlockExceptions.Add(ex)
431+
);
432+
}
425433

426434
if (result) Log?.Debug($"Test block completed successfully.");
427435
return result;

0 commit comments

Comments
 (0)