Skip to content

Commit

Permalink
fix: --pid=host tests (#8)
Browse files Browse the repository at this point in the history
Issue #, if available:

*Description of changes:*
Fix the [GitHub issue](runfinch/finch#31) that
--pid=host test sometimes fails.
Add a spec for --test=container:<container>.
*Testing done:*
Tests passed locally.


- [x] I've reviewed the guidance in CONTRIBUTING.md


#### License Acceptance

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

Signed-off-by: Anqi Pang <[email protected]>
  • Loading branch information
AnqiPang authored Nov 30, 2022
1 parent abf1f07 commit 77342d8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,16 @@ func Run(o *option.Option) {
})

ginkgo.It("should share PID namespace with host with --pid=host", func() {
command.Run(o, "run", "-d", "--name", testContainerName, "--pid", "host", defaultImage, "sleep", "infinity")
processes := command.StdoutStr(o, "top", testContainerName)
pid := strings.Fields(processes)[9]
output := command.StdOutAsLines(o, "exec", "-d", testContainerName, "ps", "-o", "pid")
gomega.Expect(output).Should(gomega.ContainElement(pid))
command.Run(o, "run", "-d", "--name", testContainerName, "--pid=host", defaultImage, "sleep", "infinity")
pid := command.StdoutStr(o, "inspect", "--format", "{{.State.Pid}}", testContainerName)
command.Run(o, "exec", testContainerName, "sh", "-c", fmt.Sprintf("ps -o pid,comm | grep '%s sleep'", pid))
})

ginkgo.It("should share PID namespace with a container with --pid=container:<container>", func() {
command.Run(o, "run", "-d", "--name", testContainerName, defaultImage, "sleep", "infinity")
// We are joining the pid namespace that was "created" by testContainerName,
// so the pid=1 process will be the main process of testContainerName, which is `sleep`.
command.Run(o, "exec", testContainerName, "sh", "-c", "ps -o pid,comm | grep '1 sleep'")
})

ginkgo.When("running a container with network related flags", func() {
Expand Down

0 comments on commit 77342d8

Please sign in to comment.