@@ -19,6 +19,7 @@ package container
19
19
import (
20
20
"encoding/json"
21
21
"errors"
22
+ "fmt"
22
23
"strings"
23
24
"testing"
24
25
"time"
@@ -138,10 +139,6 @@ func TestContainerHealthCheckBasic(t *testing.T) {
138
139
}
139
140
140
141
func TestContainerHealthCheckAdvance (t * testing.T ) {
141
- if rootlessutil .IsRootless () {
142
- t .Skip ("healthcheck tests are skipped in rootless environment" )
143
- }
144
-
145
142
testCase := nerdtest .Setup ()
146
143
147
144
// Docker CLI does not provide a standalone healthcheck command.
@@ -399,6 +396,43 @@ func TestContainerHealthCheckAdvance(t *testing.T) {
399
396
}
400
397
},
401
398
},
399
+ {
400
+ Description : "Healthcheck emits large output repeatedly" ,
401
+ Setup : func (data test.Data , helpers test.Helpers ) {
402
+ helpers .Ensure ("run" , "-d" , "--name" , data .Identifier (),
403
+ "--health-cmd" , "yes X | head -c 60000" ,
404
+ "--health-interval" , "1s" , "--health-timeout" , "2s" ,
405
+ testutil .CommonImage , "sleep" , nerdtest .Infinity )
406
+ nerdtest .EnsureContainerStarted (helpers , data .Identifier ())
407
+ },
408
+ Cleanup : func (data test.Data , helpers test.Helpers ) {
409
+ helpers .Anyhow ("rm" , "-f" , data .Identifier ())
410
+ },
411
+ Command : func (data test.Data , helpers test.Helpers ) test.TestableCommand {
412
+ for i := 0 ; i < 3 ; i ++ {
413
+ helpers .Ensure ("container" , "healthcheck" , data .Identifier ())
414
+ time .Sleep (2 * time .Second )
415
+ }
416
+ return helpers .Command ("inspect" , data .Identifier ())
417
+ },
418
+ Expected : func (data test.Data , helpers test.Helpers ) * test.Expected {
419
+ return & test.Expected {
420
+ ExitCode : 0 ,
421
+ Output : expect .All (func (_ string , t tig.T ) {
422
+ inspect := nerdtest .InspectContainer (helpers , data .Identifier ())
423
+ h := inspect .State .Health
424
+ debug , _ := json .MarshalIndent (h , "" , " " )
425
+ t .Log (string (debug ))
426
+ assert .Assert (t , h != nil , "expected health state" )
427
+ assert .Equal (t , h .Status , healthcheck .Healthy )
428
+ assert .Assert (t , len (h .Log ) >= 3 , "expected at least 3 health log entries" )
429
+ for _ , log := range h .Log {
430
+ assert .Assert (t , len (log .Output ) >= 1024 , fmt .Sprintf ("each output should be >= 1024 bytes, was: %s" , log .Output ))
431
+ }
432
+ }),
433
+ }
434
+ },
435
+ },
402
436
{
403
437
Description : "Health log in inspect keeps only the latest 5 entries" ,
404
438
Setup : func (data test.Data , helpers test.Helpers ) {
0 commit comments