On Mar 27, 2013 1:56 AM, "Shantanu Kumar" <kumar.shant...@gmail.com> wrote: > > Sorry, in the last illustration, the (binding [*deps* deps] ...) cannot be useful for Compojure route handlers because dynamic vars are bound at a thread-local level; you will probably have to `alter-var-root` it to some var and have the handlers use that static var instead. In the code I write personally, I use a static var that I `alter-var-root` so I couldn't see the error in dynamic var immediately.
If that thread-local binding is done in a middleware, that should work fine for ring, which handles each request synchronously on a thread. (Whereas alter-var-root would be visible across threads and defeat the OP's goal of running tests concurrently.) Do note, however, that the premise of this advice, that with-redefs doesn't play nicely with concurrency, is too broadly stated. • It doesn't play nicely with running tests that mock the same vars across multiple threads. • It doesn't play nicely with running tests in one thread while running your app in another, if your app does things w/o user interaction. (This is a pain for me.) • BUT it does play nicely, more so than binding, with testing code that does work across multiple threads, for example in futures, agents, or hand-rolled threading. So if you're testing concurrent code and can stand to run just one test at a time, it allows you to avoid the verbosity of injecting all your dependencies. -hume. -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.