~subsetpark/bagatto

552690d19229a0181c4ef0ad6472c0701da3ca90 — Zach Smith 1 year, 18 days ago d6e7269
Simplify thread test
1 files changed, 11 insertions(+), 10 deletions(-)

M test/threads.janet
M test/threads.janet => test/threads.janet +11 -10
@@ 5,12 5,6 @@
  [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)]


@@ 18,13 12,20 @@
    (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/*")
(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)
  # 10 + 1 placeholder file
  (is (= (length (os/dir "test/support/pool")) 11)))
  (ev/sleep 1)
  (is (= (ev/count work-chan) 10)))

(run-tests!)