I'm curious if anyone has come up with a good strategy for testing multithreaded apps.
I do alot of testing with midje, which is great for testing functions... but I'm not really sure how to test multithreaded code without it looking really hacky:
(fact "the state is modified by a thread call"
(Thread/sleep 100)
(check-state-eq *state* nil)
(Thread/sleep 100)
(modify-state-thread-call *state* :updated-value)
(Thread/sleep 100)
(check-state-eq *state* :updated-value))
Sometimes, because of compilation time, my tests fail because a state was not updated in time, so then I have to sleep for longer. Ideally, I would want a way to write something like:
(fact "the state is modified by a thread call"
(modify-state-thread-call *state* :updated-value)
=leads-to=> (check-state-eq *state* :updated-value))
and move away from the sleeps. Are there strategies to do that?