Re: tests involving threads
On Jul 6, 5:52 am, Jarkko Oranen wrote: > My guess is that having 'is inside a future messes up the per- > thread bindings that clojure.test uses. Yes, this doesn't work because the future fn is executed in a new thread, that does not inherit the dynamic context in which the future was created. clojure.test uses dynamic bindings for counting the number of tests/assertions. So yes, the answer is to do all your assertions in the test body, not in other threads. I hope this is a special case that won't be a problem too often, since I don't see any way around it. -Stuart Sierra --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: tests involving threads
Thanks for the reply Jarkko, Yes I can work around it. The scenario is that I want to see a message correctly passed: http://github.com/timothypratley/strive/blob/cef5a3a9ea18159f866fe6c94603b704daba1ba8/clj/timothypratley/test-messenger.clj It is useful (tempting?) in this case to be able to check something on a thread, but I can save the value and check it later to avoid doing so. Regarding futures not raising exceptions, this is actually completely independent of test. From experimentation, exceptions on futures are only reported if the future is @ examined (presumably by design). So I think my options are to wrap long running futures in a try/catch/ report or use a normal Thread. Regards Tim. On Jul 6, 7:52 pm, Jarkko Oranen wrote: > On Jul 6, 7:51 am, Timothy Pratley wrote: > > > > > Very glad that test is now part of clojure core. > > > I've run into 2 strange behaviours when trying to write tests where > > threads are involved. My case is a little complex so here is a minimal > > version which shows what I mean: > > > test-test.clj: > > (ns test-test > > (:use clojure.test)) > > > (deftest testathon > > (let [f1 (future (is (= 1 2))) > > f2 (future (future (/ 1 0)))] > > @f1 > > @f2)) > > > (run-tests) > > (shutdown-agents) > > > $ clj test-test.clj > > > Testing test-test > > > FAIL in clojure.lang.persistentlist$emptyl...@1 (test-test.clj:5) > > expected: (= 1 2) > > actual: (not (= 1 2)) > > > Ran 1 tests containing 0 assertions. > > 0 failures, 0 errors. > > > f1 failed, and a FAIL message is printed, but the end report indicates > > 0 failures. > > f2 raised an exception silently. > > > I guess I'm just not "doing it right"! > > Are you sure you don't want to test something like > (let [v (future (+ 1 2))] > (is (= @v 3))) > instead? My guess is that having 'is inside a future messes up the per- > thread bindings that clojure.test uses. I don't know if there's a way > around that, but also doubt assertions inside futures are really > useful. > > > Regards, > > Tim. > > -- > Jarkko --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: tests involving threads
On Jul 6, 7:51 am, Timothy Pratley wrote: > Very glad that test is now part of clojure core. > > I've run into 2 strange behaviours when trying to write tests where > threads are involved. My case is a little complex so here is a minimal > version which shows what I mean: > > test-test.clj: > (ns test-test > (:use clojure.test)) > > (deftest testathon > (let [f1 (future (is (= 1 2))) > f2 (future (future (/ 1 0)))] > @f1 > @f2)) > > (run-tests) > (shutdown-agents) > > $ clj test-test.clj > > Testing test-test > > FAIL in clojure.lang.persistentlist$emptyl...@1 (test-test.clj:5) > expected: (= 1 2) > actual: (not (= 1 2)) > > Ran 1 tests containing 0 assertions. > 0 failures, 0 errors. > > f1 failed, and a FAIL message is printed, but the end report indicates > 0 failures. > f2 raised an exception silently. > > I guess I'm just not "doing it right"! > Are you sure you don't want to test something like (let [v (future (+ 1 2))] (is (= @v 3))) instead? My guess is that having 'is inside a future messes up the per- thread bindings that clojure.test uses. I don't know if there's a way around that, but also doubt assertions inside futures are really useful. > Regards, > Tim. -- Jarkko --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
tests involving threads
Very glad that test is now part of clojure core. I've run into 2 strange behaviours when trying to write tests where threads are involved. My case is a little complex so here is a minimal version which shows what I mean: test-test.clj: (ns test-test (:use clojure.test)) (deftest testathon (let [f1 (future (is (= 1 2))) f2 (future (future (/ 1 0)))] @f1 @f2)) (run-tests) (shutdown-agents) $ clj test-test.clj Testing test-test FAIL in clojure.lang.persistentlist$emptyl...@1 (test-test.clj:5) expected: (= 1 2) actual: (not (= 1 2)) Ran 1 tests containing 0 assertions. 0 failures, 0 errors. f1 failed, and a FAIL message is printed, but the end report indicates 0 failures. f2 raised an exception silently. I guess I'm just not "doing it right"! Regards, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---