PageRenderTime 31ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/test/lamina/test/trace.clj

https://github.com/ogf/lamina
Clojure | 66 lines | 53 code | 6 blank | 7 comment | 6 complexity | 301be98bde0d025bbd36e6029cd0f925 MD5 | raw file
  1. ;; Copyright (c) Zachary Tellman. All rights reserved.
  2. ;; The use and distribution terms for this software are covered by the
  3. ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
  4. ;; which can be found in the file epl-v10.html at the root of this distribution.
  5. ;; By using this software in any fashion, you are agreeing to be bound by
  6. ;; the terms of this license.
  7. ;; You must not remove this notice, or any other, from this software.
  8. (ns lamina.test.trace
  9. (:use
  10. [lamina core trace]
  11. [lamina.trace.core :only (probe-channels probe-switches)]
  12. [clojure test]))
  13. (defn clear-probe-channels []
  14. (dosync
  15. (ref-set probe-channels {})
  16. (reset! probe-switches {})))
  17. (deftest test-trace
  18. (clear-probe-channels)
  19. (let [marker (atom false)
  20. probe :foo]
  21. (trace probe (reset! marker true))
  22. (is (not @marker))
  23. (receive-all (probe-channel probe) (fn [_] ))
  24. (trace probe (reset! marker true))
  25. (is @marker))
  26. (eval
  27. `(let [marker# (atom false)]
  28. (trace :bar (reset! marker# true))
  29. (is (not @marker#))
  30. (receive-all (probe-channel :bar) (fn [_#] ))
  31. (trace :bar (reset! marker# true))
  32. (is @marker#))))
  33. (deftest test-trace->>
  34. (clear-probe-channels)
  35. (let [marker (atom nil)
  36. ch (channel)]
  37. (receive-all ch #(reset! marker %))
  38. (enqueue
  39. (trace->> :trace (map* inc) [ch])
  40. 1)
  41. (is (nil? @marker)))
  42. (let [marker (atom nil)
  43. trace-marker (atom nil)
  44. ch (channel)]
  45. (receive-all ch #(reset! marker %))
  46. (receive-all (probe-channel :trace) #(reset! trace-marker %))
  47. (enqueue
  48. (trace->> :trace (map* inc) [ch])
  49. 1)
  50. (is (= 2 @marker))
  51. (is (= 2 @trace-marker)))
  52. (let [a-marker (atom nil)
  53. a-b-marker (atom nil)]
  54. (receive-all (probe-channel :a) #(reset! a-marker %))
  55. (receive-all (probe-channel :a:b) #(reset! a-b-marker %))
  56. (enqueue
  57. (trace->> :a (map* inc) [(trace->> :b (map* inc))])
  58. 1)
  59. (is (= 2 @a-marker))
  60. (is (= 3 @a-b-marker))))