@@ -33,9 +33,9 @@ function slowTestDescription(useChurn:boolean) {
3333 testerFactoryManager . close ( ) ;
3434 } ) ;
3535
36- // The default TCP SYN timeout is two minutes, so to be safe we
37- // set a test timeout of four minutes.
38- jasmine . DEFAULT_TIMEOUT_INTERVAL = 240000 ;
36+ // 100 MB download through CHURN takes about 10 minutes.
37+ // Set the limit to 20 minutes for safety .
38+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 20 * 60 * 1000 ;
3939
4040 // Opens 200 connections, sends 1 KB on each, and receives 250 KB on each
4141 it ( 'download load test' , ( done ) => {
@@ -51,26 +51,29 @@ function slowTestDescription(useChurn:boolean) {
5151 }
5252 return Promise . all ( connectionPromises ) ;
5353 } ) . then ( ( connectionIds :string [ ] ) => {
54- var completions = connectionIds . map ( ( connectionId :string ) : Promise < void > => {
55- var resolve :Function ;
56- var result :Promise < void > = new Promise < void > ( ( F , R ) => { resolve = F ; } ) ;
57- var isDone = false ;
58- var outputString = '' ;
59- testModule . on ( 'receivedData' , ( event :ReceivedDataEvent ) => {
60- if ( event . connectionId != connectionId ) {
61- return ;
54+ // Maps connectionIds to the number of bytes received so far. Counters
55+ // start at 0, and entries are deleted when all data has been received
56+ // for a connection. When all entries have been deleted, the test passes.
57+ let counters :{ [ id :string ] : number } = { } ;
58+ testModule . on ( 'receivedData' , ( event :ReceivedDataEvent ) => {
59+ const id = event . connectionId ;
60+ if ( id in counters ) {
61+ counters [ id ] += event . response . byteLength ;
62+ } else {
63+ throw new Error ( 'Unexpected connectionId ' + id ) ;
64+ }
65+ if ( counters [ id ] === repeat * blockSize ) {
66+ delete counters [ id ] ;
67+ // Check if we have deleted the last id.
68+ if ( Object . keys ( counters ) . length === 0 ) {
69+ done ( ) ;
6270 }
63- expect ( isDone ) . toBe ( false ) ;
64- if ( event . response . byteLength === repeat * blockSize ) {
65- isDone = true ;
66- resolve ( ) ;
67- }
68- } ) ;
69- return testModule . sendData ( connectionId , testBlock ) . then ( ( ) => {
70- return result ;
71- } ) ;
71+ }
72+ } ) ;
73+ connectionIds . map ( ( id :string ) => {
74+ counters [ id ] = 0 ;
75+ testModule . sendData ( id , testBlock ) ;
7276 } ) ;
73- Promise . all ( completions ) . then ( done ) ;
7477 } ) ;
7578 } ) ;
7679
0 commit comments