Skip to content

Commit

Permalink
fix linting errors in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tonsky committed Feb 20, 2025
1 parent 1d6286d commit c5979d5
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 75 deletions.
3 changes: 1 addition & 2 deletions server/test/instant/admin/routes_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,7 @@
first
(get "name")))))
(testing "create link attrs"
(let [pref-id (str (random-uuid))
stopa-id (-> (query-post
(let [stopa-id (-> (query-post
{:body {:query {:users {:$ {:where {:handle "stopa"}}}}}
:headers {"app-id" (str app-id)
"authorization" (str "Bearer " admin-token)}})
Expand Down
3 changes: 1 addition & 2 deletions server/test/instant/db/datalog_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
[instant.data.constants :refer [movies-app-id]]
[instant.data.resolvers :as resolvers]
[instant.jdbc.sql :as sql]
[instant.fixtures :refer [with-zeneca-app]]
[instant.db.model.attr :as attr-model]))
[instant.fixtures :refer [with-zeneca-app]]))

(def ^:private r (delay (resolvers/make-movies-resolver)))

Expand Down
8 changes: 2 additions & 6 deletions server/test/instant/db/indexing_jobs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
(= checked-data-type "number")))
order-triples))

(is (every? (fn [{:keys [triple checked-data-type]}]
(is (every? (fn [{:keys [checked-data-type]}]
(= checked-data-type "date"))
created-at-triples))

Expand Down Expand Up @@ -186,11 +186,7 @@
(with-indexing-job-queue job-queue
(with-zeneca-app-no-indexing
(fn [app r]
(let [title-triples-before (triple-model/fetch (aurora/conn-pool :read)
(:id app)
[[:= :attr-id (resolvers/->uuid r :books/title)]])

title-job (jobs/create-index-job!
(let [title-job (jobs/create-index-job!
{:app-id (:id app)
:attr-id (resolvers/->uuid r :books/title)})

Expand Down
28 changes: 10 additions & 18 deletions server/test/instant/db/instaql_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@
(deftest where-$not-$isNull-with-links-1-to-1
(with-empty-app
(fn [app]
(let [{:keys [r add-links clear-links admin-query]}
(let [{:keys [add-links admin-query]}
(add-references-to-app app
:one
:one)]
Expand Down Expand Up @@ -2040,7 +2040,7 @@
(deftest where-$not-$isNull-with-links-1-to-many
(with-empty-app
(fn [app]
(let [{:keys [r add-links clear-links admin-query]}
(let [{:keys [add-links admin-query]}
(add-references-to-app app
:one
:many)]
Expand Down Expand Up @@ -2117,7 +2117,7 @@
(deftest where-$not-$isNull-with-links-many-to-1
(with-empty-app
(fn [app]
(let [{:keys [r add-links clear-links admin-query]}
(let [{:keys [add-links admin-query]}
(add-references-to-app app
:many
:one)]
Expand Down Expand Up @@ -2194,7 +2194,7 @@
(deftest where-$not-$isNull-with-links-many-to-many
(with-empty-app
(fn [app]
(let [{:keys [r add-links clear-links admin-query]}
(let [{:keys [add-links admin-query]}
(add-references-to-app app
:many
:one)]
Expand Down Expand Up @@ -2532,11 +2532,7 @@
:app-id (:id app)
:attrs attrs}))
run-query (fn [return-field q]
(let [ctx (make-ctx)
r (resolvers/make-resolver {:conn-pool (aurora/conn-pool :read)}
(:id app)
[["books" "field"]
["authors" "field"]])]
(let [ctx (make-ctx)]
(->> (iq/permissioned-query ctx q)
(instaql-nodes->object-tree ctx)
(#(get % "etype"))
Expand Down Expand Up @@ -2677,10 +2673,10 @@
:cardinality :one}]]
(let [id (random-uuid)]
[[:add-triple id (:id attr-ids) (str id)]
[:add-triple id (:handle attr-ids) (str "a")]])
[:add-triple id (:handle attr-ids) "a"]])
(let [id (random-uuid)]
[[:add-triple id (:id attr-ids) (str id)]
[:add-triple id (:handle attr-ids) (str "b")]])))]
[:add-triple id (:handle attr-ids) "b"]])))]
(sql/select (aurora/conn-pool :write) ["ANALYZE triples"])
(testing "query on unique attr"
(let [{:keys [patterns]} (iq/instaql-query->patterns
Expand Down Expand Up @@ -2832,7 +2828,7 @@

(deftest nested-order-by
(with-zeneca-checked-data-app
(fn [app r]
(fn [app _r]
(let [ctx {:db {:conn-pool (aurora/conn-pool :read)}
:app-id (:id app)
:attrs (attr-model/get-by-app-id (:id app))}]
Expand Down Expand Up @@ -2863,7 +2859,7 @@

(deftest order-by-with-ors-and-ands
(with-zeneca-checked-data-app
(fn [app r]
(fn [app _r]
(let [ctx {:db {:conn-pool (aurora/conn-pool :read)}
:app-id (:id app)
:attrs (attr-model/get-by-app-id (:id app))}]
Expand Down Expand Up @@ -3727,11 +3723,7 @@
{:db {:conn-pool (aurora/conn-pool :read)}
:app-id (:id app)
:attrs attrs
:admin? admin?})
r (resolvers/make-resolver {:conn-pool (aurora/conn-pool :read)}
(:id app)
[["books" "field"]
["authors" "field"]])]
:admin? admin?})]
(->> (iq/permissioned-query ctx q)
(instaql-nodes->object-tree ctx))))]
(tx/transact! (aurora/conn-pool :write)
Expand Down
61 changes: 25 additions & 36 deletions server/test/instant/db/transaction_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns instant.db.transaction-test
(:require
[clojure.set :as set]
[clojure.string :as string]
[clojure.test :as test :refer [are deftest is testing]]
[instant.db.cel :as cel]
Expand All @@ -13,15 +12,13 @@
[instant.db.model.triple :as triple-model]
[instant.db.permissioned-transaction :as permissioned-tx]
[instant.db.transaction :as tx]
[instant.db.indexing-jobs :as indexing-jobs]
[instant.fixtures :refer [with-empty-app
with-zeneca-app
with-zeneca-app-no-indexing]]
[instant.jdbc.aurora :as aurora]
[instant.model.app :as app-model]
[instant.model.app-user :as app-user-model]
[instant.model.rule :as rule-model]
[instant.util.coll :as coll]
[instant.util.instaql :refer [instaql-nodes->object-tree]]
[instant.util.exception :as ex]
[instant.util.test :as test-util :refer [suid]])
Expand Down Expand Up @@ -1536,7 +1533,7 @@

(deftest new-indexed-blobs-get-nulls
(with-zeneca-app
(fn [app r]
(fn [app _r]
(let [make-ctx (fn [] {:db {:conn-pool (aurora/conn-pool :write)}
:app-id (:id app)
:attrs (attr-model/get-by-app-id (:id app))
Expand Down Expand Up @@ -2326,8 +2323,7 @@
(deftest perms-accepts-writes-to-reverse-links-to-users-table
(with-empty-app
(fn [{app-id :id}]
(let [r (resolvers/make-movies-resolver app-id)
book-id-attr-id (random-uuid)
(let [book-id-attr-id (random-uuid)
book-creator-attr-id (random-uuid)
book-id (random-uuid)
user-id (random-uuid)
Expand Down Expand Up @@ -2447,7 +2443,7 @@

(deftest auth-refs-requires-users
(with-empty-app
(fn [{app-id :id :as app}]
(fn [_app]
(testing "auth.ref requires $users namespace"
(is (= []
(rule-model/validation-errors
Expand All @@ -2461,8 +2457,7 @@
(deftest users-write-perms
(with-empty-app
(fn [{app-id :id}]
(let [r (resolvers/make-movies-resolver app-id)
book-id-attr-id (random-uuid)
(let [book-id-attr-id (random-uuid)
book-creator-attr-id (random-uuid)
book-isbn-attr-id (random-uuid)
book-title-attr-id (random-uuid)
Expand Down Expand Up @@ -2703,8 +2698,7 @@
[[:users/email :unique? :index?]
[[:users/friend :users/friend-of] :unique? :on-delete]])
ids #{(suid "1") (suid "2")}
ctx (test-util/make-ctx app-id {:rw :write})
attr-model (attr-model/get-by-app-id app-id)]
ctx (test-util/make-ctx app-id {:rw :write})]

(test-util/insert-entities
app-id attr->id
Expand All @@ -2722,24 +2716,24 @@
(fn [{app-id :id}]
(let [user-id-attr-id (random-uuid)
user-parent-attr-id (random-uuid)
insert-res (attr-model/insert-multi!
(aurora/conn-pool :write)
app-id
[{:id user-id-attr-id
:forward-identity [(random-uuid) "users" "id"]
:value-type :blob
:cardinality :one
:unique? true
:index? true}
{:id user-parent-attr-id
:forward-identity [(random-uuid) "users" "parent"]
:reverse-identity [(random-uuid) "users" "children"]
:value-type :ref
:cardinality :one
:unique? false
:index? false
:on-delete :cascade}]
{})
_ (attr-model/insert-multi!
(aurora/conn-pool :write)
app-id
[{:id user-id-attr-id
:forward-identity [(random-uuid) "users" "id"]
:value-type :blob
:cardinality :one
:unique? true
:index? true}
{:id user-parent-attr-id
:forward-identity [(random-uuid) "users" "parent"]
:reverse-identity [(random-uuid) "users" "children"]
:value-type :ref
:cardinality :one
:unique? false
:index? false
:on-delete :cascade}]
{})
root-user-id (random-uuid)
children (atom 0)]

Expand All @@ -2764,18 +2758,13 @@
(swap! children + (/ (count tx) 2))
(recur (inc i) (into #{} (map second tx))))))

(let [t0 (System/nanoTime)
ctx {:db {:conn-pool (aurora/conn-pool :write)}
(let [ctx {:db {:conn-pool (aurora/conn-pool :write)}
:app-id app-id
:attrs (attr-model/get-by-app-id app-id)
:datalog-query-fn d/query
:rules (rule-model/get-by-app-id (aurora/conn-pool :read) {:app-id app-id})
:current-user nil}
tx-steps [[:delete-entity root-user-id "users"]]
res (permissioned-tx/transact! ctx tx-steps)
dt (-> (System/nanoTime) (- t0) (/ 1000000.0))
deleted-triples (count (:delete-entity (:results res)))]
(is (= (-> @children (* 2) (+ 1)) deleted-triples))
#_(is (< dt 500)))))))
(comment
(test/run-tests *ns*))
(is (= (-> @children (* 2) (+ 1)) deleted-triples)))))))
4 changes: 2 additions & 2 deletions server/test/instant/jdbc/sql_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
(deftest in-progress-removes-itself-on-query-completion
(let [in-progress (sql/make-statement-tracker)]
(binding [sql/*in-progress-stmts* in-progress]
(let [query (sql/select (aurora/conn-pool :read) ["select 1"])]
(is (= 0 (count @(:stmts in-progress))))))))
(sql/select (aurora/conn-pool :read) ["select 1"])
(is (= 0 (count @(:stmts in-progress)))))))

(deftest cant-write-on-a-readonly-connection
(is (thrown-with-msg? clojure.lang.ExceptionInfo
Expand Down
3 changes: 1 addition & 2 deletions server/test/instant/reactive/invalidator_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns instant.reactive.invalidator-test
(:require
[clojure.core.async :as a]
[clojure.string :as string]
[clojure.test :as test :refer [deftest testing is]]
[instant.data.resolvers :as resolvers]
Expand Down Expand Up @@ -401,7 +400,7 @@
#"-"
"_")]
(with-redefs [inv/invalidate!
(fn [process-id store-conn {:keys [app-id tx-id] :as wal-record}]
(fn [process-id store-conn {:keys [app-id] :as wal-record}]
(if (and (= machine-id process-id) (= (:id app) app-id))
(swap! records conj wal-record)
(invalidate! store-conn wal-record)))]
Expand Down
11 changes: 5 additions & 6 deletions server/test/instant/reactive/session_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
[instant.db.instaql :as iq]
[instant.db.model.attr :as attr-model]
[instant.db.transaction :as tx]
[instant.flags :as flags]
[instant.fixtures :refer [with-empty-app with-movies-app]]
[instant.grouped-queue :as grouped-queue]
[instant.jdbc.aurora :as aurora]
Expand All @@ -23,7 +22,7 @@
[instant.util.async :as ua]
[instant.util.coll :as ucoll])
(:import
(com.hazelcast.core Hazelcast HazelcastInstance)
(com.hazelcast.core HazelcastInstance)
(java.util UUID)))

(test/use-fixtures :each
Expand Down Expand Up @@ -102,14 +101,14 @@
(defn read-msg [{:keys [ws-conn id]}]
(let [ret (ua/<!!-timeout ws-conn)]
(if (= :timeout ret)
(throw (ex-info "Timed out waiting for a response" {:id id})))
(dissoc ret :client-event-id)))
(throw (ex-info "Timed out waiting for a response" {:id id}))
(dissoc ret :client-event-id))))

(defn- read-msgs [n socket]
(set (repeatedly n #(read-msg socket))))

(defn- send-msg [{:keys [ws-conn id] :as socket} msg]
(session/handle-receive *store* (rs/session *store* id) msg {}))
(defn- send-msg [socket msg]
(session/handle-receive *store* (rs/session *store* (:id socket)) msg {}))

(defn- blocking-send-msg [expected-op socket msg]
(send-msg socket msg)
Expand Down
2 changes: 1 addition & 1 deletion server/test/instant/reactive/store_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
(future-cancel f1)
(is (instance? java.lang.InterruptedException (deref err 100 :timeout)))))

(dotimes [x 100]
(dotimes [_ 100]
(testing "work isn't canceled if there are still listeners"
(let [q [[:ea (random-uuid)]]
err (promise)
Expand Down

0 comments on commit c5979d5

Please sign in to comment.