|
1565 | 1565 | (is (= true (realized? fut))))) |
1566 | 1566 |
|
1567 | 1567 | (testing "timed deref of future" |
1568 | | - (let [fut (future (time/sleep 3)) |
| 1568 | + (let [pre (time/perf-counter) |
| 1569 | + fut (future (time/sleep 3)) |
1569 | 1570 | start (time/perf-counter) |
1570 | 1571 | ;; block for 100ms |
1571 | 1572 | ret (deref fut 100 :timed-out) |
1572 | 1573 | end (time/perf-counter) |
1573 | 1574 | diff (- end start)] |
1574 | 1575 | (is (= :timed-out ret)) |
1575 | | - (is (< 0.1 diff 0.5) (str "deref timeout outside of [100ms, 500ms] range: " diff "ms")) |
| 1576 | + (is (< 0.1 diff 0.5) (str "deref timeout outside of [100ms, 500ms] range: " diff "ms" |
| 1577 | + " -- :pre " pre " :start " start " :end " end)) |
1576 | 1578 | (is (= false (future-cancelled? fut))) |
1577 | 1579 | (is (= false (future-done? fut))) |
1578 | 1580 | ;; can't always cancel a sleep-ed Future |
|
1849 | 1851 | (testing "calling vars" |
1850 | 1852 | (is (= '(1 2) (#'basilisp.core/list 1 2))))) |
1851 | 1853 |
|
| 1854 | +;;;;;;;;;;;;;;;;;;; |
| 1855 | +;; Var Utilities ;; |
| 1856 | +;;;;;;;;;;;;;;;;;;; |
| 1857 | + |
| 1858 | +(def test-var-unadorned 7) |
| 1859 | +(def ^:redef test-var-redef 19) |
| 1860 | +(def ^:dynamic test-var-dynamic 23) |
| 1861 | + |
| 1862 | +(deftest test-alter-var-root |
| 1863 | + (testing "on unadorned var" |
| 1864 | + (is (= 8 (alter-var-root #'test-var-unadorned inc))) |
| 1865 | + ;; Basilisp Direct Linking Optimization side effect: altering the |
| 1866 | + ;; root var on variables is not reflected back to the code ... |
| 1867 | + (is (= 7 test-var-unadorned)) |
| 1868 | + ;; ... unless the var is referenced explicitly. |
| 1869 | + (is (= 8 @#'test-var-unadorned))) |
| 1870 | + |
| 1871 | + (testing "on ^:redef var" |
| 1872 | + (is (= 20 (alter-var-root #'test-var-redef inc))) |
| 1873 | + ;; altering the root is reflected in the code because the variable |
| 1874 | + ;; was defined with ^:redef. |
| 1875 | + (is (= 20 test-var-redef)) |
| 1876 | + (is (= 20 @#'test-var-redef))) |
| 1877 | + |
| 1878 | + (testing "on dynamic var" |
| 1879 | + (is (= 24 (alter-var-root #'test-var-dynamic inc))) |
| 1880 | + ;; altering the root is reflected in the code because the variable |
| 1881 | + ;; is dynamic. |
| 1882 | + (is (= 24 test-var-dynamic)) |
| 1883 | + (is (= 24 @#'test-var-dynamic)))) |
| 1884 | + |
1852 | 1885 | ;;;;;;;;;;;;;;;;; |
1853 | 1886 | ;; Hierarchies ;; |
1854 | 1887 | ;;;;;;;;;;;;;;;;; |
|
0 commit comments