@@ -19,6 +19,7 @@ package container
1919import (
2020 "encoding/json"
2121 "errors"
22+ "fmt"
2223 "strings"
2324 "testing"
2425 "time"
@@ -138,10 +139,6 @@ func TestContainerHealthCheckBasic(t *testing.T) {
138139}
139140
140141func TestContainerHealthCheckAdvance (t * testing.T ) {
141- if rootlessutil .IsRootless () {
142- t .Skip ("healthcheck tests are skipped in rootless environment" )
143- }
144-
145142 testCase := nerdtest .Setup ()
146143
147144 // Docker CLI does not provide a standalone healthcheck command.
@@ -399,6 +396,43 @@ func TestContainerHealthCheckAdvance(t *testing.T) {
399396 }
400397 },
401398 },
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+ },
402436 {
403437 Description : "Health log in inspect keeps only the latest 5 entries" ,
404438 Setup : func (data test.Data , helpers test.Helpers ) {
0 commit comments