Remove obsolete code
This commit is contained in:
parent
2f56caec28
commit
3b4d7a6a62
|
@ -23,7 +23,6 @@
|
|||
status-im.chat.events.commands
|
||||
status-im.chat.events.requests
|
||||
status-im.chat.events.send-message
|
||||
status-im.chat.events.queue-message
|
||||
status-im.chat.events.receive-message
|
||||
status-im.chat.events.console
|
||||
status-im.chat.events.webview-bridge))
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
(ns status-im.chat.events.queue-message
|
||||
(:require [cljs.core.async :as async]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.pre-receiver :as pre-receiver]
|
||||
[status-im.utils.handlers :as handlers]))
|
||||
|
||||
;; We queue messaged before receiving them to allow lagging messages to catch up.
|
||||
;; This ensures proper ordering from a user's POV the vast majority of the time.
|
||||
|
||||
;; XXX(oskarth): Hacky def, consider better encapsulation
|
||||
(when config/queue-message-enabled?
|
||||
(def in-ch (pre-receiver/start!
|
||||
{:delay-ms 500
|
||||
:reorder? true
|
||||
:add-fn #(re-frame/dispatch [:chat-received-message/add %])})))
|
||||
|
||||
;; NOTE(oskarth): in-ch is assumed to exist
|
||||
(re-frame/reg-fx
|
||||
::queue-message
|
||||
(fn [message]
|
||||
(async/put! in-ch message)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:pre-received-message
|
||||
(fn [_ [_ message]]
|
||||
(if config/queue-message-enabled?
|
||||
{::queue-message message}
|
||||
{:dispatch [:chat-received-message/add message]})))
|
|
@ -1,41 +0,0 @@
|
|||
(ns status-im.utils.pre-receiver
|
||||
(:require [cljs.core.async :as async]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.utils.async :as async-utils]))
|
||||
|
||||
;; See status-im.test.utils.pre-receiver for justification.
|
||||
|
||||
(defn- add-message-mock [{:keys [id clock-value] :as msg}]
|
||||
(log/debug "add-message-mock:" id clock-value))
|
||||
|
||||
(defn- earliest-clock-value-seen? [seen id clock-value]
|
||||
(->> seen
|
||||
(filter (fn [[_ x]] (= x id)))
|
||||
sort
|
||||
ffirst
|
||||
(= clock-value)))
|
||||
|
||||
(defn start!
|
||||
"Starts a pre-receiver that returns channel to put messages on. Once
|
||||
'delay-ms' (default 50ms) time has passed, calls add-fn on message."
|
||||
[& [{:keys [delay-ms reorder? add-fn]
|
||||
:or {delay-ms 50 reorder? true add-fn add-message-mock}}]]
|
||||
(let [in-ch (async/chan)
|
||||
mature-ch (async/chan)
|
||||
seen (atom #{})]
|
||||
(async/go-loop []
|
||||
(let [{:keys [message-id clock-value] :as msg} (async/<! in-ch)]
|
||||
(swap! seen conj [clock-value message-id])
|
||||
(async/<! (async-utils/timeout delay-ms))
|
||||
(async/put! mature-ch msg))
|
||||
(recur))
|
||||
(async/go-loop []
|
||||
(let [{:keys [message-id clock-value] :as msg} (async/<! mature-ch)]
|
||||
(if reorder?
|
||||
(if (earliest-clock-value-seen? @seen message-id clock-value)
|
||||
(do (swap! seen disj [clock-value message-id])
|
||||
(add-fn msg))
|
||||
(async/put! mature-ch msg))
|
||||
(add-fn msg)))
|
||||
(recur))
|
||||
in-ch))
|
|
@ -18,7 +18,6 @@
|
|||
[status-im.test.utils.utils]
|
||||
[status-im.test.utils.money]
|
||||
[status-im.test.utils.clocks]
|
||||
[status-im.test.utils.pre-receiver]
|
||||
[status-im.test.utils.ethereum.eip681]
|
||||
[status-im.test.utils.ethereum.core]
|
||||
[status-im.test.utils.random]
|
||||
|
@ -57,7 +56,6 @@
|
|||
'status-im.test.utils.utils
|
||||
'status-im.test.utils.money
|
||||
'status-im.test.utils.clocks
|
||||
'status-im.test.utils.pre-receiver
|
||||
'status-im.test.utils.ethereum.eip681
|
||||
'status-im.test.utils.ethereum.core
|
||||
'status-im.test.utils.random
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
(ns status-im.test.utils.pre-receiver
|
||||
(:require [cljs.test :refer-macros [deftest is testing async]]
|
||||
[cljs.core.async :as async]
|
||||
[status-im.utils.pre-receiver :as pre-receiver]))
|
||||
|
||||
;; The tests in clocks.cljs only ensure that the local clock value is respected
|
||||
;; and that new messages are always appended correctly so we get a locally
|
||||
;; consistent view.
|
||||
|
||||
;; Additionally, a desirable property to have is that two people talking to each
|
||||
;; other have roughly the same ordering of messages. Example:
|
||||
|
||||
;; A and B are different chats with different chat identifiers. The sent
|
||||
;; clock-value represents that client's truth, but The Network (Whisper, etc)
|
||||
;; doesn't guarantee _delivery_ order. This means a client can receive the
|
||||
;; messages in the following ordering.
|
||||
(def messages [{:id "a" :clock-value 1 :payload "a1"}
|
||||
{:id "a" :clock-value 2 :payload "a2"}
|
||||
{:id "b" :clock-value 1 :payload "b1"}
|
||||
{:id "a" :clock-value 4 :payload "a4"}
|
||||
{:id "a" :clock-value 3 :payload "a3"}
|
||||
{:id "b" :clock-value 2 :payload "b2"}])
|
||||
|
||||
;; Empirically speaking, "a4" arriving before "a3" happens when messages are
|
||||
;; sent in quick succession, but the delay between these being delivered is
|
||||
;; usually very small, i.e. <100ms.
|
||||
|
||||
;; Given this delivery order, we have a design decision to make. We can either
|
||||
;; eagerly "commit" them, and thus update our local clock value to reflect the
|
||||
;; order we see messages in. Alternatively, we can pause the commit/full receive
|
||||
;; step and wait for some time for logically earlier messages arrive.
|
||||
|
||||
;; In 0.9.12 and earlier this is the behavior we had the former behavior, but
|
||||
;; this breaks users expectation. The tests below showcases the latter behavior,
|
||||
;; which can be turned on with a flag.
|
||||
|
||||
;; Invariant to maintain
|
||||
(defn monotonic-increase? [received id clock-value]
|
||||
(->> received
|
||||
(filter (fn [[_ x]] (= x id)))
|
||||
sort
|
||||
last
|
||||
first
|
||||
((fn [v] (or (nil? v) (> clock-value v))))))
|
||||
|
||||
(defn add-message-test [received invariant? {:keys [id clock-value] :as msg}]
|
||||
(when (not (monotonic-increase? @received id clock-value))
|
||||
(println "add-message-test NOT earliest clock value seen!")
|
||||
(println "add-message-test received:" (pr-str @received))
|
||||
(println "add-message-test new:" id clock-value)
|
||||
(is (not invariant?)))
|
||||
(swap! received conj [clock-value id]))
|
||||
|
||||
(defn simulate! [{:keys [reorder? invariant? done]}]
|
||||
(let [delay-ms 50
|
||||
received (atom #{})
|
||||
add-fn (partial add-message-test received invariant?)
|
||||
in-ch (pre-receiver/start! {:delay-ms delay-ms
|
||||
:reorder? reorder?
|
||||
:add-fn add-fn})]
|
||||
|
||||
(doseq [msg messages]
|
||||
(async/put! in-ch msg))
|
||||
|
||||
(async/go (async/<! (async/timeout (* delay-ms 2)))
|
||||
(let [total (count messages)
|
||||
poss (count @received)]
|
||||
;;(println "received" poss "/" total "messages")
|
||||
(reset! received #{})
|
||||
(done)))))
|
||||
|
||||
(deftest pre-receiver
|
||||
(testing "Pre-receiver with reorder - good case"
|
||||
(async done
|
||||
(simulate! {:reorder? true :invariant? true :done done})))
|
||||
|
||||
;; By setting invariant? to true this test will fail
|
||||
(testing "Pre-receiver without reorder - bad case"
|
||||
(async done
|
||||
(simulate! {:reorder? false :invariant? false :done done}))))
|
Loading…
Reference in New Issue