circleci / bond

spying for tests
127 stars 28 forks source link

Thread-safe version of `with-spy` and `with-stub` #45

Closed mourjo closed 3 years ago

mourjo commented 5 years ago

Bond uses with-redefs which binds the function's var's root to the new definition, which means it is visible to all threads that are currently executing, not necessarily the one in the context of with-spy or with-stub, for example

(defn funk [& args] args)

(future
  (bond/with-stub! [[funk (constantly -1)]]
    (Thread/sleep 10000)
    (funk)))

(funk 9) ;; => -1 (redefined function being called outside of with-stub)

;; after ten seconds
(funk 9) ;; => (9)

I was curious if you think using thread-local redefinitions is something you think would be useful here. For example, using https://gist.github.com/gfredericks/7143494

mourjo commented 4 years ago

Hello, was wondering if there is an update on this? Have been using this patch for a while, would like to have it in a stable release!

neeasade commented 3 years ago

closing -- see https://github.com/circleci/bond/pull/47#issuecomment-832816528