Skip to content

Commit 46a1e25

Browse files
Merge pull request #20176 from edsantiago/e2e_check_stderr__more
e2e: ExitCleanly(): the final step
2 parents 4212b49 + ccb7da5 commit 46a1e25

File tree

9 files changed

+190
-170
lines changed

9 files changed

+190
-170
lines changed

test/e2e/export_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
. "github.com/containers/podman/v4/test/utils"
88
. "github.com/onsi/ginkgo/v2"
99
. "github.com/onsi/gomega"
10-
. "github.com/onsi/gomega/gexec"
1110
)
1211

1312
var _ = Describe("Podman export", func() {
@@ -19,7 +18,7 @@ var _ = Describe("Podman export", func() {
1918
outfile := filepath.Join(podmanTest.TempDir, "container.tar")
2019
result := podmanTest.Podman([]string{"export", "-o", outfile, cid})
2120
result.WaitWithDefaultTimeout()
22-
Expect(result).Should(Exit(0))
21+
Expect(result).Should(ExitCleanly())
2322
_, err := os.Stat(outfile)
2423
Expect(err).ToNot(HaveOccurred())
2524

@@ -34,7 +33,7 @@ var _ = Describe("Podman export", func() {
3433
outfile := filepath.Join(podmanTest.TempDir, "container.tar")
3534
result := podmanTest.Podman([]string{"container", "export", "-o", outfile, cid})
3635
result.WaitWithDefaultTimeout()
37-
Expect(result).Should(Exit(0))
36+
Expect(result).Should(ExitCleanly())
3837
_, err := os.Stat(outfile)
3938
Expect(err).ToNot(HaveOccurred())
4039

test/e2e/quadlet_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"github.com/containers/podman/v4/pkg/systemd/parser"
12+
. "github.com/containers/podman/v4/test/utils"
1213
"github.com/containers/podman/v4/version"
1314
"github.com/mattn/go-shellwords"
1415

@@ -434,7 +435,7 @@ var _ = Describe("quadlet system generator", func() {
434435
It("Should print correct version", func() {
435436
session := podmanTest.Quadlet([]string{"-version"}, "/something")
436437
session.WaitWithDefaultTimeout()
437-
Expect(session).Should(Exit(0))
438+
Expect(session).Should(ExitCleanly())
438439
Expect(session.OutputToString()).To(Equal(version.Version.String()))
439440
})
440441
})
@@ -512,6 +513,7 @@ BOGUS=foo
512513
session := podmanTest.Quadlet([]string{"-dryrun"}, quadletDir)
513514
session.WaitWithDefaultTimeout()
514515
Expect(session).Should(Exit(0))
516+
Expect(session.ErrorToString()).To(ContainSubstring("Loading source unit file "))
515517

516518
current := session.OutputToStringArray()
517519
expected := []string{

test/e2e/restart_test.go

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var _ = Describe("Podman restart", func() {
2626

2727
session := podmanTest.Podman([]string{"restart", "test1"})
2828
session.WaitWithDefaultTimeout()
29-
Expect(session).Should(Exit(0))
29+
Expect(session).Should(ExitCleanly())
3030
restartTime := podmanTest.Podman([]string{"inspect", "--format='{{.State.StartedAt}}'", "test1"})
3131
restartTime.WaitWithDefaultTimeout()
3232
Expect(restartTime.OutputToString()).To(Not(Equal(startTime.OutputToString())))
@@ -35,18 +35,18 @@ var _ = Describe("Podman restart", func() {
3535
It("podman restart stopped container by ID", func() {
3636
session := podmanTest.Podman([]string{"create", ALPINE, "ls"})
3737
session.WaitWithDefaultTimeout()
38-
Expect(session).Should(Exit(0))
38+
Expect(session).Should(ExitCleanly())
3939
cid := session.OutputToString()
4040
startTime := podmanTest.Podman([]string{"inspect", "--format='{{.State.StartedAt}}'", cid})
4141
startTime.WaitWithDefaultTimeout()
4242

4343
startSession := podmanTest.Podman([]string{"start", "--attach", cid})
4444
startSession.WaitWithDefaultTimeout()
45-
Expect(startSession).Should(Exit(0))
45+
Expect(startSession).Should(ExitCleanly())
4646

4747
session2 := podmanTest.Podman([]string{"restart", cid})
4848
session2.WaitWithDefaultTimeout()
49-
Expect(session2).Should(Exit(0))
49+
Expect(session2).Should(ExitCleanly())
5050
restartTime := podmanTest.Podman([]string{"inspect", "--format='{{.State.StartedAt}}'", cid})
5151
restartTime.WaitWithDefaultTimeout()
5252
Expect(restartTime.OutputToString()).To(Not(Equal(startTime.OutputToString())))
@@ -61,7 +61,7 @@ var _ = Describe("Podman restart", func() {
6161

6262
session := podmanTest.Podman([]string{"restart", "test1"})
6363
session.WaitWithDefaultTimeout()
64-
Expect(session).Should(Exit(0))
64+
Expect(session).Should(ExitCleanly())
6565
restartTime := podmanTest.Podman([]string{"inspect", "--format='{{.State.StartedAt}}'", "test1"})
6666
restartTime.WaitWithDefaultTimeout()
6767
Expect(restartTime.OutputToString()).To(Not(Equal(startTime.OutputToString())))
@@ -76,7 +76,7 @@ var _ = Describe("Podman restart", func() {
7676

7777
session := podmanTest.Podman([]string{"container", "restart", "test1"})
7878
session.WaitWithDefaultTimeout()
79-
Expect(session).Should(Exit(0))
79+
Expect(session).Should(ExitCleanly())
8080
restartTime := podmanTest.Podman([]string{"container", "inspect", "--format='{{.State.StartedAt}}'", "test1"})
8181
restartTime.WaitWithDefaultTimeout()
8282
Expect(restartTime.OutputToString()).To(Not(Equal(startTime.OutputToString())))
@@ -93,7 +93,7 @@ var _ = Describe("Podman restart", func() {
9393

9494
session := podmanTest.Podman([]string{"restart", "test1", "test2"})
9595
session.WaitWithDefaultTimeout()
96-
Expect(session).Should(Exit(0))
96+
Expect(session).Should(ExitCleanly())
9797
restartTime := podmanTest.Podman([]string{"inspect", "--format='{{.State.StartedAt}}'", "test1", "test2"})
9898
restartTime.WaitWithDefaultTimeout()
9999
Expect(restartTime.OutputToStringArray()[0]).To(Not(Equal(startTime.OutputToStringArray()[0])))
@@ -116,7 +116,7 @@ var _ = Describe("Podman restart", func() {
116116
}
117117
session := podmanTest.Podman([]string{"restart", cid})
118118
session.WaitWithDefaultTimeout()
119-
Expect(session).Should(Exit(0))
119+
Expect(session).Should(ExitCleanly())
120120
restartTime := podmanTest.Podman([]string{"inspect", "--format='{{.State.StartedAt}}'", "test1", "test2"})
121121
restartTime.WaitWithDefaultTimeout()
122122
Expect(restartTime.OutputToStringArray()[0]).To(Equal(startTime.OutputToStringArray()[0]))
@@ -126,14 +126,20 @@ var _ = Describe("Podman restart", func() {
126126
It("podman restart non-stop container with short timeout", func() {
127127
session := podmanTest.Podman([]string{"run", "-d", "--name", "test1", "--env", "STOPSIGNAL=SIGKILL", ALPINE, "sleep", "999"})
128128
session.WaitWithDefaultTimeout()
129-
Expect(session).Should(Exit(0))
129+
Expect(session).Should(ExitCleanly())
130130
startTime := time.Now()
131131
session = podmanTest.Podman([]string{"restart", "-t", "2", "test1"})
132132
session.WaitWithDefaultTimeout()
133133
Expect(session).Should(Exit(0))
134134
timeSince := time.Since(startTime)
135135
Expect(timeSince).To(BeNumerically("<", 10*time.Second))
136136
Expect(timeSince).To(BeNumerically(">", 2*time.Second))
137+
stderr := session.ErrorToString()
138+
if IsRemote() {
139+
Expect(stderr).To(BeEmpty())
140+
} else {
141+
Expect(stderr).To(ContainSubstring("StopSignal SIGTERM failed to stop container test1 in 2 seconds, resorting to SIGKILL"))
142+
}
137143
})
138144

139145
It("podman restart --all", func() {
@@ -142,14 +148,14 @@ var _ = Describe("Podman restart", func() {
142148

143149
test2 := podmanTest.RunTopContainer("test2")
144150
test2.WaitWithDefaultTimeout()
145-
Expect(test2).Should(Exit(0))
151+
Expect(test2).Should(ExitCleanly())
146152

147153
startTime := podmanTest.Podman([]string{"inspect", "--format='{{.State.StartedAt}}'", "test1", "test2"})
148154
startTime.WaitWithDefaultTimeout()
149155

150156
session := podmanTest.Podman([]string{"restart", "--all"})
151157
session.WaitWithDefaultTimeout()
152-
Expect(session).Should(Exit(0))
158+
Expect(session).Should(ExitCleanly())
153159
restartTime := podmanTest.Podman([]string{"inspect", "--format='{{.State.StartedAt}}'", "test1", "test2"})
154160
restartTime.WaitWithDefaultTimeout()
155161
Expect(restartTime.OutputToStringArray()[0]).To(Not(Equal(startTime.OutputToStringArray()[0])))
@@ -162,14 +168,14 @@ var _ = Describe("Podman restart", func() {
162168

163169
test2 := podmanTest.RunTopContainer("test2")
164170
test2.WaitWithDefaultTimeout()
165-
Expect(test2).Should(Exit(0))
171+
Expect(test2).Should(ExitCleanly())
166172

167173
startTime := podmanTest.Podman([]string{"inspect", "--format='{{.State.StartedAt}}'", "test1", "test2"})
168174
startTime.WaitWithDefaultTimeout()
169175

170176
session := podmanTest.Podman([]string{"restart", "-a", "--running"})
171177
session.WaitWithDefaultTimeout()
172-
Expect(session).Should(Exit(0))
178+
Expect(session).Should(ExitCleanly())
173179
restartTime := podmanTest.Podman([]string{"inspect", "--format='{{.State.StartedAt}}'", "test1", "test2"})
174180
restartTime.WaitWithDefaultTimeout()
175181
Expect(restartTime.OutputToStringArray()[0]).To(Equal(startTime.OutputToStringArray()[0]))
@@ -184,22 +190,22 @@ var _ = Describe("Podman restart", func() {
184190

185191
session := podmanTest.RunTopContainerInPod("host-restart-test", "foobar99")
186192
session.WaitWithDefaultTimeout()
187-
Expect(session).Should(Exit(0))
193+
Expect(session).Should(ExitCleanly())
188194

189195
testCmd := []string{"exec", "host-restart-test", "sh", "-c", "wc -l < /etc/hosts"}
190196

191197
// before restart
192198
beforeRestart := podmanTest.Podman(testCmd)
193199
beforeRestart.WaitWithDefaultTimeout()
194-
Expect(beforeRestart).Should(Exit(0))
200+
Expect(beforeRestart).Should(ExitCleanly())
195201

196202
session = podmanTest.Podman([]string{"restart", "host-restart-test"})
197203
session.WaitWithDefaultTimeout()
198-
Expect(session).Should(Exit(0))
204+
Expect(session).Should(ExitCleanly())
199205

200206
afterRestart := podmanTest.Podman(testCmd)
201207
afterRestart.WaitWithDefaultTimeout()
202-
Expect(afterRestart).Should(Exit(0))
208+
Expect(afterRestart).Should(ExitCleanly())
203209

204210
// line count should be equal
205211
Expect(beforeRestart.OutputToString()).To(Equal(afterRestart.OutputToString()))
@@ -208,22 +214,22 @@ var _ = Describe("Podman restart", func() {
208214
It("podman restart all stopped containers with --all", func() {
209215
session := podmanTest.RunTopContainer("")
210216
session.WaitWithDefaultTimeout()
211-
Expect(session).Should(Exit(0))
217+
Expect(session).Should(ExitCleanly())
212218
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
213219

214220
session = podmanTest.RunTopContainer("")
215221
session.WaitWithDefaultTimeout()
216-
Expect(session).Should(Exit(0))
222+
Expect(session).Should(ExitCleanly())
217223
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2))
218224

219225
session = podmanTest.Podman([]string{"stop", "--all"})
220226
session.WaitWithDefaultTimeout()
221-
Expect(session).Should(Exit(0))
227+
Expect(session).Should(ExitCleanly())
222228
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
223229

224230
session = podmanTest.Podman([]string{"restart", "--all"})
225231
session.WaitWithDefaultTimeout()
226-
Expect(session).Should(Exit(0))
232+
Expect(session).Should(ExitCleanly())
227233
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2))
228234
})
229235

@@ -233,16 +239,16 @@ var _ = Describe("Podman restart", func() {
233239

234240
session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile, ALPINE, "top"})
235241
session.WaitWithDefaultTimeout()
236-
Expect(session).Should(Exit(0))
242+
Expect(session).Should(ExitCleanly())
237243
cid := session.OutputToStringArray()[0]
238244

239245
session = podmanTest.Podman([]string{"start", cid})
240246
session.WaitWithDefaultTimeout()
241-
Expect(session).Should(Exit(0))
247+
Expect(session).Should(ExitCleanly())
242248

243249
result := podmanTest.Podman([]string{"restart", "--cidfile", tmpFile})
244250
result.WaitWithDefaultTimeout()
245-
Expect(result).Should(Exit(0))
251+
Expect(result).Should(ExitCleanly())
246252
output := result.OutputToString()
247253
Expect(output).To(ContainSubstring(cid))
248254
})
@@ -254,19 +260,19 @@ var _ = Describe("Podman restart", func() {
254260

255261
session := podmanTest.Podman([]string{"run", "--cidfile", tmpFile1, "-d", ALPINE, "top"})
256262
session.WaitWithDefaultTimeout()
257-
Expect(session).Should(Exit(0))
263+
Expect(session).Should(ExitCleanly())
258264
cid1 := session.OutputToStringArray()[0]
259265
Expect(podmanTest.NumberOfContainers()).To(Equal(1))
260266

261267
session = podmanTest.Podman([]string{"run", "--cidfile", tmpFile2, "-d", ALPINE, "top"})
262268
session.WaitWithDefaultTimeout()
263-
Expect(session).Should(Exit(0))
269+
Expect(session).Should(ExitCleanly())
264270
cid2 := session.OutputToStringArray()[0]
265271
Expect(podmanTest.NumberOfContainers()).To(Equal(2))
266272

267273
result := podmanTest.Podman([]string{"restart", "--cidfile", tmpFile1, "--cidfile", tmpFile2})
268274
result.WaitWithDefaultTimeout()
269-
Expect(result).Should(Exit(0))
275+
Expect(result).Should(ExitCleanly())
270276
output := result.OutputToString()
271277
Expect(output).To(ContainSubstring(cid1))
272278
Expect(output).To(ContainSubstring(cid2))
@@ -296,17 +302,17 @@ var _ = Describe("Podman restart", func() {
296302
It("podman restart --filter", func() {
297303
session1 := podmanTest.RunTopContainer("")
298304
session1.WaitWithDefaultTimeout()
299-
Expect(session1).Should(Exit(0))
305+
Expect(session1).Should(ExitCleanly())
300306
cid1 := session1.OutputToString()
301307

302308
session1 = podmanTest.RunTopContainer("")
303309
session1.WaitWithDefaultTimeout()
304-
Expect(session1).Should(Exit(0))
310+
Expect(session1).Should(ExitCleanly())
305311
cid2 := session1.OutputToString()
306312

307313
session1 = podmanTest.RunTopContainerWithArgs("", []string{"--label", "test=with,comma"})
308314
session1.WaitWithDefaultTimeout()
309-
Expect(session1).Should(Exit(0))
315+
Expect(session1).Should(ExitCleanly())
310316
cid3 := session1.OutputToString()
311317
shortCid3 := cid3[0:5]
312318

@@ -316,22 +322,22 @@ var _ = Describe("Podman restart", func() {
316322

317323
session1 = podmanTest.Podman([]string{"restart", "-a", "--filter", fmt.Sprintf("id=%swrongid", shortCid3)})
318324
session1.WaitWithDefaultTimeout()
319-
Expect(session1).Should(Exit(0))
325+
Expect(session1).Should(ExitCleanly())
320326
Expect(session1.OutputToString()).To(BeEmpty())
321327

322328
session1 = podmanTest.Podman([]string{"restart", "-a", "--filter", fmt.Sprintf("id=%s", shortCid3)})
323329
session1.WaitWithDefaultTimeout()
324-
Expect(session1).Should(Exit(0))
330+
Expect(session1).Should(ExitCleanly())
325331
Expect(session1.OutputToString()).To(BeEquivalentTo(cid3))
326332

327333
session1 = podmanTest.Podman([]string{"restart", "-a", "--filter", "label=test=with,comma"})
328334
session1.WaitWithDefaultTimeout()
329-
Expect(session1).Should(Exit(0))
335+
Expect(session1).Should(ExitCleanly())
330336
Expect(session1.OutputToString()).To(BeEquivalentTo(cid3))
331337

332338
session1 = podmanTest.Podman([]string{"restart", "-f", fmt.Sprintf("id=%s", cid2)})
333339
session1.WaitWithDefaultTimeout()
334-
Expect(session1).Should(Exit(0))
340+
Expect(session1).Should(ExitCleanly())
335341
Expect(session1.OutputToString()).To(BeEquivalentTo(cid2))
336342
})
337343
})

0 commit comments

Comments
 (0)