summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-04-03 14:51:21 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-05-03 10:36:16 -0400
commite1443fe05d146def61a5bb882ed0aafea5730d64 (patch)
tree605dd73165073dee09af16a6348b1ee78c9030de /test
parentcafb68e301ca808392aa31fda51370593fcabbed (diff)
downloadpodman-e1443fe05d146def61a5bb882ed0aafea5730d64.tar.gz
podman-e1443fe05d146def61a5bb882ed0aafea5730d64.tar.bz2
podman-e1443fe05d146def61a5bb882ed0aafea5730d64.zip
Add a test for restart policy
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'test')
-rw-r--r--test/e2e/run_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go
index fe95db016..0c1cda0a2 100644
--- a/test/e2e/run_test.go
+++ b/test/e2e/run_test.go
@@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"strings"
+ "time"
. "github.com/containers/libpod/test/utils"
"github.com/mrunalp/fileutils"
@@ -720,4 +721,44 @@ USER mail`
Expect(session.ExitCode()).To(Equal(1))
os.Unsetenv("http_proxy")
})
+
+ It("podman run with restart-policy always restarts containers", func() {
+ podmanTest.RestoreArtifact(fedoraMinimal)
+
+ aliveFile := filepath.Join(podmanTest.RunRoot, "running")
+ file, err := os.Create(aliveFile)
+ Expect(err).To(BeNil())
+ file.Close()
+
+ session := podmanTest.Podman([]string{"run", "-dt", "--restart", "always", "-v", fmt.Sprintf("%s:/tmp/runroot", podmanTest.RunRoot), fedoraMinimal, "bash", "-c", "date +%N > /tmp/runroot/ran && while test -r /tmp/runroot/running; do sleep 0.1s; done"})
+
+ found := false
+ testFile := filepath.Join(podmanTest.RunRoot, "ran")
+ for i := 0; i < 10; i++ {
+ time.Sleep(1 * time.Second)
+ if _, err := os.Stat(testFile); err == nil {
+ found = true
+ err = os.Remove(testFile)
+ Expect(err).To(BeNil())
+ break
+ }
+ }
+ Expect(found).To(BeTrue())
+
+ err = os.Remove(aliveFile)
+ Expect(err).To(BeNil())
+
+ session.WaitWithDefaultTimeout()
+
+ // 10 seconds to restart the container
+ found = false
+ for i := 0; i < 10; i++ {
+ time.Sleep(1 * time.Second)
+ if _, err := os.Stat(testFile); err == nil {
+ found = true
+ break
+ }
+ }
+ Expect(found).To(BeTrue())
+ })
})