Last active
August 29, 2015 14:14
-
-
Save pbostrom/86c261730641edca5744 to your computer and use it in GitHub Desktop.
Concurrency bugs with with-redefs and deftest
This file contains hidden or 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
| ;; with-redefs | |
| ``` clojure | |
| (defn print-it [] | |
| (println "don't print this")) | |
| (defn dont-print [x] | |
| (with-redefs [print-it (constantly nil)] | |
| (print-it))) | |
| (defn -main [] | |
| (doall (pmap dont-print (range 1000))) | |
| nil) | |
| ``` | |
| ;;$ lein run | |
| ;;don't print this | |
| ;;don't print this | |
| ;;don't print this | |
| ;;don't print this | |
| ;; deftest/is | |
| (deftest test-counter-parallel | |
| (doall (pmap (fn [x] (is true)) (range 1000)))) | |
| (deftest test-counter | |
| (doall (map (fn [x] (is true)) (range 1000)))) | |
| ;;$ lein test :only pmap-bugs.core-test/test-counter-parallel | |
| ;; | |
| ;;lein test pmap-bugs.core-test | |
| ;; | |
| ;;Ran 1 tests containing 194 assertions. | |
| ;;0 failures, 0 errors. | |
| ;;$ lein test :only pmap-bugs.core-test/test-counter | |
| ;; | |
| ;;lein test pmap-bugs.core-test | |
| ;; | |
| ;;Ran 1 tests containing 1000 assertions. | |
| ;;0 failures, 0 errors. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment