0

我正在使用 Maven Flexmojos 插件在命令行上针对 Jetty/Java/Spring Security/BlazeDS 后端运行一些 FlexUnit4 集成测试。这些集成测试在 Flash 播放器的独立版本中运行。其中一项测试尝试了几种不同的登录场景,如下所示:

    [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));
    }

这些测试中的任何一个本身都通过了 100%,但是一个接一个地运行它们我间歇性地(大约 75% 的时间)得到一个错误:

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.

如果我尝试登录/注销两次,也会发生这种情况。所有登录和注销方法都基于使用 AMFChannelSet 的 ChannelSet.login 和 ChannelSet.logout。

更新:我相信我找到了问题的根源。独立播放器不使用 cookie,因此会混淆 BlazeDS 后端。见这里: http ://www.webappsolution.com/wordpress/2009/11/25/flexunit-4-testing-services-in-flash-player-issue/

4

1 回答 1

1

问题的间歇性使我猜测正在发生竞争情况。使用 Charles 代理协议调试实用程序,我能够看到 AMF 请求/响应消息。我不确定(现在仍然不确定),但我最好的猜测是第二次登录尝试发生在服务器有机会完全禁用之前的 FlexSession 之前。

因此,为了在登录尝试之间“争取时间”,我将测试方法分成不同的测试类和中提琴……这一切都刚刚好。

也许测试后的睡眠/延迟也可以解决问题,但我找不到 ActionScript 睡眠功能。

于 2010-10-27T13:05:13.190 回答