@@ -132,12 +132,13 @@ public class TestOAuth2 : IAsyncLifetime
132
132
private readonly SemaphoreSlim _doneEvent = new SemaphoreSlim ( 0 , 1 ) ;
133
133
private readonly ITestOutputHelper _testOutputHelper ;
134
134
private readonly IConnectionFactory _connectionFactory ;
135
- private IConnection ? _connection ;
136
135
private readonly int _tokenExpiresInSeconds ;
137
136
private readonly OAuth2ClientCredentialsProvider _credentialsProvider ;
138
- private readonly CredentialsRefresher _credentialsRefresher ;
139
137
private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource ( ) ;
140
138
139
+ private IConnection ? _connection ;
140
+ private CredentialsRefresher ? _credentialsRefresher ;
141
+
141
142
public TestOAuth2 ( ITestOutputHelper testOutputHelper )
142
143
{
143
144
_testOutputHelper = testOutputHelper ;
@@ -156,15 +157,15 @@ public TestOAuth2(ITestOutputHelper testOutputHelper)
156
157
} ;
157
158
158
159
_tokenExpiresInSeconds = options . TokenExpiresInSeconds ;
159
-
160
- _credentialsRefresher = new CredentialsRefresher ( _credentialsProvider ,
161
- OnCredentialsRefreshedAsync ,
162
- _cancellationTokenSource . Token ) ;
163
160
}
164
161
165
162
public async Task InitializeAsync ( )
166
163
{
167
- _connection = await _connectionFactory . CreateConnectionAsync ( CancellationToken . None ) ;
164
+ _connection = await _connectionFactory . CreateConnectionAsync ( _cancellationTokenSource . Token ) ;
165
+
166
+ _credentialsRefresher = new CredentialsRefresher ( _credentialsProvider ,
167
+ OnCredentialsRefreshedAsync ,
168
+ _cancellationTokenSource . Token ) ;
168
169
}
169
170
170
171
public async Task DisposeAsync ( )
@@ -189,8 +190,6 @@ public async Task DisposeAsync()
189
190
private Task OnCredentialsRefreshedAsync ( Credentials ? credentials , Exception ? exception ,
190
191
CancellationToken cancellationToken = default )
191
192
{
192
- _testOutputHelper . WriteLine ( "[INFO] OnCredentialsRefreshedAsync called" ) ;
193
-
194
193
if ( _connection is null )
195
194
{
196
195
Assert . Fail ( "_connection is unexpectedly null!" ) ;
@@ -223,10 +222,11 @@ public async void IntegrationTest()
223
222
{
224
223
for ( int i = 0 ; i < 4 ; i ++ )
225
224
{
226
- _testOutputHelper . WriteLine ( "Wait until Token expires. Attempt #" + ( i + 1 ) ) ;
227
-
228
- await Task . Delay ( TimeSpan . FromSeconds ( _tokenExpiresInSeconds + 10 ) ) ;
229
- _testOutputHelper . WriteLine ( "Resuming .." ) ;
225
+ var delaySpan = TimeSpan . FromSeconds ( _tokenExpiresInSeconds + 10 ) ;
226
+ _testOutputHelper . WriteLine ( "{0} [INFO] wait '{1}' until Token expires. Attempt #{1}" ,
227
+ DateTime . Now , delaySpan , ( i + 1 ) ) ;
228
+ await Task . Delay ( delaySpan ) ;
229
+ _testOutputHelper . WriteLine ( "{0} [INFO] Resuming ..." , DateTime . Now ) ;
230
230
231
231
await PublishAsync ( publishChannel ) ;
232
232
await ConsumeAsync ( consumeChannel ) ;
0 commit comments