[Pkg-javascript-commits] [sockjs-client] 237/350: Add timeout for sender tests

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:04:25 UTC 2016


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.

commit e89740cb2eb2ab6b318c5f75a165172fec84396e
Author: Bryce Kahle <bkahle at gmail.com>
Date:   Fri Oct 24 16:29:52 2014 -0400

    Add timeout for sender tests
---
 lib/transport/browser/abstract-xhr.js | 11 +++++++++++
 lib/transport/sender/xdr.js           |  3 +++
 tests/lib/senders.js                  |  1 +
 3 files changed, 15 insertions(+)

diff --git a/lib/transport/browser/abstract-xhr.js b/lib/transport/browser/abstract-xhr.js
index ee899de..08a0a1a 100644
--- a/lib/transport/browser/abstract-xhr.js
+++ b/lib/transport/browser/abstract-xhr.js
@@ -49,6 +49,14 @@ AbstractXHRObject.prototype._start = function(method, url, payload, opts) {
   });
   try {
     this.xhr.open(method, url, true);
+    if (this.timeout && 'timeout' in this.xhr) {
+      this.xhr.timeout = this.timeout;
+      this.xhr.ontimeout = function() {
+        debug('xhr timeout');
+        self.emit('finish', 0, '');
+        self._cleanup(false);
+      };
+    }
   } catch (e) {
     debug('exception', e);
     // IE raises an exception on wrong port.
@@ -134,6 +142,9 @@ AbstractXHRObject.prototype._cleanup = function(abort) {
 
   // IE needs this field to be a function
   this.xhr.onreadystatechange = function() {};
+  if (this.xhr.ontimeout) {
+    this.xhr.ontimeout = null;
+  }
 
   if (abort) {
     try {
diff --git a/lib/transport/sender/xdr.js b/lib/transport/sender/xdr.js
index 40e35af..35d6593 100644
--- a/lib/transport/sender/xdr.js
+++ b/lib/transport/sender/xdr.js
@@ -59,6 +59,9 @@ XDRObject.prototype._start = function(method, url, payload) {
   try {
     // Fails with AccessDenied if port number is bogus
     this.xdr.open(method, url);
+    if (this.timeout) {
+      this.xdr.timeout = this.timeout;
+    }
     this.xdr.send(payload);
   } catch (x) {
     this._error();
diff --git a/tests/lib/senders.js b/tests/lib/senders.js
index 868f6e6..75085f3 100644
--- a/tests/lib/senders.js
+++ b/tests/lib/senders.js
@@ -70,6 +70,7 @@ function wrongUrl(Obj, url, statuses) {
     // Selenium has a long timeout for when it can't connect to the port
     this.timeout(30000);
     var x = new Obj('GET', url, null);
+    x.timeout = 10000;
     x.on('chunk', function (status, text) {
       done(new Error('No chunk should be received: ' + status + ', ' + text));
       x.abort();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list