diff --git a/src/osc.clj b/src/osc.clj index 5d756dd..2f8bcd8 100644 --- a/src/osc.clj +++ b/src/osc.clj @@ -1,6 +1,6 @@ (ns osc (:import - (java.util.concurrent TimeUnit TimeoutException PriorityBlockingQueue) + (java.util.concurrent TimeUnit TimeoutException LinkedBlockingQueue) (java.net InetSocketAddress DatagramSocket DatagramPacket) (java.nio.channels DatagramChannel AsynchronousCloseException ClosedChannelException) (java.nio ByteBuffer ByteOrder)) @@ -152,7 +152,7 @@ (let [chan (DatagramChannel/open) rcv-buf (ByteBuffer/allocate BUFFER-SIZE) send-buf (ByteBuffer/allocate BUFFER-SIZE) - send-q (PriorityBlockingQueue. OSC-SEND-Q-SIZE (comparator (fn [a b] (< (:timestamp (second a)) (:timestamp (second b)))))) + send-q (LinkedBlockingQueue.) running? (ref true) handlers (ref {}) listeners (ref #{(msg-handler-dispatcher handlers)}) diff --git a/test/osc_test.clj b/test/osc_test.clj index d875201..9236bd3 100644 --- a/test/osc_test.clj +++ b/test/osc_test.clj @@ -61,6 +61,25 @@ (osc-close server true) (osc-close client true))))) +(deftest osc-slowpoke-server-test [] + (let [server (osc-server PORT) + client (osc-client HOST PORT) + coll (atom []) + end 50 + end-millis (+ (System/currentTimeMillis) (* end 1000 1/5))] + (try + (osc-handle server "/test" (fn [msg] (swap! coll (fn [s] + (Thread/sleep 100) + (conj s (first (:args msg))))))) + (dotimes [i end] (osc-send client "/test" i)) + (while (or (not= (count @coll) end) (< (System/currentTimeMillis) end-millis)) + (Thread/sleep 250)) + (dorun (map-indexed #(is (= %1 %2)) @coll)) + (finally + (osc-close server true) + (osc-close client true))))) + + (defn osc-tests [] (binding [*test-out* *out*] (run-tests 'osc-test))) @@ -68,4 +87,5 @@ (defn test-ns-hook [] (osc-msg-test) (thread-lifetime-test) - (osc-basic-test)) + (osc-basic-test) + (osc-slowpoke-server-test))