浏览代码

enhance(sync): update file-sync:integration-tests

add md5 when compare local & remote files
rcmerci 3 年之前
父节点
当前提交
fe80384843
共有 2 个文件被更改,包括 15 次插入5 次删除
  1. 3 1
      bb.edn
  2. 12 4
      scripts/src/logseq/tasks/file_sync.clj

+ 3 - 1
bb.edn

@@ -8,7 +8,9 @@
   {:git/url "https://github.com/logseq/bb-tasks"
    :git/sha "4b3e623fb475cacb992425aa9dac770d6dd63e38"}
   logseq/graph-parser
-  {:local/root "deps/graph-parser"}}
+  {:local/root "deps/graph-parser"}
+  org.clj-commons/digest
+  {:mvn/version "1.4.100"}}
  :pods
  {clj-kondo/clj-kondo {:version "2022.02.09"}
   org.babashka/fswatcher {:version "0.0.3"}}

+ 12 - 4
scripts/src/logseq/tasks/file_sync.clj

@@ -12,6 +12,7 @@
             [babashka.curl :as curl]
             [clojure.data :as data]
             [clojure.test :as t :refer [deftest is]]
+            [clj-commons.digest :as digest]
             [logseq.tasks.file-sync-actions :as file-sync-actions])
   (:import (java.net URLDecoder)))
 
@@ -55,7 +56,14 @@
         body (json/parse-string (:body resp) keyword)]
     (->> body
          :Objects
-         (map (comp #(URLDecoder/decode %) fs/file-name :Key)))))
+         (map (juxt (comp #(URLDecoder/decode %) fs/file-name :Key) :checksum)))))
+
+(defn- get-local-all-files
+  [dir subdir]
+  (let [files (map fs/file (fs/list-dir (fs/file dir subdir)))
+        f (juxt fs/file-name digest/md5)]
+    (map f files)))
+
 
 (defn- api-post-get-graphs
   []
@@ -95,14 +103,14 @@
     (spit (fs/file dir file) new-content)))
 
 (defn run-action [action-map]
-  (println "==\nRUN")
+  (println "===\nRUN")
   (pp/pprint ((juxt :action #(get-in % [:args :file])) action-map))
   (println "===")
   (run-action* action-map))
 
 (defn- ensure-dir-is-synced!
   [dir graph-id subdir]
-  (let [actual (set (map fs/file-name (fs/list-dir (fs/file dir subdir))))
+  (let [actual (set (get-local-all-files dir subdir))
         expected (set (api-get-all-files graph-id subdir))]
     (assert (= actual expected)
             (let [[local-only remote-only _] (data/diff actual expected)]
@@ -163,7 +171,7 @@
     (doseq [actions partitioned-actions]
       (doseq [action actions]
         (run-action action)
-        (Thread/sleep 500))
+        (Thread/sleep 1000))
       (is (wait&files-are-in-sync? @root-dir @root-graph-id subdir)
           (str "Test " (mapv (juxt :action #(get-in % [:args :file])) actions))))))