我正在使用 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/