1 Reply Latest reply on Nov 4, 2010 6:37 AM by injpix

    Error: Asynchronous Event Received out of Order

    injpix Level 3

      Hello, I'm developing a loader library in Flex that can do multiple requests in an intermittent or sequential order there given to the loader.  I'm getting the following error message from FlexUnit when the loader is under test:


      Error: Asynchronous Event Received out of Order


      Below is the Test method.  Notice request number 13 is flagged to parallel (intermittent), which skips the queuing process and gets loaded immediately.  This is causing the error.

      [Test( async, description="Assert loader is handling parallel and sequence requests correctly.")]
      public function testToHandleProcessingTypeCorrectly():void
      {
          var pre_loader_result_list:String = "";
          var post_loader_result_list:String = "";
          
          //mock to see how many times the sendNextRequest is called
          var queuemanager:QueueManager = nice(QueueManager);
          queuemanager.airloader     = loader;
          loader.queueManager     = queuemanager;
          
          for(var i:int=1; i<=25; i++)
          {
              var request:AIRLoaderRequest = new AIRLoaderRequest("graphics/"+i.toString()+".png");
              request.processType = (i == 13)? AIRLoaderProcessType.PARALLEL:AIRLoaderProcessType.SEQUENCE;
      
              pre_loader_result_list += request.uri;
          
              var testresponder:TestResponder = new TestResponder(function (event:ResultEvent, passThroughData:Object):void 
              {
                  post_loader_result_list += (event.result as AIRLoaderRequest).uri;
              }, onFaultHandler);
              request.token.addResponder( Async.asyncResponder(this,testresponder, 5000, null) );
              
              loader.send(request);
          }
          
          // 25 requests, 1 of them doesn't go thru queuemanager, so it should equal 24.
          assertThat( queuemanager, received().method('sendNextRequest').times(24) );
      
          assertFalse(pre_loader_result_list, post_loader_result_list);
      }
      

       

      Any suggestions?

        • 1. Re: Error: Asynchronous Event Received out of Order
          injpix Level 3

          After more tinkering with this test, I realized the assertions were useless.  So below is an updated version of the test, however the original error still exists.

           

          [Test( async, timeout=10000, description="Assert loader is handling parallel and sequence requests correctly.")]
          public function testToHandleProcessingTypeCorrectly():void
          {
              for(var i:int=1; i<=25; i++)
              {
                  var request:AIRLoaderRequest = new AIRLoaderRequest("graphics/"+i.toString()+".png");
                  
                  if(i == 13)
                      request.processType = AIRLoaderProcessType.PARALLEL;
                      
                  var testresponder:TestResponder = new TestResponder(function (event:ResultEvent, passThroughData:Object):void 
                  {
                      callCounter++;
                      
                      if(callCounter == 24)
                      {
                          //check to make sure that the queue stack is now cleared.
                          assertEquals(loader.queueManager.stack.length, 0);
                          
                          // request number 13 shouldn't have gone thru queueManager, hence 24 not 25.
                          assertTrue("The number of calls to queueManager is correct.", callCounter, 24);
                      }
                      
                  }, onFaultHandler);
                  request.token.addResponder( Async.asyncResponder(this, testresponder, 5000, null) );
                  
                  loader.send(request);
              }
          }