Skip to main content
March 26, 2009
Question

Verifying a list of same events

  • March 26, 2009
  • 4 replies
  • 1054 views
Hi,

I am writing a test method to verify playing a list of video. Each time a video is played, player sends "playing" event out. So my code would just listen for that event from the player. In addition, player implementation is asynchronous by nature. The issue here is that if i code test method like the following, flexunit does not wait for event to occur before executing next loop iteration.

public function testPlaying10Videos():void
{
for (var i:int = 0; i < 10; i++)
{
var uuid:String = TestHelper.getRandomVideoId();
Player.Instance.addEventListener(Event.Playing,
addAsync(verifyVideoPlaying,
60000,
uuid,
errorVideoNotPlaying));

Player.Instance.callMethod("vidPlayId", uuid);
}
}

Any idea how to overcome this issue?

Thanks,
Dina
This topic has been closed for replies.

4 replies

Participating Frequently
March 29, 2009
Once an addAsync error handler has been called events are no longer<br />processed. FlexUnit uses a fail fast approach. The first assert that<br />fails or the first addAsync that fails will stop the test from<br />executing.<br /><br />-- Daniel R. <danielr@neophi.com> [http://danielr.neophi.com/]<br /><br /><br /><br />On Fri, Mar 27, 2009 at 8:50 PM, Dina So <member@adobeforums.com> wrote:<br />> A new message was posted by Dina So in<br />><br />> FlexUnit Development --<br />>   Verifying a list of same events<br />><br />> I face another issue with the solution. I implemented the following code. If<br />> somehow an error occur that player does not fire playing event, addAsync<br />> will call errorVideoNotPlaying() (addAsync timeout). I coded<br />> errorVideoNotPlaying() to call playNextVideo() again but it looks like even<br />> if the player does fire playing event, any subsequence addAsync successful<br />> event notification will not execute the desired verifyVideoPlaying()<br />> function at all.<br />><br />> Do you have any other idea on this?<br />><br />> private var count:int = 0;<br />><br />> public function testPlaying10Videos():void<br />> {<br />>   playNextVideo();<br />> }<br />><br />> private function playNextVideo():void<br />> {<br />>   var uuid:String = TestHelper.getRandomVideoId();<br />>   Player.Instance.addEventListener(Event.Playing,addAsync(verifyVideoPlaying,<br />> 60000, uuid, errorVideoNotPlaying));<br />> Player.Instance.callMethod("vidPlayId", uuid);<br />> }<br />><br />> private function verifyVideoPlaying(event:Event, uuid:String):void<br />> {<br />>   var state:String = Player.Instance.callMethod("vidGetState") as String;<br />>   var id:String = Player.Instance.callMethod("vidGetId") as String;<br />><br />> if (PlayerState.Playing == state && uuid == id)<br />>       Application.application.logSuccess(uuid);<br />>   else<br />>       Application.application.logError(uuid);<br />><br />> count++;<br />><br />> if (count < 10) { playNextVideo(); } }<br />><br />> private function errorVideoNotPlaying(uuid:String):void<br />> {<br />>   Application.application.logError(uuid);<br />>   playNext();<br />> }<br />><br />> ________________________________<br />> View/reply at Verifying a list of same events<br />> Replies by email are OK.<br />> Use the unsubscribe form to cancel your email subscription.<br />><br />>
March 27, 2009
I face another issue with the solution. I implemented the following code. If somehow an error occur that player does not fire playing event, addAsync will call errorVideoNotPlaying() (addAsync timeout). I coded errorVideoNotPlaying() to call playNextVideo() again but it looks like even if the player does fire playing event, any subsequence addAsync successful event notification will not execute the desired verifyVideoPlaying() function at all.

Do you have any other idea on this?

private var count:int = 0;

public function testPlaying10Videos():void
{
playNextVideo();
}

private function playNextVideo():void
{
var uuid:String = TestHelper.getRandomVideoId();
Player.Instance.addEventListener(Event.Playing,addAsync(verifyVideoPlaying, 60000, uuid, errorVideoNotPlaying));
Player.Instance.callMethod("vidPlayId", uuid);
}

private function verifyVideoPlaying(event:Event, uuid:String):void
{
var state:String = Player.Instance.callMethod("vidGetState") as String;
var id:String = Player.Instance.callMethod("vidGetId") as String;

if (PlayerState.Playing == state && uuid == id)
Application.application.logSuccess(uuid);
else
Application.application.logError(uuid);

count++;

if (count < 10)
{
playNextVideo();
}
}

private function errorVideoNotPlaying(uuid:String):void
{
Application.application.logError(uuid);
playNext();
}
March 26, 2009
Thanks Daniel for the solution.
Participating Frequently
March 26, 2009
I suspect the code will need to be reworked so that an attempt to play<br />the next video is done only after the previous attempt is verified.<br />Below is a sample rework of the code that I believe will do what you<br />need. The count tracks the number of videos played and the<br />verification function starts playing another one if appropriate. Using<br />this approach there is only ever one active addAsync call.<br /><br />private var count:int = 0;<br />public function testPlaying10Videos():void {<br /> playNextVideo();<br />}<br />private function playNextVideo():void {<br /> var uuid:String = TestHelper.getRandomVideoId();<br /> Player.Instance.addEventListener(Event.Playing,<br />addAsync(verifyVideoPlaying, 60000, uuid, errorVideoNotPlaying));<br /> Player.Instance.callMethod("vidPlayId", uuid);<br />}<br />private function verifyVideoPlaying(event:Event, uuid:String):void {<br /> // verification test here<br /> // loop as many times as desired<br /> count++;<br /> if (count < 10) {<br /> playNextVideo();<br /> }<br />}<br /><br />-- Daniel R. <danielr@neophi.com> [http://danielr.neophi.com/]<br /><br /><br /><br />On Wed, Mar 25, 2009 at 9:18 PM, Dina So <member@adobeforums.com> wrote:<br />> A new discussion was started by Dina So in<br />><br />> FlexUnit Development --<br />> Verifying a list of same events<br />><br />> Hi,<br />><br />> I am writing a test method to verify playing a list of video. Each time a<br />> video is played, player sends "playing" event out. So my code would just<br />> listen for that event from the player. In addition, player implementation is<br />> asynchronous by nature. The issue here is that if i code test method like<br />> the following, flexunit does not wait for event to occur before executing<br />> next loop iteration.<br />><br />> public function testPlaying10Videos():void<br />> {<br />> for (var i:int = 0; i < 10; i++) { var uuid:String =<br />> TestHelper.getRandomVideoId();<br />> Player.Instance.addEventListener(Event.Playing, addAsync(verifyVideoPlaying,<br />> 60000, uuid, errorVideoNotPlaying));<br />><br />> Player.Instance.callMethod("vidPlayId", uuid);<br />> }<br />> }<br />><br />> Any idea how to overcome this issue?<br />><br />> Thanks,<br />> Dina<br />><br />> ________________________________<br />> View/reply at Verifying a list of same events<br />> Replies by email are OK.<br />> Use the unsubscribe form to cancel your email subscription.<br />><br />>