views:

44

answers:

2

I am using the Maven Flexmojos plug-in to run some FlexUnit4 integration tests on the command line against a Jetty/Java/Spring Security/BlazeDS backend. These integration tests run in a stand-alone version of the flash player. One of these tests attempts a few different login scenarios as follows:

    [Test(async)]   
    public function userLogin_badCredentials_FailedLogin():void {
        var username:String = "guest";
        var password:String = "not_the_right_password";

        var token:AsyncToken = authenticationService.userLogin(username, password);
        token.addResponder(Async.asyncResponder(this, new TestResponder(handleRemoteObjectNoExpectedResult, handleRemoteObjectExpectedFaultBadCredentials), TIMEOUT, username, handleTestTimeout));
    }


    [Test(async)]
    public function userLoginLogout_UserLoggedIn_SuccessfulLoginLogout():void {
        var username:String = "admin";
        var password:String = "admin";

        var token:AsyncToken = authenticationService.userLogin(username, password);;
        token.addResponder(Async.asyncResponder(this, new TestResponder(userLoginLogout2_UserLoggedIn_SuccessfulLoginLogout, handleUnexpectedFault), TIMEOUT, username, handleTestTimeout));
    }
    public function userLoginLogout2_UserLoggedIn_SuccessfulLoginLogout(event:ResultEvent, passThroughData:Object):void {
        // Must have logged in correctly
        assertTrue(serviceManager.channelSet.authenticated);

        // Now lets test logout
        var token:AsyncToken = authenticationService.userLogout();
        token.addResponder(Async.asyncResponder(this, new TestResponder(handleExpectedResult, handleUnexpectedFault), TIMEOUT, null, handleTestTimeout));
    }

Either one of these tests pass 100% by itself, but running them both one after each other I am intermittently (about 75% of the time) getting an error:

Channel.Ping.Failed error Detected duplicate HTTP-based FlexSessions, generally
 due to the remote host disabling session cookies. Session cookies must be enabled
 to manage the client connection correctly.

This also happens if I try to login/logout twice. All login and logout methods are based on a ChannelSet.login and ChannelSet.logout which are making use of an AMFChannelSet.

Update: I believe I found the source of the problem. The standalone player does not make use of cookies and therefore is confusing the BlazeDS backend. See here: http://www.webappsolution.com/wordpress/2009/11/25/flexunit-4-testing-services-in-flash-player-issue/

+1  A: 

Check this link in order to see the detailed explanation - it's written by one of the LCDS guys.

Cornel Creanga
A: 

The intermittent nature of the problem, led me to guess that a race condition was happening. Using the Charles proxy protocol debugging utility, I was able to see the AMF request/response messages. I was not (and still am not) sure, but my best guess was that the second login attempt was happening before the server had the chance to completely disable the previous FlexSession.

So to "buy time" in between login attempts I separated the test methods into different test classes and viola...it all Just Worked.

Perhaps a post-test sleep/delay would also have done the trick, but I couldn't find an ActionScript sleep function.

HDave
try to set the log level on debug in blazeds; it's pretty verbose
Cornel Creanga