Last active
December 21, 2015 18:19
-
-
Save ifesdjeen/6346864 to your computer and use it in GitHub Desktop.
Testing with countdown latch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns my-test-ns | |
(:require [clojure.test :refer :all]) | |
(:import [java.util.concurrent CountDownLatch TimeUnit]) | |
(defmacro with-latch | |
[countdown-from & body] | |
`(let [latch# (CountDownLatch. ~countdown-from) | |
~'latch latch#] | |
~@body | |
(.await latch# 5 TimeUnit/SECONDS) | |
(is (= 0 (.getCount latch#))))) | |
;; Example usage: | |
(deftest with-latch-test | |
(with-latch 3 | |
(.countDown latch) | |
(.countDown latch) | |
(.countDown latch))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment