Skip to content

Commit

Permalink
Add Websocket broadcast test
Browse files Browse the repository at this point in the history
  • Loading branch information
kapilreddy committed Nov 21, 2024
1 parent aefb383 commit 88e9562
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions r_place_backend/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
:dependencies [[org.clojure/clojure "1.11.1"]
[compojure "1.7.1"]
[http-kit "2.8.0"]]
:profiles {:dev {:dependencies [[stylefruits/gniazdo "1.2.2"]]}}
:repl-options {:init-ns r-place-backend.core})
33 changes: 33 additions & 0 deletions r_place_backend/test/r_place_backend/core_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
(ns r-place-backend.core-test
(:require [clojure.test :refer :all]
[gniazdo.core :as ws]
[r-place-backend.core :refer :all]))

(deftest a-test
(testing "FIXME, I fail."
(is (= 0 1))))


(comment

;; @TODO Server setup for test
(let [b-socket (ws/connect
"ws://localhost:8080/ws"
:on-receive #(prn 'received %))
socket-xs (mapv (fn [_]
(let [a (atom nil)]
{:socket (ws/connect
"ws://localhost:8080/ws"
:on-receive #(reset! a %))
:data-received a}))
(range 10))
test-data {:column (rand-int 20)
:row (rand-int 20),
:color (rand-nth ["red" "blue" "green" "cyan"])}]
(ws/send-msg b-socket (pr-str test-data))

(ws/close b-socket)
(doseq [s (map :socket socket-xs)]
(ws/close s))

(every? (fn [x]
(= (read-string x)
["pixel" test-data]))
(map (comp deref :data-received)
socket-xs)))
;; Setup multiple connections to listen to the broadcast
;; Assert that the broadcast is successful
)

0 comments on commit 88e9562

Please sign in to comment.