~subsetpark/bagatto

ref: d6e726923195e1e7a8ac62c53ea38a5a997005ba bagatto/test/threads.janet -rw-r--r-- 723 bytes
d6e72692 — Zach Smith use deps, not lockfile 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
(import testament :prefix "" :exit true)
(import /src/threads)

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

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

(defn do-work
  [n _state]
  (spit (string "test/support/pool/" n) "ok"))

(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))))

(deftest pool
  (os/shell "rm test/support/pool/*")

  (threads/side-effects-pipeline (range 0 10)
                                 worker-initial-state
                                 do-work)
  # 10 + 1 placeholder file
  (is (= (length (os/dir "test/support/pool")) 11)))

(run-tests!)