Tests housekeeping

This commit is contained in:
Peter Taoussanis 2015-09-28 15:02:06 +07:00
parent 2f27666d05
commit 53d993e132

View file

@ -40,7 +40,7 @@
(check-props/for-all [val check-gen/any] (check-props/for-all [val check-gen/any]
(= val (thaw (freeze val))))))) (= val (thaw (freeze val)))))))
;;; These can sometimes crash the JVM ;;; Trying to decrypt random (invalid) data can actually crash JVM
;; (expect Exception (thaw (freeze test-data {:password "malformed"}))) ;; (expect Exception (thaw (freeze test-data {:password "malformed"})))
;; (expect Exception (thaw (freeze test-data {:password [:salted "p"]}))) ;; (expect Exception (thaw (freeze test-data {:password [:salted "p"]})))
;; (expect Exception (thaw (freeze test-data {:password [:salted "p"]}) ;; (expect Exception (thaw (freeze test-data {:password [:salted "p"]})
@ -77,25 +77,26 @@
(nippy/extend-thaw :nippy-tests/MyType [s] (->MyType (.readUTF s))) (nippy/extend-thaw :nippy-tests/MyType [s] (->MyType (.readUTF s)))
(let [type (->MyType "val")] (= type (thaw (freeze type)))))) (let [type (->MyType "val")] (= type (thaw (freeze type))))))
;;;; Stable binary representation of vals ; EXPERIMENTAL ;;;; Stable binary representation of vals
(expect (seq (freeze test-data)) (expect (seq (freeze test-data))
(seq (freeze test-data))) ; f(x)=f(y) | x=y (seq (freeze test-data))) ; f(x)=f(y) | x=y
;;; As above, but try multiple times (catch protocol interface races): ;; As above, but try multiple times to catch possible protocol interface races:
(expect #(every? true? %) (expect #(every? true? %)
(repeatedly 1000 (fn [] (= (seq (freeze test-data)) (repeatedly 1000 (fn [] (= (seq (freeze test-data))
(seq (freeze test-data)))))) (seq (freeze test-data))))))
(expect (seq (-> test-data freeze)) ; f(x)=f(f-1(f(x))) ;; NB abandoning - no way to do this reliably w/o appropriate contracts from
(seq (-> test-data freeze thaw freeze))) ;; (seq <unordered-coll>):
;;
;;; As above, but with repeated refreeze (catch protocol interface races): ;; (expect (seq (-> test-data freeze)) ; f(x)=f(f-1(f(x)))
(expect (= (seq (freeze test-data)) ;; (seq (-> test-data freeze thaw freeze)))
(seq (reduce (fn [frozen _] (freeze (thaw frozen))) ;;
(freeze test-data) (range 1000))))) ;; As above, but with repeated refreeze to catch possible protocol interface races:
;; (expect (= (seq (freeze test-data))
;;; ;; (seq (reduce (fn [frozen _] (freeze (thaw frozen)))
;; (freeze test-data) (range 1000)))))
(defn qc-prop-bijection [& [n]] (defn qc-prop-bijection [& [n]]
(let [bin->val (atom {}) (let [bin->val (atom {})
@ -125,7 +126,6 @@
(let [{:keys [result bin->val val->bin]} (qc-prop-bijection 10)] (let [{:keys [result bin->val val->bin]} (qc-prop-bijection 10)]
[result (vals bin->val)])) [result (vals bin->val)]))
;; (expect #(:result %) (qc-prop-bijection 120)) ; Time is n-non-linear
(expect #(:result %) (qc-prop-bijection 80)) (expect #(:result %) (qc-prop-bijection 80))
;;;; Thread safety ;;;; Thread safety