Skip to content

Commit aa89389

Browse files
committed
ScopedAsyncAtomicFactory.Initializer: avoid unobserved task exception as well
Remove test in AsyncAtomicFactoryTests again
1 parent d36a511 commit aa89389

File tree

2 files changed

+1
-48
lines changed

2 files changed

+1
-48
lines changed

BitFaster.Caching.UnitTests/Atomic/AsyncAtomicFactoryTests.cs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -75,52 +75,6 @@ public async Task WhenValueCreateThrowsValueIsNotStored()
7575
(await a.GetValueAsync(1, k => Task.FromResult(3))).Should().Be(3);
7676
}
7777

78-
[Fact]
79-
public async Task WhenValueCreateThrowsDoesNotCauseUnobservedTaskException()
80-
{
81-
bool unobservedExceptionThrown = false;
82-
83-
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
84-
try
85-
{
86-
await AsyncAtomicFactoryGetValueAsync();
87-
88-
GC.Collect();
89-
GC.WaitForPendingFinalizers();
90-
}
91-
finally
92-
{
93-
TaskScheduler.UnobservedTaskException -= OnUnobservedTaskException;
94-
}
95-
unobservedExceptionThrown.Should().BeFalse();
96-
97-
void OnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
98-
{
99-
if (e.Exception?.InnerException is ArithmeticException)
100-
{
101-
unobservedExceptionThrown = true;
102-
}
103-
else
104-
{
105-
Assert.Fail(e.Exception?.ToString());
106-
}
107-
108-
e.SetObserved();
109-
}
110-
111-
static async Task AsyncAtomicFactoryGetValueAsync()
112-
{
113-
var a = new AsyncAtomicFactory<int, int>();
114-
try
115-
{
116-
_ = await a.GetValueAsync(12, (i) => throw new ArithmeticException());
117-
}
118-
catch (ArithmeticException)
119-
{
120-
}
121-
}
122-
}
123-
12478
[Fact]
12579
public async Task WhenCallersRunConcurrentlyResultIsFromWinner()
12680
{

BitFaster.Caching/Atomic/ScopedAsyncAtomicFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,9 @@ public async ValueTask<Scoped<V>> CreateScopeAsync<TFactory>(K key, TFactory val
174174

175175
return scope;
176176
}
177-
catch (Exception ex)
177+
catch (Exception)
178178
{
179179
Volatile.Write(ref isTaskInitialized, false);
180-
tcs.SetException(ex);
181180
throw;
182181
}
183182
}

0 commit comments

Comments
 (0)