Skip to content

Commit d2c36fc

Browse files
authored
Merge pull request #11 from PractiTest/fix-uri-too-long
fix uri too long
2 parents 7209cde + e429ea4 commit d2c36fc

File tree

3 files changed

+55
-46
lines changed

3 files changed

+55
-46
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ pom.xml.asc
1212
.DS_Store
1313
/test-data
1414
config.json
15+
/.cpcache
16+
/.lsp/sqlite.db

deps.edn

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{:paths ["src" "test"]
2-
:deps {org.clojure/clojure {:mvn/version "1.10.3"}
3-
org.clojure/tools.cli {:mvn/version "1.0.194"}
4-
org.clojure/core.async {:mvn/version "1.2.603"}
5-
cheshire/cheshire {:mvn/version "5.10.0"}
6-
clj-http/clj-http {:mvn/version "3.12.0"}
7-
throttler/throttler {:mvn/version "1.0.0"}
8-
org.clojure/tools.logging {:mvn/version "1.1.0"}
9-
ch.qos.logback/logback-classic {:mvn/version "1.2.3"}
10-
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 "9fed1ab43b42f1b6d426925eaf159e620e793c56"}
12-
}
2+
:deps {org.clojure/clojure {:mvn/version "1.10.3"}
3+
org.clojure/tools.cli {:mvn/version "1.0.194"}
4+
org.clojure/core.async {:mvn/version "1.2.603"}
5+
cheshire/cheshire {:mvn/version "5.10.0"}
6+
clj-http/clj-http {:mvn/version "3.12.0"}
7+
throttler/throttler {:mvn/version "1.0.0"}
8+
org.clojure/tools.logging {:mvn/version "1.1.0"}
9+
ch.qos.logback/logback-classic {:mvn/version "1.2.3"}
10+
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"
12+
:deps/manifest :deps
13+
:sha "9fed1ab43b42f1b6d426925eaf159e620e793c56"}}
1314
:aliases
1415
{:dev {:extra-paths ["dev"]}
1516
:package {:extra-paths ["resources" "target/cljs/"]}
@@ -18,6 +19,4 @@
1819
:main-opts ["-m" "uberdeps.uberjar"]}
1920
:depstar {:extra-deps
2021
{seancorfield/depstar {:mvn/version "1.0.94"}}}
21-
:webassets {:extra-paths ["dev"]}
22-
}
23-
}
22+
:webassets {:extra-paths ["dev"]}}}

src/practitest_firecracker/practitest.clj

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
;; ===========================================================================
1414
;; api version
15-
(def ^:const fc-version "2.0.0")
15+
(def ^:const fc-version "2.0.2")
1616

1717
;; ===========================================================================
1818
;; utils
@@ -104,6 +104,11 @@
104104
(def ^:const list-testsets-uri "/projects/%d/sets.json")
105105
(def ^:const custom-field-uri "/projects/%d/custom_fields/%d.json")
106106

107+
;; Used when we get testset instances for multiple test ids
108+
;; It's a GET request, so if we pass too many test IDs, we get the "URL too long" error
109+
;; 50 sounds like a good compromise.
110+
111+
(def ^:const max-test-ids-bucket-size 50)
107112
;; ===========================================================================
108113
;; API
109114

@@ -130,8 +135,8 @@
130135
(api-call {:credentials credentials
131136
:uri uri
132137
:method (max-api-rate-throttler http/get)
133-
:query-params {:set-ids testset-id
134-
:test-ids test-ids}})))
138+
:query-params (cond-> {:set-ids testset-id}
139+
test-ids (assoc :test-ids test-ids))})))
135140

136141
(defn ll-test [{:keys [base-uri credentials max-api-rate-throttler]} project-id id]
137142
;; (log/infof "create step %s" id)
@@ -318,7 +323,7 @@
318323

319324
(defn testset [client project-id id]
320325
(let [testset (ll-testset client project-id id)
321-
instances (ll-testset-instances client [project-id true] id)
326+
instances (ll-testset-instances client [project-id true] id nil)
322327
tests (->> instances
323328
(map #(get-in % [:attributes :test-id]))
324329
(remove nil?)
@@ -442,7 +447,7 @@
442447
;; check that all tests exist in the given testset
443448
;; if not -- throw exception, the user will need to create another testset
444449
;; otherwise -- go on
445-
(let [instances (ll-testset-instances client [project-id display-action-logs] testset-id)
450+
(let [instances (ll-testset-instances client [project-id display-action-logs] testset-id nil)
446451
tests (map (fn [test-suite]
447452
(let [name (:name test-suite)]
448453
[name (ll-find-test client [project-id display-action-logs] name)]))
@@ -561,33 +566,36 @@
561566
[new-all-tests testset-id-to-name ts-id-test-name-num-instances]))
562567

563568
(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]
564-
(let [all-test-ids (map (fn [test] (:id (last test))) all-tests)
565-
testname-test (into {} (map (fn [test] {(first test) test}) all-tests))
566-
test-ids (string/join "," all-test-ids)
567-
testset-ids (map (fn [testset] (first (first testset))) testset-id-to-name)
568-
ts-ids (string/join "," testset-ids)
569-
instances (ll-testset-instances client [project-id display-action-logs] ts-ids test-ids)
570-
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))
578-
ts-id-instances (group-by (fn [inst] (get-in inst [:attributes :set-id])) instances)
579-
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 #(get-in % [:attributes :test-id]) (get ts-id-instances (read-string ts-id))))))})))
586-
make-instances (flatten (make-instances missing-tests))
587-
test-by-id (group-by (fn [test] (read-string (:id (last test)))) all-tests)
588-
new-intstances (flatten (for [instances-part (partition-all 100 (shuffle make-instances))]
589-
(ll-create-instances client [project-id display-action-logs] instances-part)))
590-
all-intstances (into [] (concat new-intstances instances))
569+
(let [all-test-ids (map (fn [test] (:id (last test))) all-tests)
570+
testname-test (into {} (map (fn [test] {(first test) test}) all-tests))
571+
testset-ids (map (fn [testset] (first (first testset))) testset-id-to-name)
572+
ts-ids (string/join "," testset-ids)
573+
instances (mapcat (fn [test-ids-bucket]
574+
(ll-testset-instances client
575+
[project-id display-action-logs]
576+
ts-ids
577+
(string/join "," test-ids-bucket)))
578+
(partition-all max-test-ids-bucket-size all-test-ids))
579+
ts-id-instance-num (into {} (map (fn [testset-id-name]
580+
{(first (first testset-id-name))
581+
(into {} (map (fn [test-name]
582+
{(read-string (:id (last (get testname-test test-name))))
583+
(get (get ts-id-test-name-num-instances (first (first testset-id-name))) test-name)})
584+
(last (last testset-id-name))))})
585+
testset-id-to-name))
586+
ts-id-instances (group-by (fn [inst] (get-in inst [:attributes :set-id])) instances)
587+
588+
missing-tests (into {}
589+
(doall
590+
(for [ts-id (into () testset-ids)]
591+
{ts-id (merge-with -
592+
(get ts-id-instance-num ts-id)
593+
(frequencies (vec (map #(get-in % [:attributes :test-id]) (get ts-id-instances (read-string ts-id))))))})))
594+
make-instances (flatten (make-instances missing-tests))
595+
test-by-id (group-by (fn [test] (read-string (:id (last test)))) all-tests)
596+
new-intstances (flatten (for [instances-part (partition-all 100 (shuffle make-instances))]
597+
(ll-create-instances client [project-id display-action-logs] instances-part)))
598+
all-intstances (into [] (concat new-intstances instances))
591599
instance-to-ts-test (group-by (fn [inst] [(:set-id (:attributes inst)) (:test-id (:attributes inst))]) all-intstances)]
592600
(when display-run-time (print-run-time "Time - after create instances: %d:%d:%d" start-time))
593601
[test-by-id instance-to-ts-test]))

0 commit comments

Comments
 (0)