[Groonga-commit] groonga/express-kotoumi [master] test: Run tests with test HTTP client asynchronously

Back to archive index

YUKI Hiroshi null+****@clear*****
Mon Jan 28 18:24:42 JST 2013


YUKI Hiroshi	2013-01-28 18:24:42 +0900 (Mon, 28 Jan 2013)

  New Revision: 5558d708f2e7734b723e27ab75c45290fecc59db
  https://github.com/groonga/express-kotoumi/commit/5558d708f2e7734b723e27ab75c45290fecc59db

  Log:
    test: Run tests with test HTTP client asynchronously

  Modified files:
    test/backend-connection.test.js
    test/express-adaptor.test.js
    test/frontend-socket.io-handler.test.js
    test/test-utils.js

  Modified: test/backend-connection.test.js (+46 -0)
===================================================================
--- test/backend-connection.test.js    2013-01-28 18:14:00 +0900 (a0829b5)
+++ test/backend-connection.test.js    2013-01-28 18:24:42 +0900 (c9ded68)
@@ -235,3 +235,49 @@ suite('Connection, basic features', function() {
       });
   });
 });
+
+suite('Connection, to backend', function() {
+  var connection;
+  var backend;
+
+  setup(function(done) {
+    backend = new MsgPackReceiver(utils.testSendPort);
+    backend.received = [];
+    backend.on('receive', function(data) {
+      backend.received.push(data);
+    });
+    backend.listen(function() {
+      connection = new Connection({
+        tag:      'test',
+        hostName: 'localhost',
+        port:     utils.testSendPort
+      });
+      done();
+    });
+  });
+
+  teardown(function() {
+    if (backend) {
+      backend.close();
+      backend = undefined;
+    }
+    if (connection) {
+      connection.close();
+      connection = undefined;
+    }
+  });
+
+  test('send', function(done) {
+    connection.emitMessage({ message: true });
+    Deferred
+      .wait(0.01)
+      .next(function() {
+        assert.equal(backend.received.length, 1);
+        assert.equal(backend.received[0][0], 'test.message');
+        done();
+      })
+      .error(function(error) {
+        done(error);
+      });
+  });
+});

  Modified: test/express-adaptor.test.js (+10 -8)
===================================================================
--- test/express-adaptor.test.js    2013-01-28 18:14:00 +0900 (9edfb47)
+++ test/express-adaptor.test.js    2013-01-28 18:24:42 +0900 (79e0195)
@@ -107,10 +107,10 @@ suite('Adaption for express application', function() {
           });
           handlersFactory.assertThrows();
 
-          clientSocket = utils.createClientSocket();
+          return utils.createClientSocket();
         })
-        .wait(0.01)
-        .next(function() {
+        .next(function(newClientSocket) {
+          clientSocket = newClientSocket;
           clientSocket.emit('search', { requestMessage: true });
         })
         .wait(0.01)
@@ -145,14 +145,16 @@ suite('Adaption for express application', function() {
           });
           handlersFactory.assertThrows();
 
-          clientSocket = utils.createClientSocket();
+          return utils.createClientSocket();
+        })
+        .next(function(newClientSocket) {
+          clientSocket = newClientSocket;
+
+          connection.assertThrows();
+
           clientSocket.on('search.result', function(data) {
             clientReceiver.receive(data);
           });
-        })
-        .wait(0.01)
-        .next(function() {
-          connection.assertThrows();
 
           var envelope = {
             type:       'search.result',

  Modified: test/frontend-socket.io-handler.test.js (+13 -11)
===================================================================
--- test/frontend-socket.io-handler.test.js    2013-01-28 18:14:00 +0900 (a87e784)
+++ test/frontend-socket.io-handler.test.js    2013-01-28 18:24:42 +0900 (c480e16)
@@ -36,10 +36,10 @@ suite('Socket.IO API', function() {
           connection: connection
         });
 
-        clientSocket = utils.createClientSocket();
+        return utils.createClientSocket();
       })
-      .wait(0.01)
-      .next(function() {
+      .next(function(newClientSocket) {
+        clientSocket = newClientSocket;
         clientSocket.emit('search', { requestMessage: true });
       })
       .wait(0.01)
@@ -70,14 +70,16 @@ suite('Socket.IO API', function() {
           connection: connection
         });
 
-        clientSocket = utils.createClientSocket();
+        return utils.createClientSocket();
+      })
+      .next(function(newClientSocket) {
+        clientSocket = newClientSocket;
+
+        connection.assertThrows();
+
         clientSocket.on('search.result', function(data) {
           clientReceiver.receive(data);
         });
-      })
-      .wait(0.01)
-      .next(function() {
-        connection.assertThrows();
 
         var envelope = {
           type:       'search.result',
@@ -116,10 +118,10 @@ suite('Socket.IO API', function() {
           ]
         });
 
-        clientSocket = utils.createClientSocket();
+        return utils.createClientSocket();
       })
-      .wait(0.01)
-      .next(function() {
+      .next(function(newClientSocket) {
+        clientSocket = newClientSocket;
         clientSocket.emit('foobar', { requestMessage: true });
       })
       .wait(0.01)

  Modified: test/test-utils.js (+6 -1)
===================================================================
--- test/test-utils.js    2013-01-28 18:14:00 +0900 (a1f161c)
+++ test/test-utils.js    2013-01-28 18:24:42 +0900 (40384d5)
@@ -124,9 +124,14 @@ Deferred.register('post', function() { return post.apply(this, arguments); });
 
 
 function createClientSocket() {
+  var deferred = new Deferred();
   var host = 'http://localhost:' + testServerPort;
   var options = { 'force new connection': true };
-  return client.connect(host, options);
+  var socket = client.connect(host, options);
+  socket.on('connect', function() {
+    deferred.call(socket);
+  });
+  return deferred;
 }
 exports.createClientSocket = createClientSocket;
 
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index