Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the rcf timeout for async tests inside of tests? #33

Open
didibus opened this issue Oct 24, 2021 · 0 comments
Open

Change the rcf timeout for async tests inside of tests? #33

didibus opened this issue Oct 24, 2021 · 0 comments

Comments

@didibus
Copy link

didibus commented Oct 24, 2021

I have some tests where I want to assert timing, for example:

(rcf/set-timeout! 1)
(tests
    "Awaits all promise-chan in given vector and returns a vector of their results in order. Promise-chans obviously run concurrently, so the entire operation will take as long as the longest one."
    (rcf/set-timeout! 210)
    (async
     (! (await (all [1 (timeout 100 2) (timeout 200 3)]))))
    % := [1 2 3])

Now this test will fail, because it seems the call to (rcf/set-timeout! 210) won't change the timeout of the test. This is kind of annoying, because when I have many tests which I need to control timeouts differently I have to do:

(do
  (rcf/set-timeout! 210)
  (tests
    "Awaits all promise-chan in given vector and returns a vector of their results in order. Promise-chan obviously run concurrently, so the entire operation will take as long as the longest one."
    (async
     (! (await (all [1 (timeout 100 2) (timeout 200 3)]))))
    % := [1 2 3])

  (rcf/set-timeout! 20)
  (tests
    "Short-circuits as soon as one promise-chan errors, returning the error."
    (async
     (try
       (await (all [(timeout 10 #(/ 1 0)) (timeout 100 2) (timeout 200 3)]))
       (catch Exception e
         (! e))))
    (type %) := ArithmeticException)

  (rcf/set-timeout! 1000)
  (tests
    "Can contain non-promise-chan as well."
    (async
     (! (await (all [1 2 3]))))
    % := [1 2 3]

    "But since all is not a macro, if one of them throw it throws"
    (try (all [1 (timeout 10 2) (/ 1 0)])
         (catch Exception e
           (! e)))

    (type %) := ArithmeticException))

What I'd like to do instead is:

(tests
    "Awaits all promise-chan in given vector and returns a vector of their results in order. Promise-chan obviously run concurrently, so the entire operation will take as long as the longest one."
  (rcf/set-timeout! 210)
  (async
   (! (await (all [1 (timeout 100 2) (timeout 200 3)]))))
  % := [1 2 3])

  "Short-circuits as soon as one promise-chan errors, returning the error."
  (rcf/set-timeout! 20)
    (async
     (try
       (await (all [(timeout 10 #(/ 1 0)) (timeout 100 2) (timeout 200 3)]))
       (catch Exception e
         (! e))))
    (type %) := ArithmeticException)

  (rcf/set-timeout! 1000)
  "Can contain non-promise-chan as well."
  (async
    (! (await (all [1 2 3]))))
  % := [1 2 3]

  "But since all is not a macro, if one of them throw it throws"
  (try (all [1 (timeout 10 2) (/ 1 0)])
       (catch Exception e
         (! e)))

  (type %) := ArithmeticException))

I'd be happy if I could use (binding [rcf/*timeout*]) or something similar as well to wrap my individual tests inside the tests block too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant