PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/test/riemann/test_test.clj

http://github.com/aphyr/riemann
Clojure | 55 lines | 51 code | 4 blank | 0 comment | 2 complexity | 6b090dba5fdc161cb94b21d9df3d3482 MD5 | raw file
Possible License(s): EPL-1.0
  1. (ns riemann.test-test
  2. "Who tests the testers?"
  3. (:require [riemann.streams :refer :all]
  4. [riemann.test :refer [tap io with-test-env inject! fresh-results *results* *taps*]]
  5. [riemann.time.controlled :refer :all]
  6. [clojure.test :refer :all]))
  7. (defmacro bound
  8. "Invokes body in a bound fn. Tests may run without a binding context, which
  9. breaks eval + ns."
  10. [& body]
  11. `((bound-fn [] ~@body)))
  12. (deftest only-one-tap-per-context
  13. (let [err (try
  14. (with-test-env
  15. (eval
  16. `(do (tap :foo prn)
  17. (tap :bar prn)
  18. (tap :foo nil))))
  19. (catch RuntimeException e
  20. (.getMessage e)))]
  21. (is (re-find #"Tap :foo \(.+?:\) already defined at :" err))))
  22. (deftest tap-captures-events
  23. (with-test-env
  24. (bound
  25. (eval
  26. '(do
  27. (ns riemann.test-test)
  28. (let [downstream (promise)
  29. s (rate 5 (tap :cask (partial deliver downstream)))]
  30. (with-controlled-time!
  31. (reset-time!)
  32. (binding [*results* (fresh-results @*taps*)]
  33. (is (= (inject! [s]
  34. [{:time 0 :metric 0}
  35. {:time 1 :metric 1}
  36. {:time 2 :metric 2}
  37. {:time 3 :metric 3}
  38. {:time 4 :metric 4}
  39. {:time 5 :metric 5}])
  40. {:cask [{:time 5 :metric 2}]}))
  41. (is (= @downstream {:time 5 :metric 2}))))))))))
  42. (deftest io-suppression
  43. (with-test-env
  44. (bound
  45. (eval
  46. '(do
  47. (ns riemann.test-test)
  48. (let [downstream (promise)
  49. s (sdo (io (partial deliver downstream)))]
  50. (inject! [s] [{:time 2 :metric 0}])
  51. (is (nil? (deref downstream 0 nil)))))))))