blob: 500bd9f753da9eb93ce59ca61b6e6d9ff6281b43 (
plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
(ns weepinbell.processor-starter-test
(:require [clojure.test :refer [deftest testing is]]
[clojure.core.async :refer [chan put! poll!]]
[weepinbell.processor.facade :refer [start-processor]]))
(defn- test-processor
([test-wmc received?]
(test-processor test-wmc received? 1 nil))
([test-wmc received? concurrency]
(test-processor test-wmc received? concurrency nil))
([test-wmc received? concurrency on-receive]
(let [pmeta {:wmc test-wmc
:callbacks {:on-receive (or on-receive
(fn [_] (put! received? true)))
:on-create (fn [_])
:on-delete (fn [_])
:on-update (fn [_])}
:storage {:get (fn [& _])
:delete (fn [& _])
:append (fn [& _])
:update (fn [& _])
:get-by-domain (fn [& _])}
:config {:base-url "https://test.com"
:allowed-target-domains ["test.com"]
:pipeline-concurrency concurrency}}]
(start-processor pmeta))))
(deftest start-processor-test
(testing "processor starting and taking webmention"
(let [test-wmc (chan), received? (chan)
shutdown (test-processor test-wmc received?)]
(put! test-wmc {:s "s" :t "t"})
(Thread/sleep 50)
(is (poll! received?))
(shutdown)))
(testing "graceful shutdown, should not take webmention after shutdown"
(let [test-wmc (chan), received? (chan)
shutdown (test-processor test-wmc received?)]
(shutdown)
(put! test-wmc {:s "s" :t "t"})
(Thread/sleep 50)
(is (nil? (poll! received?))))))
(deftest concurrent-processor-test
(testing "processor processing all webmentions before shutting down"
(let [test-wmc (chan), received? (chan)
concurrency 3
shutdown (test-processor test-wmc received? 3)]
(is (fn? shutdown))
(dotimes [_ concurrency] (put! test-wmc {:s "s" :t "t"}))
(shutdown)
(Thread/sleep 50)
(dotimes [_ concurrency] (is (poll! received?)))))
(testing "processor still works if Exceptions were thrown"
(let [test-wmc (chan), received? (chan), fail-once (chan)]
(put! fail-once true)
(let [on-receive (fn [_]
;; throw Exception at the first call
(if (poll! fail-once)
(throw (Exception.))
(put! received? true)))
concurrency 5
shutdown (test-processor test-wmc received? concurrency on-receive)]
(dotimes [_ concurrency] (put! test-wmc {:s "s" :t "t"}))
(Thread/sleep 50)
(dotimes [_ (- concurrency 1)] (is (poll! received?)))
(shutdown)))))
|