|
172 | 172 | :instances {:test-ids test-ids}}}})))) |
173 | 173 |
|
174 | 174 | (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)}})) |
180 | 181 |
|
181 | 182 | (defn ll-create-instance [{:keys [base-uri credentials max-api-rate-throttler]} project-id testset-id test-id] |
182 | 183 | ;; (log/infof "create instance for testset-id %s and test-id %s" testset-id test-id) |
|
513 | 514 | {(:id testset) (:test-list sf-test-suites)})))) |
514 | 515 |
|
515 | 516 | (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]] |
517 | 522 | {k (set (map |
518 | 523 | (fn [test] (sf-test-suite->pt-test-name options test)) v))}) |
519 | 524 | (into {} testsets)) |
520 | 525 | tests (flatten (map val (into {} testsets))) |
521 | 526 | all-tests (doall (into {} (for [test tests] |
522 | 527 | {(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])) |
524 | 529 |
|
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] |
526 | 531 | (let [new-tests (into [] (group-test-names (vals all-tests) options)) |
527 | 532 | results (doall |
528 | 533 | (flatten |
|
553 | 558 | (update-sf-test client options test-suite (read-string (:id test))))) |
554 | 559 | old-tests)) |
555 | 560 | (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])) |
557 | 562 |
|
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] |
559 | 564 | (let [all-test-ids (map (fn [test] (:id (last test))) all-tests) |
560 | 565 | testname-test (into {} (map (fn [test] {(first test) test}) all-tests)) |
561 | 566 | test-ids (string/join "," all-test-ids) |
562 | 567 | testset-ids (map (fn [testset] (first (first testset))) testset-id-to-name) |
563 | 568 | ts-ids (string/join "," testset-ids) |
564 | 569 | instances (ll-testset-instances client [project-id display-action-logs] ts-ids test-ids) |
565 | 570 |
|
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)) |
574 | 578 | ts-id-instances (group-by (fn [inst] (get-in inst [:attributes :set-id])) instances) |
575 | 579 |
|
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)) |
586 | 592 | instance-to-ts-test (group-by (fn [inst] [(:set-id (:attributes inst)) (:test-id (:attributes inst))]) all-intstances)] |
587 | 593 | (when display-run-time (print-run-time "Time - after create instances: %d:%d:%d" start-time)) |
588 | 594 | [test-by-id instance-to-ts-test])) |
0 commit comments