[Groonga-commit] groonga/express-kotoumi [master] Ignore negative timeout

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Jan 23 18:16:16 JST 2013


YUKI Hiroshi	2013-01-23 18:16:16 +0900 (Wed, 23 Jan 2013)

  New Revision: 6f11180b47509b4877f5b41ae67e664982ea1f37
  https://github.com/groonga/express-kotoumi/commit/6f11180b47509b4877f5b41ae67e664982ea1f37

  Log:
    Ignore negative timeout

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

  Modified: lib/backend-adaptor.js (+12 -0)
===================================================================
--- lib/backend-adaptor.js    2013-01-23 18:07:45 +0900 (8978b20)
+++ lib/backend-adaptor.js    2013-01-23 18:16:16 +0900 (105da2b)
@@ -116,6 +116,17 @@ function getCurrentTime() {
   return new Date().toISOString();
 }
 
+function toPositiveInteger(number) {
+  if (!number)
+    return 0;
+
+  var integer = parseInt(number);
+  if (isNaN(integer))
+    return 0;
+
+  return Math.max(integer, 0);
+}
+
 Connection.prototype.emitMessage = function(type, body, callback, timeout) {
   var id = createId();
   var envelope = {
@@ -129,6 +140,7 @@ Connection.prototype.emitMessage = function(type, body, callback, timeout) {
   if (callback) {
     var event = 'inReplyTo:' + id;
     this.once(event, callback);
+    timeout = toPositiveInteger(timeout);
     if (timeout) {
       setTimeout((function() {
         if (this.listeners(event)) {

  Modified: test/backend-adaptor.test.js (+23 -0)
===================================================================
--- test/backend-adaptor.test.js    2013-01-23 18:07:45 +0900 (5a3646a)
+++ test/backend-adaptor.test.js    2013-01-23 18:16:16 +0900 (e0702d5)
@@ -172,5 +172,28 @@ suite('Connection', function() {
         done(error);
       });
   });
+
+  test('sending message with one response, timeout (ignored negative timeout)', function() {
+    var callback = createMockedMessageCallback();
+    var message = connection.emitMessage('testRequest', { command: 'foobar' }, callback, -1);
+    assert.envelopeEqual(message,
+                         createExpectedEnvelope('testRequest', { command: 'foobar' }));
+    sender.assertSent('message', message);
+    assert.equal(connection.listeners('inReplyTo:' + message.id).length, 1);
+
+    var response = createReplyEnvelopeFor(message, 'testResponse', 'first call');
+    callback.takes(null, response);
+    Deferred
+      .wait(0.01)
+      .next(function() {
+        receiver.emitMessage(response);
+        callback.assert();
+        assert.equal(connection.listeners('inReplyTo:' + message.id).length, 0);
+        done();
+      })
+      .error(function(error) {
+        done(error);
+      });
+  });
 });
 
-------------- next part --------------
HTML����������������������������...
다운로드 



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