File: signal_handling_test.clj

package info (click to toggle)
trapperkeeper-clojure 4.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 964 kB
  • sloc: sh: 189; xml: 73; makefile: 25; java: 5
file content (34 lines) | stat: -rw-r--r-- 1,148 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(ns puppetlabs.trapperkeeper.signal-handling-test
  (:require
   [puppetlabs.trapperkeeper.core :as core]))

(defn- start-test [context get-in-config]
  (let [continue? (atom true)
        thread (future
                 (try ;; future just discards top-level exceptions
                   (while @continue?
                     (let [target (get-in-config [:signal-test-target])]
                       (assert target)
                       (Thread/sleep 200)
                       (spit target "exciting")))
                   (catch Throwable ex
                     (prn ex)
                     (throw ex))))]
    (assoc context
           :finish-signal-test
           (fn exit-signal-test []
             (reset! continue? false)
             @thread))))

(defn- stop-test [{:keys [finish-signal-test] :as context}]
  (finish-signal-test)
  context)

(defprotocol SignalHandlingTestService)

(core/defservice signal-handling-test-service
  SignalHandlingTestService
  [[:ConfigService get-in-config]]
  (init [this context] context)
  (start [this context] (start-test context get-in-config))
  (stop [this context] (stop-test context)))