<commit_before>(ns lambdacd.stress-test
  (:require [clojure.test :refer :all]
            [lambdacd.execution :as execution]
            [clojure.core.async :as async]
            [lambdacd.steps.control-flow :refer [in-parallel]]

            [lambdacd.steps.support :as support]
            [lambdacd.util :as util]))


(def bacon-ipsum "Bacon ipsum dolor amet meatloaf tongue flank biltong ground round. Sirloin venison sausage kielbasa andouille strip steak tri-tip. Meatloaf biltong capicola shoulder. Sausage shankle pancetta prosciutto porchetta short loin.\n\n")

(defn print-1000-lines-in-clj [args ctx]
  (support/capture-output ctx
    (doseq [i (range 1 1000)]
      (do
        (println i ")" bacon-ipsum))))
  {:status :success})

(defn done-step [args ctx]
  {:status :success})

(def pipeline-def
  `(
     (in-parallel
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj)
     done-step))

(deftest deadlock-test ; From #143, reproduces deadlock also described in #144
  (testing "should not end in a deadlock"
    (let [home-dir (util/create-temp-dir)
          config   {:home-dir             home-dir
                    :name                 "deadlock pipeline"
                    :step-updates-per-sec 10
                    :use-new-event-bus    true}
          pipeline (lambdacd.core/assemble-pipeline pipeline-def config)
          sub (lambdacd.event-bus/subscribe (:context pipeline) :step-finished)
          count-finished (atom 0)]

      (async/go-loop []
        (async/<! sub)
        (swap! count-finished inc)
        (recur))

      (is (not= :timeout
                  (deref (future
                           (execution/run (:pipeline-def pipeline) (:context pipeline)))
                         120000 :timeout)))

      (is (= 42 @count-finished)))))<commit_msg>Increase the time a stress test is allowed to take as TravisCI seems a bit slow<commit_after>(ns lambdacd.stress-test
  (:require [clojure.test :refer :all]
            [lambdacd.execution :as execution]
            [clojure.core.async :as async]
            [lambdacd.steps.control-flow :refer [in-parallel]]

            [lambdacd.steps.support :as support]
            [lambdacd.util :as util]))


(def bacon-ipsum "Bacon ipsum dolor amet meatloaf tongue flank biltong ground round. Sirloin venison sausage kielbasa andouille strip steak tri-tip. Meatloaf biltong capicola shoulder. Sausage shankle pancetta prosciutto porchetta short loin.\n\n")

(defn print-1000-lines-in-clj [args ctx]
  (support/capture-output ctx
    (doseq [i (range 1 1000)]
      (do
        (println i ")" bacon-ipsum))))
  {:status :success})

(defn done-step [args ctx]
  {:status :success})

(def pipeline-def
  `(
     (in-parallel
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj

       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj
       print-1000-lines-in-clj)
     done-step))

(deftest deadlock-test ; From #143, reproduces deadlock also described in #144
  (testing "should not end in a deadlock"
    (let [home-dir (util/create-temp-dir)
          config   {:home-dir             home-dir
                    :name                 "deadlock pipeline"
                    :step-updates-per-sec 10
                    :use-new-event-bus    true}
          pipeline (lambdacd.core/assemble-pipeline pipeline-def config)
          sub (lambdacd.event-bus/subscribe (:context pipeline) :step-finished)
          count-finished (atom 0)]

      (async/go-loop []
        (async/<! sub)
        (swap! count-finished inc)
        (recur))

      (is (not= :timeout
                  (deref (future
                           (execution/run (:pipeline-def pipeline) (:context pipeline)))
                         300000 :timeout)))

      (is (= 42 @count-finished)))))
{'fraction_non_alphanumeric': 0.11997363216875412, 'fraction_numerical': 0.061305207646671064, 'mean_word_length': 1.8573446327683616, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2250074', 'n_tokens_mistral': 2418, 'n_tokens_neox': 2069, 'n_words': 380}