[Groonga-commit] groonga/express-kotoumi [master] Implement Connection#close

Back to archive index

YUKI Hiroshi null+****@clear*****
Mon Jan 28 15:59:54 JST 2013


YUKI Hiroshi	2013-01-28 15:59:54 +0900 (Mon, 28 Jan 2013)

  New Revision: 1220cf068af188ae23065e0dae8c718e54aa89b0
  https://github.com/groonga/express-kotoumi/commit/1220cf068af188ae23065e0dae8c718e54aa89b0

  Log:
    Implement Connection#close

  Modified files:
    lib/backend/connection.js
    test/backend-connection.test.js

  Modified: lib/backend/connection.js (+14 -0)
===================================================================
--- lib/backend/connection.js    2013-01-28 15:52:27 +0900 (702249b)
+++ lib/backend/connection.js    2013-01-28 15:59:54 +0900 (e9d3fee)
@@ -132,4 +132,18 @@ Connection.prototype.emitMessage = function(type, body, callback, timeout) {
   return envelope;
 };
 
+Connection.prototype.close = function() {
+  this.removeAllListeners();
+
+  if (this._sender && typeof this._sender.end == 'function') {
+    this._sender.end();
+    delete this._sender;
+  }
+
+  if (this._receiver && typeof this._receiver.close == 'function') {
+    this._receiver.close();
+    delete this._receiver;
+  }
+};
+
 exports.Connection = Connection;

  Modified: test/backend-connection.test.js (+17 -6)
===================================================================
--- test/backend-connection.test.js    2013-01-28 15:52:27 +0900 (8cd9a6a)
+++ test/backend-connection.test.js    2013-01-28 15:59:54 +0900 (a0829b5)
@@ -7,20 +7,29 @@ var TypeOf = utils.TypeOf;
 var InstanceOf = utils.InstanceOf;
 
 var Connection = require('../lib/backend/connection').Connection;
+var MsgPackReceiver = require('../lib/backend/receiver').MsgPackReceiver;
+
+suite('Connection, initialization', function() {
+  var connection;
+  teardown(function() {
+    if (connection) {
+      connection.close();
+      connection = undefined;
+    }
+  });
 
-suite('Connection (initialization)', function() {
   function assertEventEmitter(object) {
     assert.equal(typeof object, 'object');
     assert.equal(typeof object.emit, 'function');
   }
 
   test('sender', function() {
-    var connection = new Connection({ tag: 'test' });
+    connection = new Connection({ tag: 'test' });
     assertEventEmitter(connection._sender);
   });
 
   test('receiver', function(done) {
-    var connection = new Connection({ tag: 'test' });
+    connection = new Connection({ tag: 'test' });
     assertEventEmitter(connection._receiver);
     assert.equal(connection.receivePort, undefined);
 
@@ -36,7 +45,7 @@ suite('Connection (initialization)', function() {
   });
 });
 
-suite('Connection', function() {
+suite('Connection, basic features', function() {
   var connection;
   var sender;
   var receiver;
@@ -53,7 +62,10 @@ suite('Connection', function() {
   });
 
   teardown(function() {
-    connection = undefined;
+    if (connection) {
+      connection.close();
+      connection = undefined;
+    }
     sender = undefined;
     receiver = undefined;
   });
@@ -223,4 +235,3 @@ suite('Connection', function() {
       });
   });
 });
-
-------------- next part --------------
HTML����������������������������...
Download 



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