|
12 | 12 |
|
13 | 13 | ;; =========================================================================== |
14 | 14 | ;; api version |
15 | | -(def ^:const fc-version "2.0.0") |
| 15 | +(def ^:const fc-version "2.0.2") |
16 | 16 |
|
17 | 17 | ;; =========================================================================== |
18 | 18 | ;; utils |
|
104 | 104 | (def ^:const list-testsets-uri "/projects/%d/sets.json") |
105 | 105 | (def ^:const custom-field-uri "/projects/%d/custom_fields/%d.json") |
106 | 106 |
|
| 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) |
107 | 112 | ;; =========================================================================== |
108 | 113 | ;; API |
109 | 114 |
|
|
130 | 135 | (api-call {:credentials credentials |
131 | 136 | :uri uri |
132 | 137 | :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))}))) |
135 | 140 |
|
136 | 141 | (defn ll-test [{:keys [base-uri credentials max-api-rate-throttler]} project-id id] |
137 | 142 | ;; (log/infof "create step %s" id) |
|
318 | 323 |
|
319 | 324 | (defn testset [client project-id id] |
320 | 325 | (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) |
322 | 327 | tests (->> instances |
323 | 328 | (map #(get-in % [:attributes :test-id])) |
324 | 329 | (remove nil?) |
|
442 | 447 | ;; check that all tests exist in the given testset |
443 | 448 | ;; if not -- throw exception, the user will need to create another testset |
444 | 449 | ;; 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) |
446 | 451 | tests (map (fn [test-suite] |
447 | 452 | (let [name (:name test-suite)] |
448 | 453 | [name (ll-find-test client [project-id display-action-logs] name)])) |
|
561 | 566 | [new-all-tests testset-id-to-name ts-id-test-name-num-instances])) |
562 | 567 |
|
563 | 568 | (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)) |
591 | 599 | instance-to-ts-test (group-by (fn [inst] [(:set-id (:attributes inst)) (:test-id (:attributes inst))]) all-intstances)] |
592 | 600 | (when display-run-time (print-run-time "Time - after create instances: %d:%d:%d" start-time)) |
593 | 601 | [test-by-id instance-to-ts-test])) |
0 commit comments