Skip to content

Commit 41e7272

Browse files
committed
Rename test in ScopedAsyncAtomicFactoryTests and log unobserved task exception to test output.
1 parent e92a94b commit 41e7272

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

BitFaster.Caching.UnitTests/Atomic/AsyncAtomicFactoryTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
using BitFaster.Caching.Atomic;
55
using FluentAssertions;
66
using Xunit;
7+
using Xunit.Abstractions;
78

89
namespace BitFaster.Caching.UnitTests.Atomic
910
{
1011
public class AsyncAtomicFactoryTests
1112
{
13+
private readonly ITestOutputHelper outputHelper;
14+
15+
public AsyncAtomicFactoryTests(ITestOutputHelper outputHelper)
16+
{
17+
this.outputHelper = outputHelper;
18+
}
19+
1220
[Fact]
1321
public void DefaultCtorValueIsNotCreated()
1422
{
@@ -178,6 +186,7 @@ public async Task WhenValueCreateThrowsDoesNotCauseUnobservedTaskException()
178186

179187
void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
180188
{
189+
outputHelper.WriteLine($"Unobserved task exception {e.Exception}");
181190
unobservedExceptionThrown = true;
182191
e.SetObserved();
183192
}

BitFaster.Caching.UnitTests/Atomic/ScopedAsyncAtomicFactoryTests.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
using BitFaster.Caching.Atomic;
55
using FluentAssertions;
66
using Xunit;
7+
using Xunit.Abstractions;
78

89
namespace BitFaster.Caching.UnitTests.Atomic
910
{
1011
public class ScopedAsyncAtomicFactoryTests
1112
{
13+
private readonly ITestOutputHelper outputHelper;
14+
15+
public ScopedAsyncAtomicFactoryTests(ITestOutputHelper outputHelper)
16+
{
17+
this.outputHelper = outputHelper;
18+
}
19+
1220
[Fact]
1321
public void WhenScopeIsNotCreatedScopeIfCreatedReturnsNull()
1422
{
@@ -105,7 +113,7 @@ public void WhenValueIsCreatedDisposeDisposesValue()
105113
{
106114
var holder = new IntHolder() { actualNumber = 2 };
107115
var atomicFactory = new ScopedAsyncAtomicFactory<int, IntHolder>(holder);
108-
116+
109117
atomicFactory.Dispose();
110118

111119
holder.disposed.Should().BeTrue();
@@ -152,7 +160,7 @@ public async Task WhenCallersRunConcurrentlyResultIsFromWinner()
152160

153161
result1.l.Value.actualNumber.Should().Be(winningNumber);
154162
result2.l.Value.actualNumber.Should().Be(winningNumber);
155-
163+
156164
winnerCount.Should().Be(1);
157165
}
158166

@@ -199,14 +207,14 @@ await Task.WhenAll(first, second)
199207
}
200208

201209
[Fact]
202-
public async Task WhenValueCreateThrowsDoesNotCauseUnobservedTaskException()
210+
public async Task WhenCreateFromFactoryLifetimeThrowsDoesNotCauseUnobservedTaskException()
203211
{
204212
bool unobservedExceptionThrown = false;
205213
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
206214

207215
try
208216
{
209-
await AsyncAtomicFactoryGetValueAsync();
217+
await ScopedAsyncAtomicFactoryTryCreateLifetimeAsync();
210218

211219
GC.Collect();
212220
GC.WaitForPendingFinalizers();
@@ -220,11 +228,12 @@ public async Task WhenValueCreateThrowsDoesNotCauseUnobservedTaskException()
220228

221229
void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
222230
{
231+
outputHelper.WriteLine($"Unobserved task exception {e.Exception}");
223232
unobservedExceptionThrown = true;
224233
e.SetObserved();
225234
}
226235

227-
static async Task AsyncAtomicFactoryGetValueAsync()
236+
static async Task ScopedAsyncAtomicFactoryTryCreateLifetimeAsync()
228237
{
229238
var a = new ScopedAsyncAtomicFactory<int, IntHolder>();
230239
try

0 commit comments

Comments
 (0)