Skip to content

Commit c7d6a31

Browse files
authored
Merge pull request #23 from PractiTest/PT1-179-fix-Instance-Parameters
PT1-179-fix-Instance-Parameters
2 parents d9d8c8b + 0a55b17 commit c7d6a31

3 files changed

Lines changed: 118 additions & 40 deletions

File tree

src/practitest_firecracker/api.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@
103103
:attributes attributes
104104
:instances {:test-ids test-ids}}}}))))
105105

106-
(defn make-instances [testset-tests testid-params]
106+
(defn make-instances [testset-tests testname-to-params test-id-testname]
107107
(for [[testset-id test-ids-num] testset-tests
108108
test-id-num test-ids-num
109109
index (range (last test-id-num))]
110-
{:type "instances"
111-
:attributes {:set-id testset-id
112-
:test-id (first test-id-num)
113-
:parameters (get testid-params (first test-id-num))}}))
110+
{:type "instances"
111+
:attributes {:set-id testset-id
112+
:test-id (first test-id-num)
113+
:parameters (get (get testname-to-params (get test-id-testname (first test-id-num))) index)}}))
114114

115115
(defn has-duplicates? [key runs]
116116
(let [grouped (group-by key (into [] runs))]

src/practitest_firecracker/practitest.clj

Lines changed: 108 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
(ns practitest-firecracker.practitest
22
(:require
3+
[clojure.set :refer [difference]]
34
[clojure.string :as string]
4-
[clojure.pprint :as pprint]
55
[clojure.tools.logging :as log]
66
[practitest-firecracker.utils :refer [print-run-time test-need-update? pformat]]
77
[practitest-firecracker.api :as api]
88
[practitest-firecracker.const :refer [max-test-ids-bucket-size]]
9-
[practitest-firecracker.query-dsl :refer [query? eval-query]]
10-
[practitest-firecracker.query-dsl :refer [read-query]]
9+
[practitest-firecracker.query-dsl :as query-dsl]
1110
[practitest-firecracker.eval :as eval]))
1211

1312
(defn find-sf-testset [client [project-id display-action-logs] options testset-name]
@@ -47,10 +46,10 @@
4746
{k (set (map
4847
(fn [test] (eval/sf-test-suite->pt-test-name options test)) v))})
4948
(into {} testsets))
50-
tests (flatten (map val (into {} testsets)))
51-
all-tests (doall (into {} (for [test tests]
49+
xml-tests (flatten (map val (into {} testsets)))
50+
all-tests (doall (into {} (for [test xml-tests]
5251
{(eval/sf-test-suite->pt-test-name options test) test})))]
53-
[all-tests testset-id-to-name ts-id-test-name-num-instances]))
52+
[all-tests xml-tests testset-id-to-name ts-id-test-name-num-instances]))
5453

5554
(defn value-get [existing-cases xml-cases]
5655
(conj (into [] existing-cases) (into [] xml-cases)))
@@ -73,7 +72,7 @@
7372
{:pt-test-step-name (:name attributes)
7473
:description (:description attributes)})
7574

76-
(defn create-or-update-tests [[all-tests testset-id-to-name ts-id-test-name-num-instances] client {:keys [project-id display-action-logs display-run-time use-test-step] :as options} start-time]
75+
(defn create-or-update-tests [[all-tests org-xml-tests testset-id-to-name ts-id-test-name-num-instances] client {:keys [project-id display-action-logs display-run-time use-test-step] :as options} start-time]
7776
(let [new-tests (into [] (eval/group-test-names (vals all-tests) options))
7877
results (doall
7978
(flatten
@@ -125,56 +124,83 @@
125124
(eval/update-sf-test client options test-suite test)))
126125
tests-with-steps))
127126
(when display-run-time (print-run-time "Time - after update tests: %d:%d:%d" start-time)))
128-
[new-all-tests testset-id-to-name ts-id-test-name-num-instances]))
127+
[new-all-tests org-xml-tests testset-id-to-name ts-id-test-name-num-instances]))
129128

130129
(defn split-n-filter-instance-params [test pt-instance-params]
131130
(into []
132131
(filter not-empty
133132
(string/split
134-
(eval-query
135-
(second test)
136-
(read-query pt-instance-params))
133+
(query-dsl/eval-query
134+
test
135+
(query-dsl/read-query pt-instance-params))
137136
#"\|"))))
138137

139-
(defn create-instances [[all-tests testset-id-to-name ts-id-test-name-num-instances] client {:keys [project-id display-action-logs display-run-time pt-instance-params] :as options} start-time]
138+
(defn create-instances [[all-tests org-xml-tests testset-id-to-name ts-id-test-name-num-instances] client {:keys [project-id display-action-logs display-run-time pt-instance-params] :as options} start-time]
140139
(when display-action-logs (log/infof "pt-instance-params: %s" pt-instance-params))
141140
(let [all-test-ids (map (fn [test] (:id (last test))) all-tests)
142141
testname-test (into {} (map (fn [test] {(first test) test}) all-tests))
142+
143+
test-id-testname (into {} (map (fn [test] {(query-dsl/parse-int (:id (last test))) (first test)}) all-tests))
143144
testid-params (when (not-empty pt-instance-params)
144145
(into {}
145146
(map
146147
(fn [test]
147-
(let [split-params (split-n-filter-instance-params test pt-instance-params)]
148+
(let [split-params (split-n-filter-instance-params (second test) pt-instance-params)]
148149
{(Integer/parseInt (:id (last test)))
149-
(when (even? (count split-params))
150-
(apply array-map
151-
(split-n-filter-instance-params test pt-instance-params)))}))
150+
(zipmap (iterate inc 1) split-params)}))
152151
all-tests)))
152+
153153
log (when display-action-logs (log/infof "testid-params: %s" testid-params))
154+
154155
testset-ids (map (fn [testset] (first (first testset))) testset-id-to-name)
156+
155157
ts-ids (string/join "," testset-ids)
158+
156159
instances (mapcat (fn [test-ids-bucket]
157160
(api/ll-testset-instances client
158161
[project-id display-action-logs]
159162
ts-ids
160163
(string/join "," test-ids-bucket)))
161164
(partition-all max-test-ids-bucket-size all-test-ids))
165+
166+
testname-to-params (when (not-empty pt-instance-params)
167+
(into {}
168+
(map
169+
(fn [[key tests]]
170+
{key
171+
(into []
172+
(map
173+
(fn [test]
174+
(zipmap
175+
(iterate inc 1)
176+
(split-n-filter-instance-params test pt-instance-params))) tests))})
177+
(group-by
178+
#(eval/sf-test-suite->pt-test-name options %)
179+
org-xml-tests))))
180+
181+
testname-test2 (when
182+
(not-empty pt-instance-params)
183+
(into
184+
#{}
185+
(map
186+
(fn [test]
187+
(str
188+
(eval/sf-test-suite->pt-test-name options test) ":"
189+
(split-n-filter-instance-params test pt-instance-params)))
190+
org-xml-tests)))
191+
162192
filter-instances (if (not-empty pt-instance-params)
163193
(filter
164194
(fn [instance]
165195
(let
166196
[{:keys [name bdd-parameters parameters]} (:attributes instance)
167-
[_ xml-test test] (get testname-test name)
168-
split-params (split-n-filter-instance-params test pt-instance-params)
169-
xml-params (into {} (map (fn [[key value]] {(keyword key) value})
170-
(when (even? (count split-params))
171-
(apply array-map split-params))))
172-
test-type (:test-type (:attributes test))
173-
params (if (= test-type "BDDTest") bdd-parameters parameters)]
174-
(= xml-params params)))
197+
obj-test (get testname-test name)
198+
test-type (:test-type (:attributes (last obj-test)))
199+
params (if (= test-type "BDDTest") bdd-parameters parameters)
200+
vals (into [] (if (map? params) (vals params) params))]
201+
(contains? testname-test2 (str name ":" vals))))
175202
instances)
176203
instances)
177-
log (when display-action-logs (do (log/infof "filter-instances: ") (pprint/pprint filter-instances)))
178204

179205
ts-id-instance-num (into {} (map (fn [testset-id-name]
180206
{(first (first testset-id-name))
@@ -186,17 +212,69 @@
186212
(last (last testset-id-name))))})
187213
testset-id-to-name))
188214
ts-id-instances (group-by (fn [inst] (get-in inst [:attributes :set-id])) filter-instances)
215+
189216
missing-instances (into {}
190217
(doall
191218
(for [ts-id (into () testset-ids)]
192-
{ts-id (merge-with -
193-
(get ts-id-instance-num ts-id)
194-
(frequencies (vec (map #(get-in % [:attributes :test-id]) (get ts-id-instances (read-string ts-id))))))})))
195-
make-instances (flatten (api/make-instances missing-instances testid-params))
219+
{ts-id
220+
(merge-with -
221+
(get ts-id-instance-num ts-id)
222+
(frequencies (vec (map #(get-in % [:attributes :test-id])
223+
(get ts-id-instances (read-string ts-id))))))})))
224+
225+
existing-instance (when (not-empty pt-instance-params)
226+
(into {}
227+
(map
228+
(fn [[key tests]]
229+
{key
230+
(into []
231+
(map
232+
(fn [test]
233+
(get-in test [:attributes :parameters])) tests))})
234+
(group-by
235+
(fn [inst]
236+
(get-in inst [:attributes :name]))
237+
filter-instances))))
238+
239+
new-map (into {}
240+
(map
241+
(fn [test-name]
242+
(reduce (fn [a b]
243+
(if (= (keys a) (keys b))
244+
{(first (keys a))
245+
(into [] (conj
246+
(if (vector? (first (vals a)))
247+
(first (vals a))
248+
(into [] (vals a)))
249+
(first (vals b))))}
250+
(conj a b)))
251+
{}
252+
(map (fn [x]
253+
{test-name
254+
(into {}
255+
(map (fn [y]
256+
{(keyword (str (first y)))
257+
(last y)})
258+
x))})
259+
(get testname-to-params test-name))))
260+
(keys testname-to-params)))
261+
262+
new-testname-to-params (into {}
263+
(map
264+
(fn [test-name]
265+
{test-name
266+
[(into {} (difference (set (get new-map test-name)) (set (get existing-instance test-name))))]})
267+
(keys new-map)))
268+
269+
make-instances (flatten (api/make-instances missing-instances new-testname-to-params test-id-testname))
196270
test-by-id (group-by (fn [test] (read-string (:id (last test)))) all-tests)
197271
new-intstances (flatten (for [instances-part (partition-all 100 (shuffle make-instances))]
198272
(api/ll-create-instances client [project-id display-action-logs] instances-part)))
199-
all-intstances (into [] (concat new-intstances instances))
273+
all-intstances (into [] (concat new-intstances (if
274+
(not-empty pt-instance-params)
275+
filter-instances
276+
instances)))
277+
200278
instance-to-ts-test (group-by (fn [inst] [(:set-id (:attributes inst)) (:test-id (:attributes inst))]) all-intstances)]
201279
(when display-run-time (print-run-time "Time - after create instances: %d:%d:%d" start-time))
202280
[test-by-id instance-to-ts-test]))

src/practitest_firecracker/query_dsl.cljc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@
7171
(return-error "Syntax error: 'join' argument has to be ISeqable (String, Array etc.)" query))
7272
(return-error "Syntax error: 'join' must have one argument" query))
7373
'split (if (= 2 (count args))
74-
(let [quoted #?(:clj (string/escape (first args) char-escape-string)
75-
:cljs (first args))
76-
complied #?(:clj (java.util.regex.Pattern/compile quoted)
77-
:cljs (js/RegExp. quoted))]
78-
(string/split (second args) complied))
74+
(if (empty? (last args))
75+
(last args)
76+
(let [complied #?(:clj (java.util.regex.Pattern/compile (first args))
77+
:cljs (js/RegExp. (first args)))]
78+
(string/split (second args) complied)))
7979
(return-error "Syntax error: 'split' must have two arguments" query))
8080
'get (if (= 2 (count args))
8181
(first (take 1 (drop (- (parse-int (first args)) 1) (last args))))

0 commit comments

Comments
 (0)