Skip to content

Commit 2cf438b

Browse files
committed
fix duplicate tests into several instances
1 parent c32e37c commit 2cf438b

2 files changed

Lines changed: 35 additions & 29 deletions

File tree

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
org.clojure/tools.logging {:mvn/version "1.1.0"}
99
ch.qos.logback/logback-classic {:mvn/version "1.2.3"}
1010
clj-time/clj-time {:mvn/version "0.15.2"}
11-
github-PractiTest/firecracker-report-parser {:git/url "git@github.com:PractiTest/firecracker-report-parser.git" :deps/manifest :deps :sha "b8e5e915798995ffbfcf082d446750bcc70020a5"}
11+
github-PractiTest/firecracker-report-parser {:git/url "git@github.com:PractiTest/firecracker-report-parser.git" :deps/manifest :deps :sha "9fed1ab43b42f1b6d426925eaf159e620e793c56"}
1212
}
1313
:aliases
1414
{:dev {:extra-paths ["dev"]}

src/practitest_firecracker/practitest.clj

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,12 @@
172172
:instances {:test-ids test-ids}}}}))))
173173

174174
(defn make-instances [testset-tests]
175-
(for [[testset-id test-ids] testset-tests]
176-
(for [test-id test-ids]
177-
{:type "instances"
178-
:attributes {:set-id testset-id
179-
:test-id test-id}})))
175+
(for [[testset-id test-ids-num] testset-tests
176+
test-id-num test-ids-num
177+
index (range (last test-id-num))]
178+
{:type "instances"
179+
:attributes {:set-id testset-id
180+
:test-id (first test-id-num)}}))
180181

181182
(defn ll-create-instance [{:keys [base-uri credentials max-api-rate-throttler]} project-id testset-id test-id]
182183
;; (log/infof "create instance for testset-id %s and test-id %s" testset-id test-id)
@@ -513,16 +514,20 @@
513514
{(:id testset) (:test-list sf-test-suites)}))))
514515

515516
(defn group-tests [testsets client options]
516-
(let [testset-id-to-name (map (fn [[k v]]
517+
(let [ts-id-test-name-num-instances (into {} (map (fn [[k v]]
518+
{k
519+
(frequencies (map (fn [test] (sf-test-suite->pt-test-name options test)) v))})
520+
(into {} testsets)))
521+
testset-id-to-name (map (fn [[k v]]
517522
{k (set (map
518523
(fn [test] (sf-test-suite->pt-test-name options test)) v))})
519524
(into {} testsets))
520525
tests (flatten (map val (into {} testsets)))
521526
all-tests (doall (into {} (for [test tests]
522527
{(sf-test-suite->pt-test-name options test) test})))]
523-
[all-tests testset-id-to-name]))
528+
[all-tests testset-id-to-name ts-id-test-name-num-instances]))
524529

525-
(defn create-or-update-tests [[all-tests testset-id-to-name] client {:keys [project-id display-action-logs display-run-time] :as options} start-time]
530+
(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] :as options} start-time]
526531
(let [new-tests (into [] (group-test-names (vals all-tests) options))
527532
results (doall
528533
(flatten
@@ -553,36 +558,37 @@
553558
(update-sf-test client options test-suite (read-string (:id test)))))
554559
old-tests))
555560
(when display-run-time (print-run-time "Time - after update tests: %d:%d:%d" start-time))))
556-
[new-all-tests testset-id-to-name]))
561+
[new-all-tests testset-id-to-name ts-id-test-name-num-instances]))
557562

558-
(defn create-instances [[all-tests testset-id-to-name] client {:keys [project-id display-action-logs display-run-time] :as options} start-time]
563+
(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] :as options} start-time]
559564
(let [all-test-ids (map (fn [test] (:id (last test))) all-tests)
560565
testname-test (into {} (map (fn [test] {(first test) test}) all-tests))
561566
test-ids (string/join "," all-test-ids)
562567
testset-ids (map (fn [testset] (first (first testset))) testset-id-to-name)
563568
ts-ids (string/join "," testset-ids)
564569
instances (ll-testset-instances client [project-id display-action-logs] ts-ids test-ids)
565570

566-
ts-id-tests (into {} (map (fn [testset-id-name]
567-
{(first (first testset-id-name))
568-
(filter #(some? %)
569-
(map (fn [test-name]
570-
(get testname-test test-name))
571-
(last (last testset-id-name))))})
572-
testset-id-to-name))
573-
571+
ts-id-instance-num (into {} (map (fn [testset-id-name]
572+
{(first (first testset-id-name))
573+
(into {} (map (fn [test-name]
574+
{(read-string (:id (last (get testname-test test-name))))
575+
(get (get ts-id-test-name-num-instances (first (first testset-id-name))) test-name)})
576+
(last (last testset-id-name))))})
577+
testset-id-to-name))
574578
ts-id-instances (group-by (fn [inst] (get-in inst [:attributes :set-id])) instances)
575579

576-
missing-tests (into {}
577-
(doall
578-
(for [ts-id (into () testset-ids)]
579-
{ts-id (difference (set (map #(read-string (:id (last %))) (remove #(nil? (last %)) (get ts-id-tests ts-id))))
580-
(set (map #(get-in % [:attributes :test-id]) (get ts-id-instances (read-string ts-id)))))})))
581-
make-instances (flatten (make-instances missing-tests))
582-
test-by-id (group-by (fn [test] (read-string (:id (last test)))) all-tests)
583-
new-intstances (flatten (for [instances-part (partition-all 100 (shuffle make-instances))]
584-
(ll-create-instances client [project-id display-action-logs] instances-part)))
585-
all-intstances (into [] (concat new-intstances instances))
580+
missing-tests (into {}
581+
(doall
582+
(for [ts-id (into () testset-ids)]
583+
{ts-id (merge-with -
584+
(get ts-id-instance-num ts-id)
585+
;; (frequencies (vec (map #(read-string (:id (last %))) (remove #(nil? (last %)) (get ts-id-tests ts-id)))))
586+
(frequencies (vec (map #(get-in % [:attributes :test-id]) (get ts-id-instances (read-string ts-id))))))})))
587+
make-instances (flatten (make-instances missing-tests))
588+
test-by-id (group-by (fn [test] (read-string (:id (last test)))) all-tests)
589+
new-intstances (flatten (for [instances-part (partition-all 100 (shuffle make-instances))]
590+
(ll-create-instances client [project-id display-action-logs] instances-part)))
591+
all-intstances (into [] (concat new-intstances instances))
586592
instance-to-ts-test (group-by (fn [inst] [(:set-id (:attributes inst)) (:test-id (:attributes inst))]) all-intstances)]
587593
(when display-run-time (print-run-time "Time - after create instances: %d:%d:%d" start-time))
588594
[test-by-id instance-to-ts-test]))

0 commit comments

Comments
 (0)