diff --git a/src/malli/generator.cljc b/src/malli/generator.cljc index 407890bd4..750b980d5 100644 --- a/src/malli/generator.cljc +++ b/src/malli/generator.cljc @@ -305,7 +305,8 @@ dschema (m/deref schema)] (cond->> (generator dschema (assoc-in options [::rec-gen ref-id] scalar-ref-gen)) (realized? scalar-ref-gen) (gen/recursive-gen - #(generator dschema (assoc-in options [::rec-gen ref-id] %)))))))) + #(do #?(:clj (when (Thread/interrupted) (throw (InterruptedException.)))) + (generator dschema (assoc-in options [::rec-gen ref-id] %))))))))) (defn -=>-gen [schema options] (let [output-generator (generator (:output (m/-function-info schema)) options)] diff --git a/test/malli/generator_test.cljc b/test/malli/generator_test.cljc index 18afaa9fa..06d7d4df0 100644 --- a/test/malli/generator_test.cljc +++ b/test/malli/generator_test.cljc @@ -1124,3 +1124,19 @@ (doseq [_ (range 100) v (mg/sample [:seqable {:min 1} :any])] (is (seq v)))) + +#?(:clj + (deftest interrupt-recursive-gen-test + (let [started (promise) + finished (promise) + f (future + (deliver started true) + (try (mg/generate [:schema {:registry {::cons [:maybe [:vector [:tuple pos-int? [:ref ::cons]]]]}} + [:vector [:ref ::cons]]] + {:seed 1 + :size 10000}) + (catch InterruptedException _ (deliver finished :interrupted)) + (finally (deliver finished :not-interrupted))))] + @started + (future-cancel f) + (is (= :interrupted (deref finished 1000 :interrupted))))))