THRIFT-2313 nodejs server crash after processing the first request when using MultiplexedProcessor/FramedBuffer/BinaryProtocol

patch: Pierre Lamot
This commit is contained in:
henrique 2014-01-14 15:17:04 +01:00
parent a16737a87f
commit 216374ec4a
5 changed files with 288 additions and 222 deletions

View File

@ -19,11 +19,11 @@
var Thrift = require('./thrift');
var MultiplexedProcessor = exports.MultiplexedProcessor = function(stream, options) {
this.services = new Map();
this.services = {};
};
MultiplexedProcessor.prototype.registerProcessor = function(name, handler) {
this.services.set(name, handler);
this.services[name] = handler;
};
MultiplexedProcessor.prototype.process = function(inp, out) {
@ -38,7 +38,7 @@ MultiplexedProcessor.prototype.process = function(inp, out) {
var sname = p[0];
var fname = p[1];
if (!this.services.has(sname)) {
if (! sname in this.services) {
throw new Thrift.TException("TMultiplexedProcessor: Unknown service: " + sname);
}
@ -56,6 +56,6 @@ MultiplexedProcessor.prototype.process = function(inp, out) {
};
};
this.services.get(sname).process(inpProxy, out);
this.services[sname].process(inpProxy, out);
};

View File

@ -90,7 +90,14 @@ TFramedTransport.prototype = {
open: function() {},
close: function() {},
ensureAvailable: function(len) {
if (this.readPos + len > this.inBuf.length) {
throw new InputBufferUnderrunError();
}
},
read: function(len) { // this function will be used for each frames.
this.ensureAvailable(len);
var end = this.readPos + len;
if (this.inBuf.length < end) {
@ -103,28 +110,33 @@ TFramedTransport.prototype = {
},
readByte: function() {
this.ensureAvailable(1);
return binary.readByte(this.inBuf[this.readPos++]);
},
readI16: function() {
this.ensureAvailable(2);
var i16 = binary.readI16(this.inBuf, this.readPos);
this.readPos += 2;
return i16;
},
readI32: function() {
this.ensureAvailable(4);
var i32 = binary.readI32(this.inBuf, this.readPos);
this.readPos += 4;
return i32;
},
readDouble: function() {
this.ensureAvailable(8);
var d = binary.readDouble(this.inBuf, this.readPos);
this.readPos += 8;
return d;
},
readString: function(len) {
this.ensureAvailable(len);
var str = this.inBuf.toString('utf8', this.readPos, this.readPos + len);
this.readPos += len;
return str;

View File

@ -50,7 +50,7 @@ client:
NODE_PATH=../../lib/nodejs/lib:../../lib/nodejs/lib/thrift:$(NODE_PATH) node client.js
mserver:
NODE_PATH=../../lib/nodejs/lib:../../lib/nodejs/lib/thrift:$(NODE_PATH) node --harmony multiplex_server.js
NODE_PATH=../../lib/nodejs/lib:../../lib/nodejs/lib/thrift:$(NODE_PATH) node multiplex_server.js
mclient:
NODE_PATH=../../lib/nodejs/lib:../../lib/nodejs/lib/thrift:$(NODE_PATH) node --harmony multiplex_client.js
NODE_PATH=../../lib/nodejs/lib:../../lib/nodejs/lib/thrift:$(NODE_PATH) node multiplex_client.js

View File

@ -78,7 +78,31 @@ client.testString("", function(err, response) {
});
// all Languages in UTF-8
var stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, Bahasa Melayu, مازِرونی, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, Occitan, Иронау, Papiamentu, Deitsch, Norfuk / Pitkern, Polski, پنجابی, پښتو, Português, Runa Simi, Rumantsch, Romani, Română, Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, Bân-lâm-gú, 粵語";
var stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " +
"Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " +
"Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, বাংলা, " +
"Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, Cebuano, ᏣᎳᎩ, " +
"Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, Dansk, Zazaki, " +
"ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, Esperanto, " +
"Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, Français, " +
"Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, Avañe'ẽ, " +
"ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, Kreyòl ayisyen, " +
"Magyar, Հայերեն, Interlingua, Bahasa Indonesia, Ilokano, Ido, " +
"Íslenska, Italiano, 日本語, Lojban, Basa Jawa, ქართული, Kongo, " +
"Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, Ripoarisch, Kurdî, Коми, " +
"Kernewek, Кыргызча, Latina, Ladino, Lëtzebuergesch, Limburgs, " +
"Lingála, ລາວ, Lietuvių, Latviešu, Basa Banyumasan, Malagasy, " +
"Македонски, മലയാളം, मराठी, Bahasa Melayu, مازِرونی, Nnapulitano, " +
"Nedersaksisch, नेपाल भाषा, Nederlands, Norsk (nynorsk), Norsk (" +
"bokmål), Nouormand, Diné bizaad, Occitan, Иронау, Papiamentu, " +
"Deitsch, Norfuk / Pitkern, Polski, پنجابی, پښتو, Português, Runa " +
"Simi, Rumantsch, Romani, Română, Русский, Саха тыла, Sardu, " +
"Sicilianu, Scots, Sámegiella, Simple English, Slovenčina, " +
"Slovenščina, Српски / Srpski, Seeltersk, Svenska, Kiswahili, தமிழ், " +
"తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, Türkçe, Татарча/Tatarça, " +
"Українська, اردو, Tiếng Việt, Volapük, Walon, Winaray, 吴语, isiXhosa, " +
"ייִדיש, Yorùbá, Zeêuws, 中文, Bân-lâm-gú, 粵語";
client.testString(stringTest, function(err, response) {
assert(!err);
assert.equal(stringTest, response);

View File

@ -31,244 +31,274 @@ var ttypes = require('./gen-nodejs/ThriftTest_types');
var ThriftTestDriver = exports.ThriftTestDriver = function(client, callback) {
// deepEqual doesn't work with fields using node-int64
function checkRecursively(map1, map2) {
if (typeof map1 !== 'function' && typeof map2 !== 'function') {
if (!map1 || typeof map1 !== 'object') {
assert.equal(map1, map2);
} else {
for (var key in map1) {
checkRecursively(map1[key], map2[key]);
}
}
}
}
// deepEqual doesn't work with fields using node-int64
function checkRecursively(map1, map2) {
if (typeof map1 !== 'function' && typeof map2 !== 'function') {
if (!map1 || typeof map1 !== 'object') {
assert.equal(map1, map2);
} else {
for (var key in map1) {
checkRecursively(map1[key], map2[key]);
}
}
}
}
client.testVoid(function(err, response) {
assert( ! err);
assert.equal(undefined, response); //void
});
client.testVoid(function(err, response) {
assert( ! err);
assert.equal(undefined, response); //void
});
client.testString("Test", function(err, response) {
assert( ! err);
assert.equal("Test", response);
});
client.testString("Test", function(err, response) {
assert( ! err);
assert.equal("Test", response);
});
client.testString("", function(err, response) {
assert( ! err);
assert.equal("", response);
});
client.testString("", function(err, response) {
assert( ! err);
assert.equal("", response);
});
//all Languages in UTF-8
var stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, Bahasa Melayu, مازِرونی, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, Occitan, Иронау, Papiamentu, Deitsch, Norfuk / Pitkern, Polski, پنجابی, پښتو, Português, Runa Simi, Rumantsch, Romani, Română, Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, Bân-lâm-gú, 粵語";
client.testString(stringTest, function(err, response) {
assert( ! err);
assert.equal(stringTest, response);
});
//all Languages in UTF-8
var stringTest = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " +
"Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " +
"Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " +
"বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " +
"Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, " +
"Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, " +
"Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, " +
"Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, " +
"Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, " +
"Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, " +
"Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, " +
"ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, " +
"Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " +
"Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " +
"Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " +
"Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, " +
"Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, " +
"Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " +
"Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " +
"Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple " +
"English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, " +
"Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, " +
"Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " +
"Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " +
"Bân-lâm-gú, 粵語";
var specialCharacters = 'quote: \" backslash:' +
' forwardslash-escaped: \/ ' +
' backspace: \b formfeed: \f newline: \n return: \r tab: ' +
' now-all-of-them-together: "\\\/\b\n\r\t' +
' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><' +
' char-to-test-json-parsing: ]] \"]] \\" }}}{ [[[ ';
client.testString(specialCharacters, function(err, response) {
assert( ! err);
assert.equal(specialCharacters, response);
});
client.testString(stringTest, function(err, response) {
assert( ! err);
assert.equal(stringTest, response);
});
var specialCharacters = 'quote: \" backslash:' +
' forwardslash-escaped: \/ ' +
' backspace: \b formfeed: \f newline: \n return: \r tab: ' +
' now-all-of-them-together: "\\\/\b\n\r\t' +
' now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><' +
' char-to-test-json-parsing: ]] \"]] \\" }}}{ [[[ ';
client.testString(specialCharacters, function(err, response) {
assert( ! err);
assert.equal(specialCharacters, response);
});
client.testByte(1, function(err, response) {
assert( ! err);
assert.equal(1, response);
});
client.testByte(0, function(err, response) {
assert( ! err);
assert.equal(0, response);
});
client.testByte(-1, function(err, response) {
assert( ! err);
assert.equal(-1, response);
});
client.testByte(-127, function(err, response) {
assert( ! err);
assert.equal(-127, response);
});
client.testByte(1, function(err, response) {
assert( ! err);
assert.equal(1, response);
});
client.testI32(-1, function(err, response) {
assert( ! err);
assert.equal(-1, response);
});
client.testByte(0, function(err, response) {
assert( ! err);
assert.equal(0, response);
});
client.testI64(5, function(err, response) {
assert( ! err);
assert.equal(5, response);
});
client.testI64(-5, function(err, response) {
assert( ! err);
assert.equal(-5, response);
});
client.testI64(-34359738368, function(err, response) {
assert( ! err);
assert.equal(-34359738368, response);
});
client.testByte(-1, function(err, response) {
assert( ! err);
assert.equal(-1, response);
});
client.testDouble(-5.2098523, function(err, response) {
assert( ! err);
assert.equal(-5.2098523, response);
});
client.testDouble(7.012052175215044, function(err, response) {
assert( ! err);
assert.equal(7.012052175215044, response);
});
client.testByte(-127, function(err, response) {
assert( ! err);
assert.equal(-127, response);
});
var out = new ttypes.Xtruct({
string_thing: 'Zero',
byte_thing: 1,
i32_thing: -3,
i64_thing: 1000000
});
client.testStruct(out, function(err, response) {
assert( ! err);
checkRecursively(out, response);
});
client.testI32(-1, function(err, response) {
assert( ! err);
assert.equal(-1, response);
});
var out2 = new ttypes.Xtruct2();
out2.byte_thing = 1;
out2.struct_thing = out;
out2.i32_thing = 5;
client.testNest(out2, function(err, response) {
assert( ! err);
checkRecursively(out2, response);
});
client.testI64(5, function(err, response) {
assert( ! err);
assert.equal(5, response);
});
var mapout = {};
for (var i = 0; i < 5; ++i) {
mapout[i] = i-10;
}
client.testMap(mapout, function(err, response) {
assert( ! err);
assert.deepEqual(mapout, response);
});
client.testI64(-5, function(err, response) {
assert( ! err);
assert.equal(-5, response);
});
var mapTestInput = {
"a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key",
"longValue":stringTest, stringTest:"long key"
};
client.testStringMap(mapTestInput, function(err, response) {
assert( ! err);
assert.deepEqual(mapTestInput, response);
});
client.testI64(-34359738368, function(err, response) {
assert( ! err);
assert.equal(-34359738368, response);
});
var setTestInput = [1,2,3];
client.testSet(setTestInput, function(err, response) {
assert( ! err);
assert.deepEqual(setTestInput, response);
});
client.testList(setTestInput, function(err, response) {
assert( ! err);
assert.deepEqual(setTestInput, response);
});
client.testDouble(-5.2098523, function(err, response) {
assert( ! err);
assert.equal(-5.2098523, response);
});
client.testEnum(ttypes.Numberz.ONE, function(err, response) {
assert( ! err);
assert.equal(ttypes.Numberz.ONE, response);
});
client.testDouble(7.012052175215044, function(err, response) {
assert( ! err);
assert.equal(7.012052175215044, response);
});
client.testTypedef(69, function(err, response) {
assert( ! err);
assert.equal(69, response);
});
var out = new ttypes.Xtruct({
string_thing: 'Zero',
byte_thing: 1,
i32_thing: -3,
i64_thing: 1000000
});
client.testStruct(out, function(err, response) {
assert( ! err);
checkRecursively(out, response);
});
var mapMapTest = {
"4": {"1":1, "2":2, "3":3, "4":4},
"-4": {"-4":-4, "-3":-3, "-2":-2, "-1":-1}
};
client.testMapMap(mapMapTest, function(err, response) {
assert( ! err);
assert.deepEqual(mapMapTest, response);
});
var out2 = new ttypes.Xtruct2();
out2.byte_thing = 1;
out2.struct_thing = out;
out2.i32_thing = 5;
client.testNest(out2, function(err, response) {
assert( ! err);
checkRecursively(out2, response);
});
var crazy = new ttypes.Insanity({
"userMap":{ "5":5, "8":8 },
"xtructs":[new ttypes.Xtruct({
"string_thing":"Goodbye4",
"byte_thing":4,
"i32_thing":4,
"i64_thing":4
}), new ttypes.Xtruct({
"string_thing":"Hello2",
"byte_thing":2,
"i32_thing":2,
"i64_thing":2
})]
});
var insanity = {
"1":{ "2": crazy, "3": crazy },
"2":{ "6":{ "userMap":null, "xtructs":null } }
};
client.testInsanity(crazy, function(err, response) {
assert( ! err);
checkRecursively(insanity, response);
});
var mapout = {};
for (var i = 0; i < 5; ++i) {
mapout[i] = i-10;
}
client.testMap(mapout, function(err, response) {
assert( ! err);
assert.deepEqual(mapout, response);
});
client.testException('TException', function(err, response) {
assert( ! response);
});
var mapTestInput = {
"a":"123", "a b":"with spaces ", "same":"same", "0":"numeric key",
"longValue":stringTest, stringTest:"long key"
};
client.testStringMap(mapTestInput, function(err, response) {
assert( ! err);
assert.deepEqual(mapTestInput, response);
});
client.testException('Xception', function(err, response) {
assert( ! response);
assert.equal(err.errorCode, 1001);
assert.equal('Xception', err.message);
});
var setTestInput = [1,2,3];
client.testSet(setTestInput, function(err, response) {
assert( ! err);
assert.deepEqual(setTestInput, response);
});
client.testList(setTestInput, function(err, response) {
assert( ! err);
assert.deepEqual(setTestInput, response);
});
client.testException('no Exception', function(err, response) {
assert( ! err);
assert.equal(undefined, response); //void
});
client.testEnum(ttypes.Numberz.ONE, function(err, response) {
assert( ! err);
assert.equal(ttypes.Numberz.ONE, response);
});
client.testOneway(0, function(err, response) {
assert(false); //should not answer
});
client.testTypedef(69, function(err, response) {
assert( ! err);
assert.equal(69, response);
});
(function() {
var test_complete = false;
var retrys = 0;
var retry_limit = 30;
var retry_interval = 100;
/**
* redo a simple test after the oneway to make sure we aren't "off by one" --
* if the server treated oneway void like normal void, this next test will
* fail since it will get the void confirmation rather than the correct
* result. In this circumstance, the client will throw the exception:
*
* Because this is the last test against the server, when it completes
* the entire suite is complete by definition (the tests run serially).
*/
client.testI32(-1, function(err, response) {
assert( ! err);
assert.equal(-1, response);
test_complete = true;
});
var mapMapTest = {
"4": {"1":1, "2":2, "3":3, "4":4},
"-4": {"-4":-4, "-3":-3, "-2":-2, "-1":-1}
};
client.testMapMap(mapMapTest, function(err, response) {
assert( ! err);
assert.deepEqual(mapMapTest, response);
});
//We wait up to retry_limit * retry_interval for the test suite to complete
function TestForCompletion() {
if(test_complete) {
if (callback) {
callback("Server successfully tested!");
}
} else {
if (++retrys < retry_limit) {
setTimeout(TestForCompletion, retry_interval);
} else {
if (callback) {
callback("Server test failed to complete after " +
(retry_limit*retry_interval/1000) + " seconds");
}
}
}
}
var crazy = new ttypes.Insanity({
"userMap":{ "5":5, "8":8 },
"xtructs":[new ttypes.Xtruct({
"string_thing":"Goodbye4",
"byte_thing":4,
"i32_thing":4,
"i64_thing":4
}), new ttypes.Xtruct({
"string_thing":"Hello2",
"byte_thing":2,
"i32_thing":2,
"i64_thing":2
})]
});
var insanity = {
"1":{ "2": crazy, "3": crazy },
"2":{ "6":{ "userMap":null, "xtructs":null } }
};
client.testInsanity(crazy, function(err, response) {
assert( ! err);
checkRecursively(insanity, response);
});
setTimeout(TestForCompletion, retry_interval);
})();
}
client.testException('TException', function(err, response) {
assert( ! response);
});
client.testException('Xception', function(err, response) {
assert( ! response);
assert.equal(err.errorCode, 1001);
assert.equal('Xception', err.message);
});
client.testException('no Exception', function(err, response) {
assert( ! err);
assert.equal(undefined, response); //void
});
client.testOneway(0, function(err, response) {
assert(false); //should not answer
});
(function() {
var test_complete = false;
var retrys = 0;
var retry_limit = 30;
var retry_interval = 100;
/**
* redo a simple test after the oneway to make sure we aren't "off by one" --
* if the server treated oneway void like normal void, this next test will
* fail since it will get the void confirmation rather than the correct
* result. In this circumstance, the client will throw the exception:
*
* Because this is the last test against the server, when it completes
* the entire suite is complete by definition (the tests run serially).
*/
client.testI32(-1, function(err, response) {
assert( ! err);
assert.equal(-1, response);
test_complete = true;
});
//We wait up to retry_limit * retry_interval for the test suite to complete
function TestForCompletion() {
if(test_complete) {
if (callback) {
callback("Server successfully tested!");
}
} else {
if (++retrys < retry_limit) {
setTimeout(TestForCompletion, retry_interval);
} else {
if (callback) {
callback("Server test failed to complete after " +
(retry_limit*retry_interval/1000) + " seconds");
}
}
}
}
setTimeout(TestForCompletion, retry_interval);
})();
}