@@ -82,34 +82,38 @@ func (cc *CesantaConfig) Save(path string) error {
82
82
return err
83
83
}
84
84
85
+ // FIXME: this is a copy of the utility method EnsureContainerStarted
86
+ // We cannot reference it (circular dep), so the copy.
87
+ // To be fixed later when we will be done migrating test helpers to the new framework and we can split them
88
+ // in meaningful subpackages.
89
+
85
90
func ensureContainerStarted (helpers test.Helpers , con string ) {
86
- const maxRetry = 5
87
- const sleep = time .Second
88
- success := false
89
- for i := 0 ; i < maxRetry && ! success ; i ++ {
90
- time .Sleep (sleep )
91
- count := i
92
- cmd := helpers .Command ("container" , "inspect" , con )
93
- cmd .Run (& test.Expected {
94
- Output : func (stdout string , info string , t * testing.T ) {
95
- var dc []dockercompat.Container
96
- err := json .Unmarshal ([]byte (stdout ), & dc )
97
- assert .NilError (t , err , "Unable to unmarshal output\n " + info )
98
- assert .Equal (t , 1 , len (dc ), "Unexpectedly got multiple results\n " + info )
99
- if dc [0 ].State .Running {
100
- success = true
101
- return
102
- }
103
- if count == maxRetry - 1 {
104
- // FIXME: there is currently no simple way to capture stderr
105
- // Sometimes, it is convenient for debugging, like here
106
- // Here we cheat with unbuffer which will bundle stderr and stdout together
107
- // This is just bad
108
- t .Error (helpers .Err ("logs" , con ))
109
- t .Fatalf ("container %s still not running after %d retries" , con , count )
110
- }
111
- },
112
- })
91
+ started := false
92
+ for i := 0 ; i < 5 && ! started ; i ++ {
93
+ helpers .Command ("container" , "inspect" , con ).
94
+ Run (& test.Expected {
95
+ ExitCode : test .ExitCodeNoCheck ,
96
+ Output : func (stdout string , info string , t * testing.T ) {
97
+ var dc []dockercompat.Container
98
+ err := json .Unmarshal ([]byte (stdout ), & dc )
99
+ if err != nil || len (dc ) == 0 {
100
+ return
101
+ }
102
+ assert .Equal (t , len (dc ), 1 , "Unexpectedly got multiple results\n " + info )
103
+ started = dc [0 ].State .Running
104
+ },
105
+ })
106
+ time .Sleep (time .Second )
107
+ }
108
+
109
+ if ! started {
110
+ ins := helpers .Capture ("container" , "inspect" , con )
111
+ lgs := helpers .Capture ("logs" , con )
112
+ ps := helpers .Capture ("ps" , "-a" )
113
+ helpers .T ().Log (ins )
114
+ helpers .T ().Log (lgs )
115
+ helpers .T ().Log (ps )
116
+ helpers .T ().Fatalf ("container %s still not running after %d retries" , con , 5 )
113
117
}
114
118
}
115
119
0 commit comments