コード例 #1
0
func killPID(pid int) {
	process, err := os.FindProcess(pid)
	if err != nil {
		return
	}
	process.Signal(syscall.SIGKILL)
	process.Release()
	Eventually(func() bool {
		return utils.IsPIDRunning(pid)
	}, COMMAND_TIMEOUT, time.Millisecond*250).Should(BeFalse())
}
コード例 #2
0
		})

		AfterEach(func() {
			Expect(os.Remove(configFile.Name())).NotTo(HaveOccurred())
		})

		testStoppingConsulProcess := func(pid int) {

			stop := exec.Command(pathToConfab,
				"stop",
				"--config-file", configFile.Name(),
			)
			Eventually(stop.Run, COMMAND_TIMEOUT, COMMAND_TIMEOUT).Should(Succeed())

			Eventually(func() bool {
				return utils.IsPIDRunning(pid)
			}, COMMAND_TIMEOUT, time.Millisecond*250).Should(BeFalse())

			Expect(fakeAgentOutputFromFile(consulConfigDir, "fake-output.json")).To(Equal(FakeAgentOutputData{
				PID: pid,
				Args: []string{
					"agent",
					fmt.Sprintf("-config-dir=%s", consulConfigDir),
					"-recursor=8.8.8.8",
					"-recursor=10.0.2.3",
				},
				LeaveCallCount: 1,
			}))

			serviceConfig, err := ioutil.ReadFile(filepath.Join(consulConfigDir, "service-cloud_controller.json"))
			Expect(err).NotTo(HaveOccurred())
コード例 #3
0
		})

		DescribeTable("when the pidfile exists",
			func(pid string, isRunning bool) {
				err := ioutil.WriteFile(pidFile.Name(), []byte(pid), os.ModePerm)
				Expect(err).NotTo(HaveOccurred())

				processIsRunning := utils.IsRunningProcess(pidFile.Name())
				Expect(processIsRunning).To(Equal(isRunning))
			},
			Entry("returns false if the process is not running", "-1", false),
			Entry("returns true if the process is running", strconv.Itoa(os.Getpid()), true),
			Entry("returns false if the pidfile contains garbage", "something-bad", false),
		)

		It("returns false if the pidfile does not exist", func() {
			processIsRunning := utils.IsRunningProcess("/nonexistent/pidfile")
			Expect(processIsRunning).To(BeFalse())
		})
	})

	DescribeTable("IsPIDRunning",
		func(pid int, expected bool) {
			isRunning := utils.IsPIDRunning(pid)
			Expect(isRunning).To(Equal(expected))
		},
		Entry("returns true when the process is running", os.Getpid(), true),
		Entry("returns false when the process is not running", -1, false),
	)
})