Skip to content

Instantly share code, notes, and snippets.

@jebberjeb
Created December 3, 2015 20:51
Show Gist options
  • Save jebberjeb/fbd063e36e6c2a119981 to your computer and use it in GitHub Desktop.
Save jebberjeb/fbd063e36e6c2a119981 to your computer and use it in GitHub Desktop.
Subscriptions Data Test
(deftest subscriptions-perf-test
(testing "subscriptions messages all received"
(let [broker (d/start-broker)
subs-count 10
reply-tos (repeatedly subs-count #(a/chan 1024))
group-code "foo" #_(generate-l85-uuid)
subs-str (str "group_s:" group-code)
test-record-count 10000
subs-reply-count (atom 0)]
(println "setting up subscriptions")
(doseq [r reply-tos]
(dbc/subscribe->values broker :obs subs-str :reply-to r))
(println "writing test data to riak")
(a/go (dbc/put broker :obs (repeatedly test-record-count
(fn []
{:k (generate-l85-uuid)
:group_s group-code
;; TODO - don't need rand-int.
:value_s (rand-int 1000)}))))
(println "reading subscription replies")
(time (let [total-count (atom 0)]
(doseq [r reply-tos]
(a/go-loop []
(when (a/<! r)
(swap! total-count inc)
(recur))))
;; TODO - this is bad, timeout shouldn't be arbitrary 30 seconds,
;; but based on when rate slows down, stops, etc.
(<!! (a/timeout (* 1000 30)))
@total-count))
;; TODO - show counts, times.
;; TODO - assert counts equal.
;; (clojure.test/test-vars [#'lg-databroker.put-values-test/subscriptions-perf-test])
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment