~subsetpark/bagatto

ref: 552690d19229a0181c4ef0ad6472c0701da3ca90 bagatto/test/threads.janet -rw-r--r-- 675 bytes
552690d1 — Zach Smith Simplify thread test 1 year, 2 months ago
                                                                                
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
(import testament :prefix "" :exit true)
(import /src/threads)

(defn dist-job
  [i]
  [i true])

(deftest distribute
  (let [jobs (seq [x :range [0 10]] [dist-job x])
        out (threads/distribute-gather jobs)]

    (is (== @{0 true 2 true 1 true 3 true 5 true
              6 true 4 true 8 true 7 true 9 true} out))))

(defn worker-initial-state [] ())

(def- work-chan (ev/thread-chan 10))

(defn do-work
  [n _state]
  (ev/give work-chan n))


(deftest pipeline
  (threads/side-effects-pipeline (range 0 10)
                                 worker-initial-state
                                 do-work)
  (ev/sleep 1)
  (is (= (ev/count work-chan) 10)))

(run-tests!)