-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Use the provided timeout option, if set, for the InfoReceiver. ⏰ #594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,7 @@ function SockJS(url, protocols, options) { | |
, sameScheme: urlUtils.isSchemeEqual(this.url, loc.href) | ||
}; | ||
|
||
this._ir = new InfoReceiver(this.url, this._urlInfo); | ||
this._ir = new InfoReceiver(this.url, this._urlInfo, options.timeout); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential runtime error if 'options' is undefined or null. The code should safely access options.timeout with optional chaining or a fallback check. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
this._ir.once('finish', this._receiveInfo.bind(this)); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ var expect = require('expect.js') | |
, XhrReceiver = require('../../lib/transport/receiver/xhr') | ||
, XhrFake = require('../../lib/transport/sender/xhr-fake') | ||
, utils = require('../../lib/utils/iframe') | ||
; | ||
, InfoAjax = require('../../lib/info-ajax') | ||
, InfoReceiver = require('../../lib/info-receiver'); | ||
|
||
describe('Receivers', function () { | ||
describe('jsonp', function () { | ||
|
@@ -288,4 +289,43 @@ describe('Receivers', function () { | |
xhr.abort(); | ||
}); | ||
}); | ||
describe('info', function () { | ||
it('will timeout - default timeout', function (done) { | ||
this.timeout(10000); | ||
InfoReceiver.prototype._getReceiver = function(baseUrl, url) { | ||
return new InfoAjax(url, XhrFake); | ||
}; | ||
|
||
var expectedWasClean = true; | ||
InfoReceiver.prototype._cleanup = function(wasClean) { | ||
expect(wasClean).to.equal(expectedWasClean); | ||
if (expectedWasClean === false) { | ||
// Cleanup was called because of a timeout | ||
done(); | ||
} | ||
expectedWasClean = false; | ||
}; | ||
|
||
new InfoReceiver('test', {}); | ||
}); | ||
|
||
it('will timeout - configured timeout', function (done) { | ||
this.timeout(2000); | ||
InfoReceiver.prototype._getReceiver = function(baseUrl, url) { | ||
return new InfoAjax(url, XhrFake); | ||
}; | ||
|
||
var expectedWasClean = true; | ||
InfoReceiver.prototype._cleanup = function(wasClean) { | ||
expect(wasClean).to.equal(expectedWasClean); | ||
if (expectedWasClean === false) { | ||
// Cleanup was called because of a timeout | ||
done(); | ||
} | ||
expectedWasClean = false; | ||
}; | ||
|
||
new InfoReceiver('test', {}, 1000); | ||
}); | ||
}); | ||
Comment on lines
+292
to
+330
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I apologize for these awkward tests - I do not fully understand all of the inheritance going on, so I overrode what I needed to test the override. The result is that the finish event is still emitted, and that is why I have the |
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I saw in the documentation that SockJS will use the bigger timeout of either the "internally calculated" timeout, or the timeout option. Do you want this to apply here, too? Something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really "calculated," though. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.