-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Hi there,
First off - thank you for this. I know Alex Miller and Rich Hickey are very opinionated (as is their right of course) about how Clojure and Spec are supposed to be used and indeed removed the :fn and :ret checking from the earlier versions of fdef instrumentation. I'm extremely happy you have added it back, as I love to be able to have multiple different kinds of testing (predefined unit, generational, and this sort of last chance monitoring of the running system).
I'd love to suggest an improvement for your consideration please.
Allow for an orchestra function to be defined which, if non-nil, will be called when an instrumented/fdef function's assertions would fail, would call this function with details of the failure instead of throwing an AssertionError. You might consider a global for the entire application, or a dynamic variable which can be used in certain sensitive areas, or even a different one for each fdef spec, stored in a map, etc. But, for the initial try, I'd be entirely happy with a single global function.
I looked at the code and there didn't seem to be too many places you throw things, so hopefully it would be straight-forward to implement.
This would allow the fdef instrumented assertion failures to be used and handled in whatever way suits the application, and would even, for example (assuming the overhead was acceptable), allow them to be used in production.
One thought was that I would love to deploy new code to production with fdef instrumentation turned on but the failures logged to an error log for a few days to ensure that there are no unexpected problems logged. That is much more gentle than breaking the application with a thrown error.
It would also be neat to be able to turn off the checking of instrumented functions with another global variable at runtime. This way I could connect to my running server over nREPL (yes, I run them in production that way), set the "assertion failure handling function", then set the "enable fdef spec checking" and find out more information about any production problems in a running system.
The function could do anything, including keeping a tab on the rate of failures and escalating things if the rate is high, etc.
Anyway, just a thought that I feel would add enormous flexibility to your Orchestra.
Thanks!