test(rtc): launch two clients at the same time

This commit is contained in:
rcmerci
2024-08-29 20:14:32 +08:00
parent fa43327eff
commit 50fb730c43
10 changed files with 187 additions and 149 deletions

View File

@@ -1,93 +1,31 @@
(ns basic-edits-test
(:require [cljs.test :as t :refer [deftest is testing]]
(:require [client1-edits]
[cljs.test :as t :refer [deftest testing]]
[const]
[datascript.core :as d]
[fixture]
[frontend.worker.rtc.client-op :as client-op]
[frontend.worker.rtc.core :as rtc-core]
[frontend.worker.rtc.log-and-state :as rtc-log-and-state]
[helper]
[logseq.outliner.batch-tx :as batch-tx]
[meander.epsilon :as me]
[missionary.core :as m]))
(when (exists? js/__karma__)
(prn :config.testvar js/__karma__.config.testvar))
(t/use-fixtures :once
fixture/install-some-consts
fixture/install-example-db-fixture
fixture/clear-test-remote-graphs-fixture
fixture/build-two-conns-by-download-example-graph-fixture)
(defn- simplify-client-op
[client-op]
#_:clj-kondo/ignore
(me/find
client-op
[?op-type _ {:block-uuid ?block-uuid :av-coll [[!a !v _ !add] ...]}]
[?op-type ?block-uuid (map vector !a !v !add)]
[?op-type _ {:block-uuid ?block-uuid}]
[?op-type ?block-uuid]))
(def ^:private page-uuid1 (random-uuid))
(def ^:private block-uuid1 (random-uuid))
(def ^:private tx-data-map
{:create-page
[{:db/id "page"
:block/name "basic-edits-test"
:block/title "basic-edits-test"
:block/uuid page-uuid1
:block/created-at 1724836490809
:block/updated-at 1724836490809
:block/type "page"
:block/format :markdown}
{:block/uuid block-uuid1
:block/updated-at 1724836490810
:block/created-at 1724836490810
:block/format :markdown
:block/title "block1"
:block/parent "page"
:block/order "a0"
:block/page "page"}]})
fixture/upload-example-graph-fixture
fixture/build-conn-by-download-example-graph-fixture)
(deftest basic-edits-test
(let [conn1 (helper/get-downloaded-test-conn)]
(t/async
done
(js/Promise.
(t/async
done
(js/Promise.
(if const/is-client1?
(m/sp
(testing "create page first"
(let [tx-data (tx-data-map :create-page)]
(batch-tx/with-batch-tx-mode conn1 {:e2e-test const/downloaded-test-repo}
(d/transact! conn1 tx-data))
(is (=
#{[:update-page page-uuid1]
[:update page-uuid1
[[:block/title "[\"~#'\",\"basic-edits-test\"]" true]
[:block/created-at "[\"~#'\",1724836490809]" true]
[:block/updated-at "[\"~#'\",1724836490809]" true]
[:block/type "[\"~#'\",\"page\"]" true]]]
[:move block-uuid1]
[:update block-uuid1
[[:block/updated-at "[\"~#'\",1724836490810]" true]
[:block/created-at "[\"~#'\",1724836490810]" true]
[:block/title "[\"~#'\",\"block1\"]" true]]]}
(set (map simplify-client-op (client-op/get-all-ops const/downloaded-test-repo)))))))
(client1-edits/step1--create-page))
(testing "start rtc on repo"
(let [r (m/? (rtc-core/new-task--rtc-start const/downloaded-test-repo const/test-token))]
(is (nil? r))))
(m/? (client1-edits/step2--task-start-rtc)))
(testing "waiting for :create-page synced"
(let [r (m/? (m/timeout
(m/reduce (fn [_ v]
(when (= :rtc.log/push-local-update (:type v))
(reduced v)))
rtc-log-and-state/rtc-log-flow)
6000 :timeout))]
(is (not= :timeout r))))
(m/? (client1-edits/step3--task-wait-:create-page-synced)))
(done))
(m/sp
(testing "TODO: client2 cases")
(done))))))