Uploaded image for project: 'ClojureScript'
  1. CLJS-1705

Calling (done) within binding in an async test corrupts bound vars

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Declined
    • Affects versions: 1.9.293, 1.9.76, 1.9.36
    • Fix versions: None
    • Labels:
    • Environment:

      OS X 10.11.5

      ⟩ java -version
      java version "1.8.0_72"
      Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)

      Description

      In an async test, calling (done) within a (binding) corrupts bound vars.

      repro/core.cljs
      (ns repro.core
        (:require [clojure.string :as string]
                  [cljs.test :refer-macros [async deftest is run-tests]]))
      
      (def ^:dynamic *foo* nil)
      
      (deftest async-binding-safe
        (async done
          (binding [*foo* {}]
            (is (some? *foo*)))
          (is (nil? *foo*))
          (done)))
      
      (deftest async-binding-corruption
        (async done
          (is (nil? *foo*))
          (binding [*foo* {}]
            (is (some? *foo*))
            (done))))
      
      (deftest async-binding-corrupt?
        (async done
          (is (nil? *foo*))
          (done)))
      
      (enable-console-print!)
      
      (run-tests 'repro.core)
      

      The first test passes as expected, and because (done) is outside the binding, *foo* is reverted to nil. The second test passes, but leaves *foo* bound. The third test fails.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: