Skip to content

Commit 49527bd

Browse files
committed
Fix system check plugins and profile plugin edge case
1 parent d8e4ca4 commit 49527bd

File tree

5 files changed

+77
-8
lines changed

5 files changed

+77
-8
lines changed

deps.edn

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
fulcrologic/fulcro {:mvn/version "2.4.4"}
99
fulcrologic/fulcro-inspect {:mvn/version "2.0.0"}
1010
binaryage/devtools {:mvn/version "0.9.9"}
11-
org.clojure/test.check {:mvn/version "0.9.0"}
11+
org.clojure/test.check {:mvn/version "0.10.0-alpha3"}
1212
camel-snake-kebab {:mvn/version "0.4.0"}}}

project.clj

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
[org.clojure/math.combinatorics "0.1.4"]
1414
[com.wsscode/spec-inspec "1.0.0-alpha2"]
1515
[fulcrologic/fulcro "2.5.5" :scope "provided"]
16-
[org.clojure/test.check "0.9.0"]
16+
[org.clojure/test.check "0.10.0-alpha3" :scope "provided"]
1717
[camel-snake-kebab "0.4.0"]]
1818

1919
:plugins [[lein-cljsbuild "1.1.7"]]
@@ -26,4 +26,5 @@
2626

2727
:jar-exclusions [#"src-docs/.*" #"docs/.+" #"node-modules/.+"]
2828

29-
:profiles {:dev {:source-paths ["src" "src-docs"]}})
29+
:profiles {:dev {:source-paths ["src" "src-docs"]
30+
:dependencies [[criterium "0.4.4"]]}})

src/com/wsscode/pathom/core.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@
712712
plugins))
713713

714714
(defn wrap-normalize-env
715-
([parser] (wrap-normalize-env parser {}))
715+
([parser] (wrap-normalize-env parser []))
716716
([parser plugins]
717717
(fn wrap-normalize-env-internal
718718
([env tx] (wrap-normalize-env-internal env tx nil))

src/com/wsscode/pathom/profile.cljc

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
@profile*
3232
(let [start-time (current-time-ms)]
3333
(let-chan [res (reader env)]
34-
(swap! profile* update-in path append-at
35-
(- (current-time-ms) start-time))
34+
(try
35+
(swap! profile* update-in path append-at
36+
(- (current-time-ms) start-time))
37+
(catch Exception _))
3638
res)))))
3739

3840
::p/wrap-mutate

test/com/wsscode/pathom/system_test.clj

+68-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@
9292
(defn parser-test-props [env]
9393
(props/for-all [{:keys [query errors? plugins]} (->> (base-gen)
9494
(gen/fmap #(update % :query p/remove-query-wildcard)))]
95-
(let [parser (p/parser {::p/plugins plugins
95+
(let [plugins (mapv (comp deref resolve) plugins)
96+
parser (p/parser {::p/plugins plugins
9697
:mutate pt/mutate-fn})
9798

9899
async-parser (p/async-parser {::p/plugins plugins
@@ -112,6 +113,69 @@
112113
[{{::pc/keys [output]} ::pc/resolver-data} _]
113114
(pct/parser (assoc pct/parser-env ::pt/include-nils? false) output))
114115

116+
(defn profile-speed-props [env]
117+
(let [props (gen/generate (gen/vector-distinct gen/keyword-ns {:min-elements 8
118+
:max-elements 100})
119+
4)]
120+
(props/for-all [query (s.query/make-gen {::s.query/gen-property
121+
(fn [_] (gen/elements props))
122+
123+
::s.query/gen-params
124+
(fn [_] (gen/map gen/keyword gen/simple-type-printable {:max-elements 3}))}
125+
::s.query/gen-query)]
126+
(let [plugins [pp/profile-plugin]
127+
parser (p/parser {::p/plugins plugins
128+
:mutate pt/mutate-fn})
129+
130+
async-parser (p/async-parser {::p/plugins plugins
131+
:mutate pt/mutate-fn})
132+
{:keys [async-reader] :as env} env]
133+
(= (catch-run-parser parser env query)
134+
(catch-run-parser (comp <!! async-parser) (assoc env ::p/reader async-reader) query))))))
135+
136+
(test/defspec profile-speed
137+
{:max-size 16 :num-tests 30
138+
:seed 1530060220973} (profile-speed-props pct/parser-env))
139+
140+
(comment
141+
(let [props (gen/generate (gen/vector-distinct gen/keyword-ns {:min-elements 8
142+
:max-elements 100})
143+
4)
144+
query-gen (s.query/make-gen {::s.query/gen-property
145+
(fn [_] (gen/elements props))
146+
147+
::s.query/gen-params
148+
(fn [_] (gen/map gen/keyword gen/simple-type-printable {:max-elements 3}))}
149+
::s.query/gen-query)
150+
queries (take 20 (gen/sample-seq query-gen 16))]
151+
(def queries queries))
152+
153+
(let [env pct/parser-env
154+
plugins [pp/profile-plugin]
155+
parser (p/parser {::p/plugins plugins
156+
:mutate pt/mutate-fn})
157+
158+
async-parser (p/async-parser {::p/plugins plugins
159+
:mutate pt/mutate-fn})
160+
{:keys [async-reader] :as env} env]
161+
162+
(doseq [query queries]
163+
(parser env query))
164+
165+
#_
166+
(criterium/with-progress-reporting
167+
(criterium/bench
168+
(doseq [query queries]
169+
#_ (parser env query)
170+
((comp <!! async-parser) (assoc env ::p/reader async-reader) query)))))
171+
172+
(time
173+
(clojure.test/test-vars [#'profile-speed]))
174+
175+
(criterium/with-progress-reporting
176+
(criterium/bench
177+
(clojure.test/test-vars [#'profile-speed]))))
178+
115179
(defn async-resolve-fn
116180
[{{::pc/keys [output]} ::pc/resolver-data :as env} _]
117181
(if (-> env :ast :key (pt/hash-mod? 3))
@@ -194,7 +258,9 @@
194258
:query [(A {})]
195259
:type :call})
196260

197-
(let [{:keys [query plugins errors?]} {:query [#:N3Sq!.+!w?0.j+?_.lG+{:x?d? [:hP0*/dN04E]}], :errors? false, :plugins []}
261+
(let [{:keys [query plugins errors?]} {:query '[:A.?d!.!W_l.Zj/j?+y
262+
{:A.?d!.!W_l.Zj/j?+y
263+
[{:a [:foo]}]}], :errors? false, :plugins [pp/profile-plugin]}
198264
env pct/parser-env]
199265
(let [parser (p/parser {::p/plugins plugins
200266
:mutate pt/mutate-fn})

0 commit comments

Comments
 (0)