@@ -211,6 +211,12 @@ AV.Cloud.define("userMatching", function(req, res) {
211211 } , Math . floor ( ( Math . random ( ) * 2000 ) + 1 ) ) ;
212212} ) ;
213213
214+ AV . Cloud . define ( 'testTimeout' , function ( req , res ) {
215+ setTimeout ( function ( ) {
216+ res . success ( 'ok' ) ;
217+ } , req . params . delay ) ;
218+ } ) ;
219+
214220AV . Insight . on ( 'end' , function ( err , result ) {
215221 assert . deepEqual ( {
216222 "id" : "job id" ,
@@ -472,7 +478,6 @@ describe('functions', function() {
472478
473479 // 测试带有 sessionToken 时,user 对象的正确解析
474480 it ( 'testUser' , function ( done ) {
475- this . timeout ( 5000 ) ;
476481 request ( AV . Cloud )
477482 . post ( '/1/functions/testUser' )
478483 . set ( 'X-AVOSCloud-Application-Id' , appId )
@@ -483,7 +488,6 @@ describe('functions', function() {
483488
484489 // 无效 sessionToken 测试
485490 it ( 'testUser_invalid_sessionToken' , function ( done ) {
486- this . timeout ( 5000 ) ;
487491 request ( AV . Cloud )
488492 . post ( '/1/functions/testUser' )
489493 . set ( 'X-AVOSCloud-Application-Id' , appId )
@@ -498,7 +502,6 @@ describe('functions', function() {
498502
499503 // 测试调用 run 方法时,传递 user 对象的有效性
500504 it ( 'testRunWithUser' , function ( done ) {
501- this . timeout ( 5000 ) ;
502505 request ( AV . Cloud )
503506 . post ( '/1/functions/testRunWithUser' )
504507 . set ( 'X-AVOSCloud-Application-Id' , appId )
@@ -509,7 +512,6 @@ describe('functions', function() {
509512
510513 // 测试调用 run 方法 options callback
511514 it ( 'testRun_options_callback' , function ( done ) {
512- this . timeout ( 5000 ) ;
513515 request ( AV . Cloud )
514516 . post ( '/1/functions/testRun_options_callback' )
515517 . set ( 'X-AVOSCloud-Application-Id' , appId )
@@ -520,7 +522,6 @@ describe('functions', function() {
520522
521523 // 测试调用 run 方法,返回值是 promise 类型
522524 it ( 'testRun_promise' , function ( done ) {
523- this . timeout ( 5000 ) ;
524525 request ( AV . Cloud )
525526 . post ( '/1/functions/testRun_promise' )
526527 . set ( 'X-AVOSCloud-Application-Id' , appId )
@@ -574,6 +575,24 @@ describe('functions', function() {
574575 } ) ;
575576 } ) ;
576577
578+ it ( 'timeoutTest' , function ( done ) {
579+ this . timeout ( 17000 ) ;
580+ request ( AV . Cloud )
581+ . post ( '/1.1/functions/testTimeout' )
582+ . set ( 'X-AVOSCloud-Application-Id' , appId )
583+ . set ( 'X-AVOSCloud-Application-Key' , appKey )
584+ . send ( {
585+ delay : 15200 ,
586+ } )
587+ . expect ( 503 )
588+ . end ( function ( err , res ) {
589+ res . body . should . eql ( { code :124 , error :"The request timed out on the server." } ) ;
590+ setTimeout ( function ( ) { // 等待业务逻辑真正响应,确认异常信息
591+ done ( ) ;
592+ } , 1000 ) ;
593+ } ) ;
594+ } ) ;
595+
577596 // 用户串号测试
578597 it ( 'user_matching_func' , function ( done ) {
579598 this . timeout ( 30000 ) ;
0 commit comments