25
25
using System ;
26
26
using System . Collections . Concurrent ;
27
27
using System . Collections . Generic ;
28
- using System . Runtime . CompilerServices ;
29
28
using System . Threading ;
30
29
using System . Threading . Tasks ;
31
30
using Microsoft . Playwright . Core ;
34
33
35
34
namespace Microsoft . Playwright . Xunit ;
36
35
37
- public class WorkerAwareTest : ExceptionCapturer , IAsyncLifetime
36
+ public class WorkerAwareTest : ExceptionCapturer
38
37
{
39
38
private static readonly ConcurrentStack < Worker > _allWorkers = new ( ) ;
40
- private Worker ? _currentWorker = null ! ;
39
+ private Worker _currentWorker = null ! ;
41
40
42
41
internal class Worker
43
42
{
@@ -58,8 +57,9 @@ public async Task<T> RegisterService<T>(string name, Func<Task<T>> factory) wher
58
57
return ( _currentWorker . Services [ name ] as T ) ! ;
59
58
}
60
59
61
- public virtual Task InitializeAsync ( )
60
+ async public override Task InitializeAsync ( )
62
61
{
62
+ await base . InitializeAsync ( ) . ConfigureAwait ( false ) ;
63
63
if ( ! _allWorkers . TryPop ( out _currentWorker ! ) )
64
64
{
65
65
_currentWorker = new ( ) ;
@@ -69,10 +69,9 @@ public virtual Task InitializeAsync()
69
69
{
70
70
AssertionsBase . SetDefaultTimeout ( PlaywrightSettingsProvider . ExpectTimeout . Value ) ;
71
71
}
72
- return Task . CompletedTask ;
73
72
}
74
73
75
- public virtual async Task DisposeAsync ( )
74
+ public async override Task DisposeAsync ( )
76
75
{
77
76
if ( TestOk )
78
77
{
@@ -90,6 +89,7 @@ public virtual async Task DisposeAsync()
90
89
}
91
90
_currentWorker . Services . Clear ( ) ;
92
91
}
92
+ await base . DisposeAsync ( ) . ConfigureAwait ( false ) ;
93
93
}
94
94
}
95
95
@@ -107,16 +107,26 @@ public interface IWorkerService
107
107
/// Note: There is no way of getting the test status in xUnit in the dispose method.
108
108
/// For more information, see: https://stackoverflow.com/questions/28895448/current-test-status-in-xunit-net
109
109
/// </summary>
110
- public class ExceptionCapturer
110
+ public class ExceptionCapturer : IAsyncLifetime
111
111
{
112
- protected static bool TestOk { get ; private set ; } = true ;
112
+ protected bool TestOk { get ; private set ; } = true ;
113
113
114
- [ ModuleInitializer ]
115
- public static void Setup ( )
114
+ public ExceptionCapturer ( )
116
115
{
117
116
AppDomain . CurrentDomain . FirstChanceException += ( _ , e ) =>
118
117
{
119
118
TestOk = false ;
120
119
} ;
121
120
}
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
+ }
122
132
}
0 commit comments