Skip to main content
Participant
September 24, 2008
Question

addAsync chaining help

  • September 24, 2008
  • 8 replies
  • 1677 views
Hi,
Using v0.9

I read over the online doc on chaining here:

http://www.adobe.com/cfusion/communityengine/index.cfm?event=showDetails&postId=6882&productId=2&loc=en_US

However I cannot seem to get this to work.

a) My outer "test" registers a addAsync function (verifyWriteComplete) to listen for the "success" event of writing a file. This gets called successfully.

b) verifyWriteComplete, then calls another function called "readWrittenFile".

c) "readWrittenFile" registers and addAsync function "verifyReadComplete" which reads the file written by A above. This verifyReadComplete function IS being called OK (I can see via trace statements).

The problem is that the second chained addAsync (C) above in flexunit is still reporting that it was never called within the timeout, despite the fact that it obviously is. The test runner is reporting a failure, even though the verifyReadComplete wrapped in an addAsync was called OK.
This topic has been closed for replies.

8 replies

Participant
October 7, 2008
There is a problem in the current code where the firing of an async will be ignored if it fires before the test or currently executing async has finished executing. This is because AsyncTestHelper.runNext clears the values of func, objToPass, and extraData when it finishes. This has been fixed in a test version of FlexUnit.

I filed bug https://bugs.adobe.com/jira/browse/FXU-19 for this issue.
Participant
September 25, 2008
Ok, if I do that as recommended in your last post, I get a false positive during a failure in the read portion. The error pops up in the app as an exception but the test passes green.

If I have the second addAsync with the callLater call, then it fails red with no pop-up exception
Participating Frequently
September 25, 2008
> interesting. Well I added a wrapper call for <br />> Application.application.callLater for the call to readWrittenFile and <br />> now it works.<br /><br /> If you remove the call to callLater you can also remove the second <br />addAsync() call. What that means is that readWrittenFile() isn't <br />performing any asynchronous action which requires the use of addAsync(). <br />Only events that fire asynchronously need to be wrapped with addAsync(). <br />Events that fire immediately can be setup with a normal addEventListener() <br />call.<br /><br />-- Daniel R. <danielr@neophi.com> [http://danielr.neophi.com/]
Participant
September 24, 2008
interesting. Well I added a wrapper call for Application.application.callLater for the call to readWrittenFile and now it works.

Thanks for your help!

Side note: This behavior may need to be reworked as it is not very natural nor obvious to someone trying to create some tests.
Participating Frequently
September 24, 2008
> I really am confused here, if there are multiple items on the async<br />> helper stack, why is the timer being stopped on the first call which<br />> subsequently is preventing my second "addAsync" handling function not to<br />> be called?<br /><br /> The timer is restarted when the method called by the first <br />addAsync() finishes executing. The test harness then determines that <br />another addAsync() was registered and it should wait for that instead of <br />running the next test.<br /><br /> If I understand the test flow from your original message <br />"verifyWriteComplete" must exit before the second event fires as noted <br />below.<br /><br />testWrite() {<br /> addAsync("verifyWriteComplete");<br /> // this method must return before the event<br /> // that triggers verifyWriteComplete is called<br />}<br /><br />verifyWriteComplete() {<br /> readWrittenFile();<br /> // this method must return before the event<br /> // that triggers verifyReadComplete is called<br />}<br /><br />readWrittenFile() {<br /> addAsync("verifyReadComplete");<br />}<br /><br />verifyReadComplete() {<br />}<br /><br />-- Daniel R. <danielr@neophi.com> [http://danielr.neophi.com/]
Participant
September 24, 2008
Basically I am doing essentially the same thing as listed here (last example) to no avail.

http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=6882
Participant
September 24, 2008
Thanks saw your article earlier. However I am already making multiple calls to addAsync. I have been stepping into the flexunit code:

This function is returned on the first call to addAsync(). The first event that this handles stops the timer and "wasReallyAsync" is true so the code continues. At this point my code calls "addAsync" again. When the event fires for the 2nd event, this code runs again but since the timer is stopped my code is not being called.

I really am confused here, if there are multiple items on the async helper stack, why is the timer being stopped on the first call which subsequently is preventing my second "addAsync" handling function not to be called?

public function handleEvent( event : Object ) : void
{
var wasReallyAsync : Boolean = timer.running;

timer.stop();

if ( shouldFail )
return;

objToPass = event;
if ( wasReallyAsync )
{
testResult.continueRun( testCase );
}
}
Participating Frequently
September 24, 2008
> The problem is that the second chained addAsync (C) above in flexunit is <br />> still reporting that it was never called within the timeout, despite the <br />> fact that it obviously is. The test runner is reporting a failure, even <br />> though the verifyReadComplete wrapped in an addAsync was called OK.<br /><br /> This sounds like an issue I ran across where if the function <br />mentioned in addAsync() isn't actually being called in an asynchronous <br />manner, you will get the odd behavior. I wrote up some details on this <br />case (in particular the last example):<br /><br />http://life.neophi.com/danielr/2008/08/odd_addasync_behavior_when_han.html<br /><br />-- Daniel R. <danielr@neophi.com> [http://danielr.neophi.com/]