diff --git a/src/main/frontend/worker/sync.cljs b/src/main/frontend/worker/sync.cljs index 12a4e68066..480535c9f5 100644 --- a/src/main/frontend/worker/sync.cljs +++ b/src/main/frontend/worker/sync.cljs @@ -273,10 +273,8 @@ [client repo graph-id] (when (and client (= repo (:repo client)) (= graph-id (:graph-id client))) (let [ws (:ws client) - ws-state (some-> (:ws-state client) deref) ws-ready-state (when ws (ready-state ws))] - (or (= :open ws-state) - (contains? #{0 1} ws-ready-state))))) + (contains? #{0 1} ws-ready-state)))) (defn- connect! [repo client url token] diff --git a/src/test/frontend/worker/sync/restart_test.cljs b/src/test/frontend/worker/sync/restart_test.cljs new file mode 100644 index 0000000000..caf7880370 --- /dev/null +++ b/src/test/frontend/worker/sync/restart_test.cljs @@ -0,0 +1,60 @@ +(ns frontend.worker.sync.restart-test + (:require [cljs.test :refer [async deftest is]] + [frontend.worker.platform :as platform] + [frontend.worker.shared-service :as shared-service] + [frontend.worker.state :as worker-state] + [frontend.worker.sync :as sync] + [frontend.worker.sync.util :as sync-util] + [promesa.core :as p])) + +(deftest start-reconnects-closed-ws-with-stale-open-state-test + (async done + (let [repo "stale-repo" + graph-id "graph-1" + prev-client @worker-state/*db-sync-client + prev-config @worker-state/*db-sync-config + prev-platform (try + (platform/current) + (catch :default _ nil)) + connect-calls (atom 0) + stale-ws #js {:readyState 3 + :close (fn [] nil)} + stale-client {:repo repo + :graph-id graph-id + :ws stale-ws + :ws-state (atom :open) + :online-users (atom []) + :reconnect (atom {:attempt 0 :timer nil}) + :stale-kill-timer (atom nil)}] + (reset! worker-state/*db-sync-config {:ws-url "wss://sync.example.test/sync/%s"}) + (reset! worker-state/*db-sync-client stale-client) + (platform/set-platform! + {:env {:runtime :node} + :storage {} + :kv {} + :broadcast {} + :websocket {:connect (fn [_url] + (swap! connect-calls inc) + #js {:readyState 0 + :close (fn [] nil)})} + :crypto {} + :timers {} + :sqlite {}}) + (-> (p/with-redefs [sync-util/get-graph-id (fn [_repo] graph-id) + sync/