Skip to content

Commit

Permalink
Merge pull request #473 from scgilardi/tweak-469-test-sentinel
Browse files Browse the repository at this point in the history
wait for all dispatched events to be processed before checking
  • Loading branch information
danielcompton authored May 29, 2018
2 parents ffe407c + 5966bde commit 719e4b2
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions test/re_frame/router_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@
(fn [db [_ i]]
(update db ::test (fnil conj []) i)))

(rf/reg-fx
::promise
(fn [{:keys [p val]}]
(deliver p val)))

(rf/reg-event-fx
::sentinel
(fn [cofx [_ p val]]
{::promise {:p p :val val}}))

(deftest dispatching-race-condition-469-test
;; Checks for Day8/re-frame#469
(is (nil? (dotimes [i 1000]
(rf/dispatch [::test i]))))
(is (= (::test @db/app-db)
(range 1000))))
(let [p (promise)]
(is (nil? (dotimes [i 1000]
(rf/dispatch [::test i]))))
(is (nil? (rf/dispatch [::sentinel p ::done])))
(let [val (deref p 1000 ::timed-out)]
(is (= ::done val)))
(is (= (::test @db/app-db)
(range 1000)))))

0 comments on commit 719e4b2

Please sign in to comment.