-
-
Notifications
You must be signed in to change notification settings - Fork 133
Open
Description
I have this test namespace:
(ns memento.redis.listener2-test
(:require [clojure.test :refer :all]
[taoensso.carmine :as car]))
(defn listener [conn f]
(car/with-new-pubsub-listener conn
{"test-chan" (fn [[typ _ msg]] (when (= "message" typ) (f msg)))}
(car/subscribe "test-chan")))
(deftest listener-subscription-test
(testing "messages work"
(let [msgs (atom [])]
(with-open [l (listener {} #(swap! msgs conj %))]
(car/wcar {}
(car/publish "test-chan" [1]))
(while (empty? @msgs)
(Thread/sleep 100))
(is (= [[1]] @msgs))))))
Around 5% of the time running this test (in the same REPL, so not a new JVM for every run) it hangs (on the while statement). If I change while statement to just a sleep call, the test fails around 5% of the time instead of hanging. I was unable to figure out why that is. It is like sometimes the pub/sub system fails to deliver the message.