Browse Source

test(rtc): add step6, delete-blocks case

rcmerci 1 year ago
parent
commit
b59ae21618
3 changed files with 151 additions and 4 deletions
  1. 50 2
      src/rtc_e2e_test/client_steps.cljs
  2. 73 2
      src/rtc_e2e_test/const.cljs
  3. 28 0
      src/rtc_e2e_test/helper.cljs

+ 50 - 2
src/rtc_e2e_test/client_steps.cljs

@@ -159,6 +159,7 @@
        (helper/transact! conn tx-data2)
        (is (nil? (m/? (rtc-core/new-task--rtc-start const/downloaded-test-repo const/test-token))))
        (m/? (helper/new-task--wait-all-client-ops-sent))
+       (m/? (helper/new-task--client1-sync-barrier-2->1 "step5"))
        (let [message (m/? (helper/new-task--wait-message-from-other-client
                            (fn [message] (= "move-blocks-concurrently-page-blocks" (:id message)))
                            :retry-message "move-blocks-concurrently-page-blocks"))
@@ -189,13 +190,60 @@
        (helper/transact! conn (const/tx-data-map :move-blocks-concurrently-client2))
        (is (nil? (m/? (rtc-core/new-task--rtc-start const/downloaded-test-repo const/test-token))))
        (m/? (helper/new-task--wait-all-client-ops-sent))
-       (m/? (m/sleep 5000))
+       (m/? (helper/new-task--client2-sync-barrier-2->1 "step5"))
        (m/? (helper/new-task--send-message-to-other-client
              {:id "move-blocks-concurrently-page-blocks"
               :page-blocks (ldb/get-page-blocks @conn (:db/id (d/entity @conn [:block/uuid const/page3-uuid]))
                                                 :pull-keys '[:block/uuid :block/title :block/order
                                                              {:block/parent [:block/uuid]}])}))))})
 
+(def ^:private step6
+  "Delete blocks test-1
+client1:
+- insert some blocks
+- wait to be synced
+- stop rtc
+- delete blocks
+- start rtc
+- wait to be synced
+
+client2:
+- wait blocks from client1
+- wait delete-blocks changes synced from client1
+- check block-tree"
+  {:client1
+   (m/sp
+     (let [conn (helper/get-downloaded-test-conn)
+           tx-data1 (const/tx-data-map :step6-delete-blocks-client1-1)
+           tx-data2 (const/tx-data-map :step6-delete-blocks-client1-2)]
+       (helper/transact! conn tx-data1)
+       (m/? (helper/new-task--wait-all-client-ops-sent))
+       (m/? (helper/new-task--client1-sync-barrier-1->2 "step6"))
+       (m/? helper/new-task--stop-rtc)
+       (helper/transact! conn tx-data2)
+       (let [r (m/? (rtc-core/new-task--rtc-start const/downloaded-test-repo const/test-token))]
+         (is (nil? r))
+         (m/? (helper/new-task--wait-all-client-ops-sent)))))
+   :client2
+   (m/sp
+     (let [conn (helper/get-downloaded-test-conn)]
+       (m/? (helper/new-task--client2-sync-barrier-1->2 "step6"))
+       (m/?
+        (c.m/backoff
+         (take 4 c.m/delays)
+         (m/sp
+           (let [page (d/pull @conn '[*] [:block/uuid const/step6-page-uuid])
+                 page-blocks (when-let [page-id (:db/id page)]
+                               (ldb/get-page-blocks @conn page-id
+                                                    :pull-keys '[:block/uuid {:block/parent [:block/uuid]}]))]
+             (when-not (= 1 (count page-blocks))
+               (throw (ex-info "wait delete-blocks changes synced"
+                               {:missionary/retry true
+                                :page-blocks page-blocks})))
+             (is (= {:block/uuid const/step6-block3-uuid
+                     :block/parent {:block/uuid const/step6-page-uuid}}
+                    (select-keys (first page-blocks) [:block/uuid :block/parent])))))))))})
+
 (defn- wrap-print-step-info
   [steps client]
   (map-indexed
@@ -206,7 +254,7 @@
        (helper/log "end step" idx)))
    steps))
 
-(def ^:private all-steps [step0 step1 step2 step3 step4 step5])
+(def ^:private all-steps [step0 step1 step2 step3 step4 step5 step6])
 
 (def client1-steps
   (wrap-print-step-info all-steps :client1))

+ 73 - 2
src/rtc_e2e_test/const.cljs

@@ -32,7 +32,13 @@
 (def block5-uuid #uuid "f3c48e62-1726-4492-b42a-a36f4de7b32f")
 (def block6-uuid #uuid "23f51a53-db85-465a-9f18-6ca94e59f56c")
 (def block7-uuid #uuid "83f99937-fe0a-4d33-81ce-7fe5837baad3")
-;;; -----------------------------------------
+;;; ----- delete-blocks case ---------
+(def step6-page-uuid #uuid "e22dafa5-b3b4-405d-b93d-470caa420e10")
+(def step6-block1-uuid #uuid "776acd4a-d011-4985-bfc2-14ee7bbd6a28")
+(def step6-block2-uuid #uuid "ba3998c2-8059-4f9e-9e76-2760d2f14512")
+(def step6-block3-uuid #uuid "f9ce5393-370a-43dd-a721-aaa5ef83d3ff")
+(def step6-block4-uuid #uuid "db00bb0d-2bef-49e7-96ed-b4882cdf5686")
+(def step6-block5-uuid #uuid "d34e8a9c-5e87-4511-b982-2bf2ebc82607")
 
 (def ^:large-vars/data-var tx-data-map
   {:create-page
@@ -167,4 +173,69 @@
      :block/order "a0"}
     {:block/uuid block4-uuid
      :block/parent [:block/uuid block7-uuid]
-     :block/order "a0"}]})
+     :block/order "a0"}]
+   :step6-delete-blocks-client1-1
+   ;; - 1
+   ;;   - 2
+   ;; - 3
+   ;;   - 4
+   ;;     - 5
+   [{:db/id "page"
+     :block/uuid step6-page-uuid
+     :block/name "step6-delete-blocks"
+     :block/title "step6-delete-blocks"
+     :block/created-at 1725024677501
+     :block/updated-at 1725024677501
+     :block/type "page"
+     :block/format :markdown}
+    {:db/id "b1"
+     :block/uuid step6-block1-uuid
+     :block/created-at 1725024677501
+     :block/updated-at 1725024677501
+     :block/format :markdown
+     :block/title "x1"
+     :block/parent "page"
+     :block/order "a0"
+     :block/page "page"}
+    {:db/id "b2"
+     :block/uuid step6-block2-uuid
+     :block/created-at 1725024677501
+     :block/updated-at 1725024677501
+     :block/format :markdown
+     :block/title "x2"
+     :block/parent "b1"
+     :block/order "a0"
+     :block/page "page"}
+    {:db/id "b3"
+     :block/uuid step6-block3-uuid
+     :block/created-at 1725024677501
+     :block/updated-at 1725024677501
+     :block/format :markdown
+     :block/title "x3"
+     :block/parent "page"
+     :block/order "a1"
+     :block/page "page"}
+    {:db/id "b4"
+     :block/uuid step6-block4-uuid
+     :block/created-at 1725024677501
+     :block/updated-at 1725024677501
+     :block/format :markdown
+     :block/title "x4"
+     :block/parent "b3"
+     :block/order "a0"
+     :block/page "page"}
+    {:db/id "b5"
+     :block/uuid step6-block5-uuid
+     :block/created-at 1725024677501
+     :block/updated-at 1725024677501
+     :block/format :markdown
+     :block/title "x5"
+     :block/parent "b4"
+     :block/order "a0"
+     :block/page "page"}]
+   :step6-delete-blocks-client1-2
+   ;; only block3 left
+   [[:db/retractEntity [:block/uuid step6-block1-uuid]]
+    [:db/retractEntity [:block/uuid step6-block2-uuid]]
+    [:db/retractEntity [:block/uuid step6-block4-uuid]]
+    [:db/retractEntity [:block/uuid step6-block5-uuid]]]})

+ 28 - 0
src/rtc_e2e_test/helper.cljs

@@ -155,6 +155,34 @@
          (throw (ex-info (str "wait message from other client " retry-message) {:missionary/retry true})))
        first-block-title))))
 
+(defn new-task--client1-sync-barrier-1->2
+  [message]
+  (m/sp
+    (m/? (new-task--send-message-to-other-client (str message "-client1")))
+    (m/? (new-task--wait-message-from-other-client #(= (str message "-client2") %)))
+    (log "sync-barrier-1->2" message)))
+
+(defn new-task--client2-sync-barrier-1->2
+  [message]
+  (m/sp
+    (m/? (new-task--wait-message-from-other-client #(= (str message "-client1") %)))
+    (m/? (new-task--send-message-to-other-client (str message "-client2")))
+    (log "sync-barrier-1->2" message)))
+
+(defn new-task--client1-sync-barrier-2->1
+  [message]
+  (m/sp
+    (m/? (new-task--wait-message-from-other-client #(= (str message "-client2") %)))
+    (m/? (new-task--send-message-to-other-client (str message "-client1")))
+    (log "sync-barrier-2->1" message)))
+
+(defn new-task--client2-sync-barrier-2->1
+  [message]
+  (m/sp
+    (m/? (new-task--send-message-to-other-client (str message "-client2")))
+    (m/? (new-task--wait-message-from-other-client #(= (str message "-client1") %)))
+    (log "sync-barrier-2->1" message)))
+
 (defn transact!
   [conn tx-data]
   {:pre [(seq tx-data)]}