@@ -54,7 +54,7 @@ public async Task CreateContainerAsync_CreatesContainer()
54
54
}
55
55
56
56
// Timeout causing task to be cancelled
57
- [ Theory ]
57
+ [ Theory ( Skip = "There is nothing we can do to delay CreateContainerAsync (aka HttpClient.SendAsync) deterministic. We cannot control if it responses successful before the timeout." ) ]
58
58
[ InlineData ( 1 ) ]
59
59
[ InlineData ( 5 ) ]
60
60
[ InlineData ( 10 ) ]
@@ -87,10 +87,9 @@ public async Task CreateContainerAsync_TimeoutExpires_Fails(int millisecondsTime
87
87
}
88
88
89
89
[ Fact ]
90
- public async Task GetContainerLogs_Follow_False_TaskIsCompleted ( )
90
+ public async Task GetContainerLogs_Tty_False_Follow_True_TaskIsCompleted ( )
91
91
{
92
92
using var containerLogsCts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 60 ) ) ;
93
- var logList = new List < string > ( ) ;
94
93
95
94
var createContainerResponse = await _dockerClient . Containers . CreateContainerAsync (
96
95
new CreateContainerParameters ( )
@@ -108,7 +107,7 @@ await _dockerClient.Containers.StartContainerAsync(
108
107
_cts . Token
109
108
) ;
110
109
111
- containerLogsCts . CancelAfter ( TimeSpan . FromSeconds ( 20 ) ) ;
110
+ containerLogsCts . CancelAfter ( TimeSpan . FromSeconds ( 5 ) ) ;
112
111
113
112
var containerLogsTask = _dockerClient . Containers . GetContainerLogsAsync (
114
113
createContainerResponse . ID ,
@@ -120,7 +119,7 @@ await _dockerClient.Containers.StartContainerAsync(
120
119
Follow = true
121
120
} ,
122
121
containerLogsCts . Token ,
123
- new Progress < string > ( ( m ) => { _output . WriteLine ( m ) ; logList . Add ( m ) ; } )
122
+ new Progress < string > ( m => _output . WriteLine ( m ) )
124
123
) ;
125
124
126
125
await _dockerClient . Containers . StopContainerAsync (
@@ -136,7 +135,7 @@ await _dockerClient.Containers.StopContainerAsync(
136
135
[ Fact ]
137
136
public async Task GetContainerLogs_Tty_False_Follow_False_ReadsLogs ( )
138
137
{
139
- using var containerLogsCts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 50 ) ) ;
138
+ using var containerLogsCts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 60 ) ) ;
140
139
var logList = new List < string > ( ) ;
141
140
142
141
var createContainerResponse = await _dockerClient . Containers . CreateContainerAsync (
@@ -155,7 +154,9 @@ await _dockerClient.Containers.StartContainerAsync(
155
154
_cts . Token
156
155
) ;
157
156
158
- await _dockerClient . Containers . GetContainerLogsAsync (
157
+ containerLogsCts . CancelAfter ( TimeSpan . FromSeconds ( 5 ) ) ;
158
+
159
+ var containerLogsTask = _dockerClient . Containers . GetContainerLogsAsync (
159
160
createContainerResponse . ID ,
160
161
new ContainerLogsParameters
161
162
{
@@ -165,33 +166,33 @@ await _dockerClient.Containers.GetContainerLogsAsync(
165
166
Follow = false
166
167
} ,
167
168
containerLogsCts . Token ,
168
- new Progress < string > ( ( m ) => { logList . Add ( m ) ; _output . WriteLine ( m ) ; } )
169
+ new Progress < string > ( m => { logList . Add ( m ) ; _output . WriteLine ( m ) ; } )
169
170
) ;
170
171
171
172
await _dockerClient . Containers . StopContainerAsync (
172
173
createContainerResponse . ID ,
173
174
new ContainerStopParameters ( ) ,
174
175
_cts . Token
175
- ) ;
176
+ ) ;
176
177
178
+ await containerLogsTask ;
177
179
_output . WriteLine ( $ "Line count: { logList . Count } ") ;
178
180
179
181
Assert . NotEmpty ( logList ) ;
180
182
}
181
183
182
184
[ Fact ]
183
- public async Task GetContainerLogs_Tty_False_Follow_True_Requires_Task_To_Be_Cancelled ( )
185
+ public async Task GetContainerLogs_Tty_True_Follow_False_ReadsLogs ( )
184
186
{
185
- using var containerLogsCts = CancellationTokenSource . CreateLinkedTokenSource ( _cts . Token ) ;
186
-
187
+ using var containerLogsCts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 60 ) ) ;
187
188
var logList = new List < string > ( ) ;
188
189
189
190
var createContainerResponse = await _dockerClient . Containers . CreateContainerAsync (
190
191
new CreateContainerParameters ( )
191
192
{
192
193
Image = _imageId ,
193
194
Name = Guid . NewGuid ( ) . ToString ( ) ,
194
- Tty = false
195
+ Tty = true
195
196
} ,
196
197
_cts . Token
197
198
) ;
@@ -204,33 +205,44 @@ await _dockerClient.Containers.StartContainerAsync(
204
205
205
206
containerLogsCts . CancelAfter ( TimeSpan . FromSeconds ( 5 ) ) ;
206
207
207
- // Will be cancelled after CancellationTokenSource interval, would run forever otherwise
208
- await Assert . ThrowsAsync < TaskCanceledException > ( ( ) => _dockerClient . Containers . GetContainerLogsAsync (
208
+ var containerLogsTask = _dockerClient . Containers . GetContainerLogsAsync (
209
209
createContainerResponse . ID ,
210
210
new ContainerLogsParameters
211
211
{
212
212
ShowStderr = true ,
213
213
ShowStdout = true ,
214
214
Timestamps = true ,
215
- Follow = true
215
+ Follow = false
216
216
} ,
217
217
containerLogsCts . Token ,
218
- new Progress < string > ( ( m ) => { _output . WriteLine ( JsonConvert . SerializeObject ( m ) ) ; logList . Add ( m ) ; } )
219
- ) ) ;
218
+ new Progress < string > ( m => { _output . WriteLine ( m ) ; logList . Add ( m ) ; } )
219
+ ) ;
220
+
221
+ await Task . Delay ( TimeSpan . FromSeconds ( 5 ) ) ;
222
+
223
+ await _dockerClient . Containers . StopContainerAsync (
224
+ createContainerResponse . ID ,
225
+ new ContainerStopParameters ( ) ,
226
+ _cts . Token
227
+ ) ;
228
+
229
+ await containerLogsTask ;
230
+ _output . WriteLine ( $ "Line count: { logList . Count } ") ;
231
+
232
+ Assert . NotEmpty ( logList ) ;
220
233
}
221
234
222
235
[ Fact ]
223
- public async Task GetContainerLogs_Tty_True_Follow_True_Requires_Task_To_Be_Cancelled ( )
236
+ public async Task GetContainerLogs_Tty_False_Follow_True_Requires_Task_To_Be_Cancelled ( )
224
237
{
225
238
using var containerLogsCts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 60 ) ) ;
226
- var logList = new List < string > ( ) ;
227
239
228
240
var createContainerResponse = await _dockerClient . Containers . CreateContainerAsync (
229
241
new CreateContainerParameters ( )
230
242
{
231
243
Image = _imageId ,
232
244
Name = Guid . NewGuid ( ) . ToString ( ) ,
233
- Tty = true
245
+ Tty = false
234
246
} ,
235
247
_cts . Token
236
248
) ;
@@ -241,9 +253,9 @@ await _dockerClient.Containers.StartContainerAsync(
241
253
_cts . Token
242
254
) ;
243
255
244
- containerLogsCts . CancelAfter ( TimeSpan . FromSeconds ( 10 ) ) ;
256
+ containerLogsCts . CancelAfter ( TimeSpan . FromSeconds ( 5 ) ) ;
245
257
246
- var containerLogsTask = _dockerClient . Containers . GetContainerLogsAsync (
258
+ await Assert . ThrowsAsync < TaskCanceledException > ( ( ) => _dockerClient . Containers . GetContainerLogsAsync (
247
259
createContainerResponse . ID ,
248
260
new ContainerLogsParameters
249
261
{
@@ -253,17 +265,14 @@ await _dockerClient.Containers.StartContainerAsync(
253
265
Follow = true
254
266
} ,
255
267
containerLogsCts . Token ,
256
- new Progress < string > ( ( m ) => { _output . WriteLine ( m ) ; logList . Add ( m ) ; } )
257
- ) ;
258
-
259
- await Assert . ThrowsAsync < TaskCanceledException > ( ( ) => containerLogsTask ) ;
268
+ new Progress < string > ( m => _output . WriteLine ( m ) )
269
+ ) ) ;
260
270
}
261
271
262
272
[ Fact ]
263
- public async Task GetContainerLogs_Tty_True_Follow_True_StreamLogs_TaskIsCancelled ( )
273
+ public async Task GetContainerLogs_Tty_True_Follow_True_Requires_Task_To_Be_Cancelled ( )
264
274
{
265
275
using var containerLogsCts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 60 ) ) ;
266
- var logList = new List < string > ( ) ;
267
276
268
277
var createContainerResponse = await _dockerClient . Containers . CreateContainerAsync (
269
278
new CreateContainerParameters ( )
@@ -293,53 +302,14 @@ await _dockerClient.Containers.StartContainerAsync(
293
302
Follow = true
294
303
} ,
295
304
containerLogsCts . Token ,
296
- new Progress < string > ( ( m ) => { _output . WriteLine ( m ) ; logList . Add ( m ) ; } )
297
- ) ;
298
-
299
- await Task . Delay ( TimeSpan . FromSeconds ( 10 ) ) ;
300
-
301
- await _dockerClient . Containers . StopContainerAsync (
302
- createContainerResponse . ID ,
303
- new ContainerStopParameters
304
- {
305
- WaitBeforeKillSeconds = 0
306
- } ,
307
- _cts . Token
308
- ) ;
309
-
310
- await _dockerClient . Containers . RemoveContainerAsync (
311
- createContainerResponse . ID ,
312
- new ContainerRemoveParameters
313
- {
314
- Force = true
315
- } ,
316
- _cts . Token
305
+ new Progress < string > ( m => _output . WriteLine ( m ) )
317
306
) ;
318
307
319
308
await Assert . ThrowsAsync < TaskCanceledException > ( ( ) => containerLogsTask ) ;
320
-
321
- _output . WriteLine ( JsonConvert . SerializeObject ( new
322
- {
323
- AsyncState = containerLogsTask . AsyncState ,
324
- CreationOptions = containerLogsTask . CreationOptions ,
325
- Exception = containerLogsTask . Exception ,
326
- Id = containerLogsTask . Id ,
327
- IsCanceled = containerLogsTask . IsCanceled ,
328
- IsCompleted = containerLogsTask . IsCompleted ,
329
- IsCompletedSuccessfully = containerLogsTask . IsCompletedSuccessfully ,
330
- Status = containerLogsTask . Status
331
- }
332
- ) ) ;
333
-
334
- _output . WriteLine ( $ "Line count: { logList . Count } ") ;
335
-
336
- await Task . Delay ( TimeSpan . FromSeconds ( 1 ) ) ;
337
-
338
- Assert . NotEmpty ( logList ) ;
339
309
}
340
310
341
311
[ Fact ]
342
- public async Task GetContainerLogs_Tty_True_ReadsLogs ( )
312
+ public async Task GetContainerLogs_Tty_True_Follow_True_ReadsLogs_TaskIsCancelled ( )
343
313
{
344
314
using var containerLogsCts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 60 ) ) ;
345
315
var logList = new List < string > ( ) ;
@@ -369,47 +339,22 @@ await _dockerClient.Containers.StartContainerAsync(
369
339
ShowStderr = true ,
370
340
ShowStdout = true ,
371
341
Timestamps = true ,
372
- Follow = false
342
+ Follow = true
373
343
} ,
374
344
containerLogsCts . Token ,
375
- new Progress < string > ( ( m ) => { _output . WriteLine ( m ) ; logList . Add ( m ) ; } )
345
+ new Progress < string > ( m => { _output . WriteLine ( m ) ; logList . Add ( m ) ; } )
376
346
) ;
377
347
378
- await Task . Delay ( TimeSpan . FromSeconds ( 10 ) ) ;
348
+ await Task . Delay ( TimeSpan . FromSeconds ( 5 ) ) ;
379
349
380
350
await _dockerClient . Containers . StopContainerAsync (
381
351
createContainerResponse . ID ,
382
- new ContainerStopParameters
383
- {
384
- WaitBeforeKillSeconds = 0
385
- } ,
386
- _cts . Token
387
- ) ;
388
-
389
- await _dockerClient . Containers . RemoveContainerAsync (
390
- createContainerResponse . ID ,
391
- new ContainerRemoveParameters
392
- {
393
- Force = true
394
- } ,
352
+ new ContainerStopParameters ( ) ,
395
353
_cts . Token
396
354
) ;
397
355
398
- await containerLogsTask ;
399
-
400
- _output . WriteLine ( JsonConvert . SerializeObject ( new
401
- {
402
- AsyncState = containerLogsTask . AsyncState ,
403
- CreationOptions = containerLogsTask . CreationOptions ,
404
- Exception = containerLogsTask . Exception ,
405
- Id = containerLogsTask . Id ,
406
- IsCanceled = containerLogsTask . IsCanceled ,
407
- IsCompleted = containerLogsTask . IsCompleted ,
408
- IsCompletedSuccessfully = containerLogsTask . IsCompletedSuccessfully ,
409
- Status = containerLogsTask . Status
410
- }
411
- ) ) ;
412
356
357
+ await Assert . ThrowsAsync < TaskCanceledException > ( ( ) => containerLogsTask ) ;
413
358
_output . WriteLine ( $ "Line count: { logList . Count } ") ;
414
359
415
360
Assert . NotEmpty ( logList ) ;
@@ -445,7 +390,7 @@ await _dockerClient.Containers.GetContainerStatsAsync(
445
390
{
446
391
Stream = false
447
392
} ,
448
- new Progress < ContainerStatsResponse > ( ( m ) => { _output . WriteLine ( m . ID ) ; containerStatsList . Add ( m ) ; } ) ,
393
+ new Progress < ContainerStatsResponse > ( m => { _output . WriteLine ( m . ID ) ; containerStatsList . Add ( m ) ; } ) ,
449
394
tcs . Token
450
395
) ;
451
396
@@ -492,7 +437,7 @@ await _dockerClient.Containers.GetContainerStatsAsync(
492
437
{
493
438
Stream = true
494
439
} ,
495
- new Progress < ContainerStatsResponse > ( ( m ) => { containerStatsList . Add ( m ) ; _output . WriteLine ( JsonConvert . SerializeObject ( m ) ) ; } ) ,
440
+ new Progress < ContainerStatsResponse > ( m => { containerStatsList . Add ( m ) ; _output . WriteLine ( JsonConvert . SerializeObject ( m ) ) ; } ) ,
496
441
linkedCts . Token
497
442
) ;
498
443
}
@@ -536,7 +481,7 @@ await _dockerClient.Containers.GetContainerStatsAsync(
536
481
{
537
482
Stream = false
538
483
} ,
539
- new Progress < ContainerStatsResponse > ( ( m ) => { _output . WriteLine ( m . ID ) ; containerStatsList . Add ( m ) ; } ) ,
484
+ new Progress < ContainerStatsResponse > ( m => { _output . WriteLine ( m . ID ) ; containerStatsList . Add ( m ) ; } ) ,
540
485
tcs . Token
541
486
) ;
542
487
@@ -585,7 +530,7 @@ await _dockerClient.Containers.GetContainerStatsAsync(
585
530
{
586
531
Stream = true
587
532
} ,
588
- new Progress < ContainerStatsResponse > ( ( m ) => { containerStatsList . Add ( m ) ; _output . WriteLine ( JsonConvert . SerializeObject ( m ) ) ; } ) ,
533
+ new Progress < ContainerStatsResponse > ( m => { containerStatsList . Add ( m ) ; _output . WriteLine ( JsonConvert . SerializeObject ( m ) ) ; } ) ,
589
534
linkedTcs . Token
590
535
) ;
591
536
}
0 commit comments