[Pkg-javascript-commits] [sockjs-client] 07/434: More tests: 404, 500 and connection refused tests.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:46:57 UTC 2014


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

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

commit 83abf1c7144f32b441ad5025529de71dbb686bb1
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Sat Jul 23 00:05:27 2011 +0100

    More tests: 404,500 and connection refused tests.
---
 lib/trans-jsonp.js            |  2 +-
 tests-src/test-factory.coffee | 87 ++++++++++++++++++++++++++++++++-----------
 tests-src/test-run.coffee     |  6 +++
 3 files changed, 73 insertions(+), 22 deletions(-)

diff --git a/lib/trans-jsonp.js b/lib/trans-jsonp.js
index cdd5e49..5302d05 100644
--- a/lib/trans-jsonp.js
+++ b/lib/trans-jsonp.js
@@ -51,7 +51,7 @@ JsonPTransport.prototype.doClose = function(status, reason) {
         this._send_stop();
     }
     this._recv_stop = this._send_stop = undefined;
-    this.ri._didClose();
+    this.ri._didClose(1001, "User requested");
 };
 
 JsonPTransport.prototype.doSend = function(message) {
diff --git a/tests-src/test-factory.coffee b/tests-src/test-factory.coffee
index f22bbd6..52e69f2 100644
--- a/tests-src/test-factory.coffee
+++ b/tests-src/test-factory.coffee
@@ -1,19 +1,13 @@
-debug = false
-
-echo_factory_factory = (protocol, messages, name) ->
+echo_factory_factory = (protocol, messages) ->
     return ->
         expect(3 + messages.length)
         a = messages.slice(0)
         r = new SockJS(test_server_url + '/echo', [protocol])
         ok(r)
         r.onopen = (e) ->
-            if debug
-                log(name+'_'+protocol+'_open', e)
             ok(true)
             r.send(a[0])
         r.onmessage = (e) ->
-            if debug
-                log(name+'_'+protocol+'_msg', e.data + ' ' + a[0])
             equals(e.data, a[0])
             a.shift()
             if typeof a[0] is 'undefined'
@@ -21,14 +15,12 @@ echo_factory_factory = (protocol, messages, name) ->
             else
                 r.send(a[0])
         r.onclose = (e) ->
-            if debug
-                log(name+'_'+protocol+'_close', e)
             ok(true)
             start()
 
 factor_echo_basic = (protocol) ->
     messages = ['data']
-    return echo_factory_factory(protocol, messages, 'echo_basic')
+    return echo_factory_factory(protocol, messages)
 
 factor_echo_unicode = (protocol) ->
     messages = [
@@ -43,7 +35,7 @@ factor_echo_unicode = (protocol) ->
         "Mogę jeść szkło, i mi nie szkodzi.",
         "\ufffd\u10102\u2f877",
     ]
-    return echo_factory_factory(protocol, messages, 'echo_unicode')
+    return echo_factory_factory(protocol, messages)
 
 factor_echo_special_chars = (protocol) ->
     messages = [
@@ -72,7 +64,7 @@ factor_echo_special_chars = (protocol) ->
         "message\ufffd",
         "\ufffdmessage",
     ]
-    return echo_factory_factory(protocol, messages, 'echo_unicode')
+    return echo_factory_factory(protocol, messages)
 
 
 factor_echo_large_message = (protocol) ->
@@ -82,31 +74,25 @@ factor_echo_large_message = (protocol) ->
         Array(4096*4).join('x'),
         Array(4096*8).join('x'),
     ]
-    return echo_factory_factory(protocol, messages, 'large_message')
+    return echo_factory_factory(protocol, messages)
 
 
-batch_factory_factory = (protocol, messages, name) ->
+batch_factory_factory = (protocol, messages) ->
     return ->
         expect(3 + messages.length)
         r = new SockJS(test_server_url + '/echo', [protocol])
         ok(r)
         counter = 0
         r.onopen = (e) ->
-            if debug
-                log(name+'_'+protocol+'_open', e)
             ok(true)
             for msg in messages
                 r.send(msg)
         r.onmessage = (e) ->
-            if debug
-                log(name+'_'+protocol+'_msg', e.data + ' ' + messages[counter])
             equals(e.data, messages[counter])
             counter += 1
             if counter is messages.length
                 r.close()
         r.onclose = (e) ->
-            if debug
-                log(name+'_'+protocol+'_close', e)
             ok(true)
             start()
 
@@ -120,4 +106,63 @@ factor_batch_large = (protocol) ->
         Array(Math.pow(2,17)).join('x'),
         Array(Math.pow(2,18)).join('x'),
     ]
-    return batch_factory_factory(protocol, messages, 'batch_large')
+    return batch_factory_factory(protocol, messages)
+
+
+
+factor_user_close = (protocol) ->
+    return ->
+        expect(4)
+        r = new SockJS(test_server_url + '/echo', [protocol])
+        ok(r)
+        r.onopen = (e) ->
+            ok(true)
+            r.close(3000, "User message")
+        r.onclose = (e) ->
+            equals(e.status, 3000)
+            equals(e.reason, "User message")
+            start()
+
+factor_server_close = (protocol) ->
+    return ->
+        expect(3)
+        r = new SockJS(test_server_url + '/close', [protocol])
+        ok(r)
+        r.onopen = (e) ->
+            ok(true)
+        r.onclose = (e) ->
+            equals(e.status, 1001)
+            start()
+
+test_invalid_url_404 = (protocol) ->
+    return ->
+        expect(2)
+        r = new SockJS(test_server_url + '/invalid_url', [protocol])
+        ok(r)
+        r.onopen = (e) ->
+            fail(true)
+        r.onclose = (e) ->
+            equals(e.status, 2000)
+            start()
+
+test_invalid_url_500 = (protocol) ->
+    return ->
+        expect(2)
+        r = new SockJS(test_server_url + '/500_error', [protocol])
+        ok(r)
+        r.onopen = (e) ->
+            fail(true)
+        r.onclose = (e) ->
+            equals(e.status, 2000)
+            start()
+
+test_invalid_url_port = (protocol) ->
+    return ->
+        expect(2)
+        r = new SockJS("http://127.0.0.1:1079", [protocol])
+        ok(r)
+        r.onopen = (e) ->
+            fail(true)
+        r.onclose = (e) ->
+            equals(e.status, 2000)
+            start()
diff --git a/tests-src/test-run.coffee b/tests-src/test-run.coffee
index 456a45c..43f701f 100644
--- a/tests-src/test-run.coffee
+++ b/tests-src/test-run.coffee
@@ -11,6 +11,12 @@ test_protocol = (protocol) ->
         asyncTest("large_message", factor_echo_large_message(protocol))
         asyncTest("batch_large", factor_batch_large(protocol))
 
+        asyncTest("user close", factor_user_close(protocol))
+        asyncTest("server close", factor_server_close(protocol))
+        asyncTest("invalid url 404", test_invalid_url_404(protocol))
+        asyncTest("invalid url 500", test_invalid_url_500(protocol))
+        asyncTest("invalid url port", test_invalid_url_port(protocol))
+
 
 for protocol in ['ws', 'jsonp']
     test_protocol(protocol)

-- 
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