Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Kill using -g instead of -s (#68)
Browse files Browse the repository at this point in the history
* Kill using -g instead of -s

* Add integration test for kill-process!

* feedback from dpo

* feedback from shams
  • Loading branch information
pschorf authored and shamsimam committed Jul 13, 2017
1 parent d24a632 commit 73b9f19
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
30 changes: 30 additions & 0 deletions waiter/integration/waiter/shell_scheduler_integration_test.clj
@@ -0,0 +1,30 @@
(ns waiter.shell-scheduler-integration-test
(:require [clojure.java.shell :as sh]
[clojure.string :as str]
[clojure.test :refer :all]
[waiter.shell-scheduler :refer :all]
[waiter.test-helpers :refer :all]
[waiter.utils :as utils])
(:import (java.nio.file Files
Paths)
java.nio.file.attribute.FileAttribute))

(deftest ^:parallel ^:integration-fast test-kill-process
(let [working-dir (Files/createTempDirectory nil
(make-array FileAttribute 0))
test-cmd (-> (Paths/get "test-files/test-command.sh" (make-array String 0))
.toAbsolutePath
.toString)
port->reservation-atom (atom {})
{:keys [shell-scheduler/pid] :as instance} (launch-instance "abc" working-dir test-cmd "http" {} 1
port->reservation-atom [40000 50000])]
; There are 4 processes spawned by the instance:
; 1. The wrapper process launched by the scheduler
; 2. The `test-command.sh` script
; 3/4 sleep commands forked by `test-command.sh`
(is (wait-for #(= 4 (count (str/split (:out (sh/sh "pgrep" "-g" (str pid)))
#"\n")))
:interval 1 :timeout 10))
(kill-process! instance port->reservation-atom 100)
(is (wait-for #(= "" (:out (sh/sh "pgrep" "-g" (str pid))))
:interval 1 :timeout 10))))
2 changes: 1 addition & 1 deletion waiter/src/waiter/shell_scheduler.clj
Expand Up @@ -97,7 +97,7 @@
(try
(log/info "killing process:" instance)
(.destroyForcibly process)
(sh/sh "pkill" "-9" "-s" (str pid))
(sh/sh "pkill" "-9" "-g" (str pid))
(release-port! port->reservation-atom port port-grace-period-ms)
(doseq [port extra-ports]
(release-port! port->reservation-atom port port-grace-period-ms))
Expand Down
3 changes: 3 additions & 0 deletions waiter/test-files/test-command.sh
@@ -0,0 +1,3 @@
sleep 120 &
sleep 120 &
wait

0 comments on commit 73b9f19

Please sign in to comment.