tl;dr; does anyone know how to safely do asynchronous coldbox handler integration testing using testbox?
I'm using coldbox 3.8.1.00076 and testbox 1.1.0.00076 and have created some integration tests similar to the example below and to make them run faster enabled asyncAll for them, however it seems the BaseTestCase execute method is not thread safe and shares the request context (and controller, etc) with all the threads in the cfc so Thread A (aTest) and Thread B (bTest) can sometimes end up returning the exact same event object which will contain the rendered result of whichever thread finished last... ish.
They mention in the docs to ensure tests are thread safe by properly scoping variables which they are and in their async example they reload wirebox but as the thread issues are coming from the shared coldbox objects i doubt this would help, i have tried it just in case but it also breaks the tests anyway as the example seems to be missing getting wirebox to configure with existing mappings but i didn't bother working out how to do that as i doubt it would solve my issue anyway.
Example Test
component extends="coldbox.system.testing.BaseTestCase" asyncAll="true"{
public function aTest() output="false"{
var event = execute(event:"someHandler.a", renderResults: true);
var cbox_rendered_content = event.getValue("cbox_rendered_content", "");
$assert.includes(cbox_rendered_content, "SOME_UNIQUE_CONTENT_TO_A"); //fails here when b content is returned
}
public function bTest() output="false"{
var event = execute(event:"someHandler.b", renderResults: true);
var cbox_rendered_content = event.getValue("cbox_rendered_content", "");
$assert.includes(cbox_rendered_content, "SOME_UNIQUE_CONTENT_TO_B"); //fails here when a content is returned
}
}
Example Runner
<!--- Executes all tests in the 'specs' folder with simple reporter by default --->
<cfparam name="url.reporter" default="simple">
<cfparam name="url.directory" default="test.specs">
<cfparam name="url.recurse" default="true" type="boolean">
<cfparam name="url.bundles" default="">
<cfparam name="url.labels" default="">
<cfparam name="url.reportpath" default="#expandPath( "/test/results" )#">
<cfparam name="url.propertiesFilename" default="TEST.properties">
<cfparam name="url.propertiesSummary" default="false" type="boolean">
<!--- Include the TestBox HTML Runner --->
<cfinclude template="/coldbox/system/testing/runners/HTMLRunner.cfm" >