Skip to content

Commit 30e8de5

Browse files
author
Gabriel Schulhof
committed
[testHelper] Fix up detailedEventCascade to properly deal with timeouts
1 parent e7896ac commit 30e8de5

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

tests/jquery.testHelper.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -262,34 +262,35 @@
262262
var newResult = {},
263263
nEventsDone = 0,
264264
nEvents = 0,
265+
recordResult = function( key, event, result ) {
266+
// Record the result
267+
newResult[ key ] = $.extend( {}, event, result );
268+
// Increment the number of received responses
269+
nEventsDone++;
270+
if ( nEventsDone === nEvents ) {
271+
// clear the timeout and move on to the next step when all events have been received
272+
if ( warnTimer ) {
273+
clearTimeout( warnTimer );
274+
}
275+
setTimeout( function() {
276+
self.detailedEventCascade( seq, newResult );
277+
}, 0);
278+
}
279+
},
265280
// set a failsafe timer in case one of the events never happens
266281
warnTimer = setTimeout( function() {
282+
warnTimer = 0;
267283
$.each( events, function( key, event ) {
268-
if ( newResult[ key ] === undefined ) {
284+
// Timeouts are left out of this, because they will complete for
285+
// sure, calling recordResult when they do
286+
if ( newResult[ key ] === undefined && event.src ) {
269287
// clean up the unused handler
270288
derefSrc( event.src ).unbind( event.event );
271-
newResult[ key ] = $.extend( {}, event, { timedOut: true } );
289+
recordResult( key, event, { timedOut: true } );
272290
}
273291
});
274-
275-
// Move on to the next step
276-
self.detailedEventCascade( seq, newResult );
277292
}, 20000);
278293

279-
function recordResult( key, event, result ) {
280-
// Record the result
281-
newResult[ key ] = $.extend( {}, event, result );
282-
// Increment the number of received responses
283-
nEventsDone++;
284-
if ( nEventsDone === nEvents ) {
285-
// clear the timeout and move on to the next step when all events have been received
286-
clearTimeout( warnTimer );
287-
setTimeout( function() {
288-
self.detailedEventCascade( seq, newResult );
289-
}, 0);
290-
}
291-
}
292-
293294
$.each( events, function( key, event ) {
294295
// Count the events so that we may know how many responses to expect
295296
nEvents++;

0 commit comments

Comments
 (0)