2525using System ;
2626using System . Collections . Concurrent ;
2727using System . Collections . Generic ;
28- using System . Runtime . CompilerServices ;
2928using System . Threading ;
3029using System . Threading . Tasks ;
3130using Microsoft . Playwright . Core ;
3433
3534namespace Microsoft . Playwright . Xunit ;
3635
37- public class WorkerAwareTest : ExceptionCapturer , IAsyncLifetime
36+ public class WorkerAwareTest : ExceptionCapturer
3837{
3938 private static readonly ConcurrentStack < Worker > _allWorkers = new ( ) ;
40- private Worker ? _currentWorker = null ! ;
39+ private Worker _currentWorker = null ! ;
4140
4241 internal class Worker
4342 {
@@ -58,8 +57,9 @@ public async Task<T> RegisterService<T>(string name, Func<Task<T>> factory) wher
5857 return ( _currentWorker . Services [ name ] as T ) ! ;
5958 }
6059
61- public virtual Task InitializeAsync ( )
60+ async public override Task InitializeAsync ( )
6261 {
62+ await base . InitializeAsync ( ) . ConfigureAwait ( false ) ;
6363 if ( ! _allWorkers . TryPop ( out _currentWorker ! ) )
6464 {
6565 _currentWorker = new ( ) ;
@@ -69,10 +69,9 @@ public virtual Task InitializeAsync()
6969 {
7070 AssertionsBase . SetDefaultTimeout ( PlaywrightSettingsProvider . ExpectTimeout . Value ) ;
7171 }
72- return Task . CompletedTask ;
7372 }
7473
75- public virtual async Task DisposeAsync ( )
74+ public async override Task DisposeAsync ( )
7675 {
7776 if ( TestOk )
7877 {
@@ -90,6 +89,7 @@ public virtual async Task DisposeAsync()
9089 }
9190 _currentWorker . Services . Clear ( ) ;
9291 }
92+ await base . DisposeAsync ( ) . ConfigureAwait ( false ) ;
9393 }
9494}
9595
@@ -107,16 +107,26 @@ public interface IWorkerService
107107/// Note: There is no way of getting the test status in xUnit in the dispose method.
108108/// For more information, see: https://stackoverflow.com/questions/28895448/current-test-status-in-xunit-net
109109/// </summary>
110- public class ExceptionCapturer
110+ public class ExceptionCapturer : IAsyncLifetime
111111{
112- protected static bool TestOk { get ; private set ; } = true ;
112+ protected bool TestOk { get ; private set ; } = true ;
113113
114- [ ModuleInitializer ]
115- public static void Setup ( )
114+ public ExceptionCapturer ( )
116115 {
117116 AppDomain . CurrentDomain . FirstChanceException += ( _ , e ) =>
118117 {
119118 TestOk = false ;
120119 } ;
121120 }
121+
122+ public virtual Task InitializeAsync ( )
123+ {
124+ TestOk = true ;
125+ return Task . CompletedTask ;
126+ }
127+
128+ public virtual Task DisposeAsync ( )
129+ {
130+ return Task . CompletedTask ;
131+ }
122132}
0 commit comments