[Pkg-javascript-commits] [sockjs-client] 143/434: Instead of uploading loads of data, we're in fact insterested mostly about the testing of messages from the server.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:09 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 df0588b6bd4e4ea8ab6d055ad8fb0185c6d1ee11
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Fri Sep 9 14:23:08 2011 +0100

    Instead of uploading loads  of data, we're in fact insterested mostly about the testing of messages from the server.
    
    Thus, introducing new test, which doesn't require us to upload big blobs.
---
 tests/html/src/tests.coffee | 51 ++++++++++++++++++++++++++++++++++++++-------
 tests/server.js             |  1 +
 tests/sockjs_app.js         | 15 +++++++++++++
 3 files changed, 59 insertions(+), 8 deletions(-)

diff --git a/tests/html/src/tests.coffee b/tests/html/src/tests.coffee
index 041b26d..b279ea0 100644
--- a/tests/html/src/tests.coffee
+++ b/tests/html/src/tests.coffee
@@ -125,9 +125,8 @@ factor_echo_large_message = (protocol) ->
         Array(Math.pow(2,2)).join('x'),
         Array(Math.pow(2,4)).join('x'),
         Array(Math.pow(2,8)).join('x'),
-        Array(Math.pow(2,16)).join('x'),
-        Array(Math.pow(2,17)).join('x'),
-        Array(Math.pow(2,18)).join('x'),
+        Array(Math.pow(2,13)).join('x'),
+        Array(Math.pow(2,13)).join('x'),
     ]
     return echo_factory_factory(protocol, messages)
 
@@ -160,13 +159,47 @@ factor_batch_large = (protocol) ->
         Array(Math.pow(2,2)).join('x'),
         Array(Math.pow(2,4)).join('x'),
         Array(Math.pow(2,8)).join('x'),
-        Array(Math.pow(2,16)).join('x'),
-        Array(Math.pow(2,17)).join('x'),
-        Array(Math.pow(2,18)).join('x'),
+        Array(Math.pow(2,13)).join('x'),
+        Array(Math.pow(2,13)).join('x'),
     ]
     return batch_factory_factory(protocol, messages)
 
 
+batch_factory_factory_amp = (protocol, messages) ->
+    return ->
+        expect(3 + messages.length)
+        r = newSockJS('/amplify', protocol)
+        ok(r)
+        counter = 0
+        r.onopen = (e) ->
+            ok(true)
+            for msg in messages
+                r.send(''+msg)
+        r.onmessage = (e) ->
+            equals(e.data.length, Math.pow(2, messages[counter]), e.data)
+            counter += 1
+            if counter is messages.length
+                r.close()
+        r.onclose = (e) ->
+            if counter isnt messages.length
+                ok(false, "Transport closed prematurely. " + e)
+            else
+                ok(true)
+            start()
+
+factor_batch_large_amp = (protocol) ->
+    messages = [
+        1,
+        2,
+        4,
+        8,
+        13,
+        15,
+        15,
+    ]
+    return batch_factory_factory_amp(protocol, messages)
+
+
 
 factor_user_close = (protocol) ->
     return ->
@@ -264,8 +297,10 @@ test_protocol_messages = (protocol) ->
         asyncTest("echo2", factor_echo_rich(protocol))
         asyncTest("unicode", factor_echo_unicode(protocol))
         asyncTest("special_chars", factor_echo_special_chars(protocol))
-        asyncTest("large_message", factor_echo_large_message(protocol))
-        asyncTest("batch_large", factor_batch_large(protocol))
+        asyncTest("large message (ping-pong)",
+            factor_echo_large_message(protocol))
+        asyncTest("large message (batch)", factor_batch_large(protocol))
+        asyncTest("large download", factor_batch_large_amp(protocol))
 
         asyncTest("user close", factor_user_close(protocol))
         asyncTest("server close", factor_server_close(protocol))
diff --git a/tests/server.js b/tests/server.js
index feac715..941e72f 100644
--- a/tests/server.js
+++ b/tests/server.js
@@ -22,6 +22,7 @@ server.addListener('request', function(req, res) {
 server.addListener('upgrade', function(req,res){
                        res.end();
                    });
+config.response_limit = 4*1024;
 sockjs_app.install(config, server);
 
 console.log(" [*] Listening on", config.host + ':' + config.port);
diff --git a/tests/sockjs_app.js b/tests/sockjs_app.js
index f669fd1..bfa9c07 100644
--- a/tests/sockjs_app.js
+++ b/tests/sockjs_app.js
@@ -57,9 +57,24 @@ exports.install = function(config, server) {
                                  });
                      });
 
+    var sjs_amplify = new sockjs.Server(config.opts);
+    sjs_amplify.on('open', function(conn){
+                    console.log('    [+] amp open    ' + conn);
+                    conn.on('close', function(e) {
+                                console.log('    [-] amp close   ' + conn, e);
+                            });
+                    conn.on('message', function(e) {
+                                var n = Math.floor(Number(e.data));
+                                n = (n > 0 && n < 19) ? n : 1;
+                                console.log('    [ ] amp message: 2^' + n);
+                                conn.send(Array(Math.pow(2, n)+1).join('x'));
+                            });
+                });
+
 
     sjs_echo.installHandlers(server, {prefix:'[/]echo'});
     sjs_close.installHandlers(server, {prefix:'[/]close'});
     sjs_ticker.installHandlers(server, {prefix:'[/]ticker'});
+    sjs_amplify.installHandlers(server, {prefix:'[/]amplify'});
     sjs_broadcast.installHandlers(server, {prefix:'[/]broadcast'});
 };

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