Skip to content

Instantly share code, notes, and snippets.

@williammartin
Last active February 13, 2019 18:46
Show Gist options
  • Save williammartin/8e510b3a1859564de44e799b4fbd231b to your computer and use it in GitHub Desktop.
Save williammartin/8e510b3a1859564de44e799b4fbd231b to your computer and use it in GitHub Desktop.
package matcher_test
import (
"os/exec"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"golang.org/x/sys/unix"
)
var _ = Describe("Pid Matcher Example", func() {
When("there is a process running", func() {
var pid int
BeforeEach(func() {
cmd := exec.Command("sleep", "10")
Expect(cmd.Start()).To(Succeed())
go func() {
Expect(cmd.Wait()).To(Succeed())
}()
pid = cmd.Process.Pid
})
It("runs for at least 5 seconds", func() {
Consistently(func() bool {
return unix.Kill(pid, unix.Signal(0)) == nil
}, time.Second*5, time.Second).Should(BeTrue())
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment