Skip to content

Commit

Permalink
THRIFT-3373: cross test cleanup
Browse files Browse the repository at this point in the history
Client: build, node, c_glib, cpp, hs, py, rb
Patch: Nobuaki Sukegawa

Github Pull Request:
This closes #641
commit 338f1a5
Author: Nobuaki Sukegawa <nsukeg@gmail.com>
Date: 2015-10-09T17:25:18Z
THRIFT-3373 Various fixes for cross test servers and clients
  • Loading branch information
RandyAbernethy committed Oct 9, 2015
1 parent f124b55 commit 983bf7d
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 161 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Expand Up @@ -49,7 +49,7 @@ empty :=
space := $(empty) $(empty)
comma := ,

CROSS_LANGS = @MAYBE_CPP@ @MAYBE_C_GLIB@ @MAYBE_JAVA@ @MAYBE_CSHARP@ @MAYBE_PYTHON@ @MAYBE_RUBY@ @MAYBE_HASKELL@ @MAYBE_PERL@ @MAYBE_PHP@ @MAYBE_GO@ @MAYBE_NODEJS@
CROSS_LANGS = @MAYBE_CPP@ @MAYBE_C_GLIB@ @MAYBE_JAVA@ @MAYBE_CSHARP@ @MAYBE_PYTHON@ @MAYBE_RUBY@ @MAYBE_HASKELL@ @MAYBE_PERL@ @MAYBE_PHP@ @MAYBE_GO@ @MAYBE_NODEJS@ @MAYBE_DART@
CROSS_LANGS_COMMA_SEPARATED = $(subst $(space),$(comma),$(CROSS_LANGS))

cross: precross
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Expand Up @@ -780,11 +780,11 @@ if test "$have_java" = "yes" ; then MAYBE_JAVA="java" ; else MAYBE_JAVA="" ; fi
AC_SUBST([MAYBE_JAVA])
if test "$have_csharp" = "yes" ; then MAYBE_CSHARP="csharp" ; else MAYBE_CSHARP="" ; fi
AC_SUBST([MAYBE_CSHARP])
if test "$have_python" = "yes" ; then MAYBE_PYTHON="python" ; else MAYBE_PYTHON="" ; fi
if test "$have_python" = "yes" ; then MAYBE_PYTHON="py" ; else MAYBE_PYTHON="" ; fi
AC_SUBST([MAYBE_PYTHON])
if test "$have_ruby" = "yes" ; then MAYBE_RUBY="rb" ; else MAYBE_RUBY="" ; fi
AC_SUBST([MAYBE_RUBY])
if test "$have_haskell" = "yes" ; then MAYBE_HASKELL="haskell" ; else MAYBE_HASKELL="" ; fi
if test "$have_haskell" = "yes" ; then MAYBE_HASKELL="hs" ; else MAYBE_HASKELL="" ; fi
AC_SUBST([MAYBE_HASKELL])
if test "$have_perl" = "yes" ; then MAYBE_PERL="perl" ; else MAYBE_PERL="" ; fi
AC_SUBST([MAYBE_PERL])
Expand Down
7 changes: 4 additions & 3 deletions lib/nodejs/test/client.js
Expand Up @@ -118,11 +118,12 @@ if (type === 'tcp') {
function runTests() {
testDriver(client, function (status) {
console.log(status);
if (type === 'http' || type === 'websocket') {
process.exit(0);
} else {
if (type !== 'http' && type !== 'websocket') {
connection.end();
}
if (type !== 'multiplex') {
process.exit(0);
}
});
}

Expand Down
6 changes: 5 additions & 1 deletion lib/nodejs/test/test-cases.js
Expand Up @@ -76,9 +76,12 @@ for (var i = 0; i < 5; ++i) {
}

var deep = [
['testList', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]],
];

var deepUnordered = [
['testMap', mapout],
['testSet', [1,2,3]],
['testList', [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]],
['testStringMap', mapTestInput]
];

Expand Down Expand Up @@ -133,6 +136,7 @@ var insanity = {
module.exports.simple = simple;
module.exports.simpleLoose = simpleLoose;
module.exports.deep = deep;
module.exports.deepUnordered = deepUnordered;

module.exports.out = out;
module.exports.out2 = out2;
Expand Down
19 changes: 19 additions & 0 deletions lib/nodejs/test/test_driver.js
Expand Up @@ -55,6 +55,7 @@ exports.ThriftTestDriver = function(client, callback) {
assert.ok(a == e, m);
}));
testCases.deep.forEach(makeAsserter(assert.deepEqual));
testCases.deepUnordered.forEach(makeAsserter(makeUnorderedDeepEqual(assert)));

client.testMapMap(42, function(err, response) {
var expected = {
Expand Down Expand Up @@ -147,6 +148,7 @@ exports.ThriftTestDriverPromise = function(client, callback) {
assert.ok(a == e, m);
}));
testCases.deep.forEach(makeAsserter(assert.deepEqual));
testCases.deepUnordered.forEach(makeAsserter(makeUnorderedDeepEqual(assert)));

client.testStruct(testCases.out)
.then(function(response) {
Expand Down Expand Up @@ -281,3 +283,20 @@ function checkOffByOne(done, callback) {

setTimeout(TestForCompletion, retry_interval);
}

function makeUnorderedDeepEqual(assert) {
return function(actual, expected, name) {
assert.equal(actual.length, expected.length, name);
for (var k in actual) {
var found = false;
for (var k2 in expected) {
if (actual[k] === expected[k2]) {
found = true;
}
}
if (!found) {
assert.fail('Unexpected value ' + actual[k] + ' with key ' + k);
}
}
};
}
13 changes: 1 addition & 12 deletions lib/nodejs/test/test_handler.js
Expand Up @@ -62,6 +62,7 @@ var identityHandlers = [
'testI32',
'testI64',
'testDouble',
'testBinary',
'testStruct',
'testNest',
'testMap',
Expand Down Expand Up @@ -101,18 +102,6 @@ function testInsanity(argument) {
//console.log(argument);
//console.log(')');

var hello = new ttypes.Xtruct();
hello.string_thing = 'Hello2';
hello.byte_thing = 2;
hello.i32_thing = 2;
hello.i64_thing = 2;

var goodbye = new ttypes.Xtruct();
goodbye.string_thing = 'Goodbye4';
goodbye.byte_thing = 4;
goodbye.i32_thing = 4;
goodbye.i64_thing = 4;

var first_map = [];
var second_map = [];

Expand Down
2 changes: 1 addition & 1 deletion test/c_glib/Makefile.am
Expand Up @@ -29,7 +29,7 @@ nodist_libtestcglib_la_SOURCES = \

libtestcglib_la_LIBADD = $(top_builddir)/lib/c_glib/libthrift_c_glib.la

precross: test_client test_server
precross: libtestcglib.la test_client test_server

check_PROGRAMS = \
test_client \
Expand Down
14 changes: 9 additions & 5 deletions test/c_glib/src/thrift_test_handler.c
Expand Up @@ -68,7 +68,7 @@ thrift_test_handler_test_bool (TTestThriftTestIf *iface,
THRIFT_UNUSED_VAR (iface);
THRIFT_UNUSED_VAR (error);

printf ("testByte(%s)\n", thing ? "true" : "false");
printf ("testBool(%s)\n", thing ? "true" : "false");
*_return = thing;

return TRUE;
Expand Down Expand Up @@ -144,7 +144,7 @@ thrift_test_handler_test_binary (TTestThriftTestIf *iface,
THRIFT_UNUSED_VAR (error);

printf ("testBinary()\n"); // TODO: hex output
g_byte_array_append( *_return, thing->data, thing->len);
*_return = thing;

return TRUE;
}
Expand Down Expand Up @@ -701,16 +701,17 @@ thrift_test_handler_test_multi_exception (TTestThriftTestIf *iface,
g_assert (*err1 == NULL);
g_assert (*err2 == NULL);

if (strncmp (arg0, "Xception", 9) == 0) {
if (strncmp (arg0, "Xception", 8) == 0 && strlen(arg0) == 8) {
*err1 = g_object_new (T_TEST_TYPE_XCEPTION,
"errorCode", 1001,
"message", g_strdup ("This is an Xception"),
NULL);
result = FALSE;
}
else if (strncmp (arg0, "Xception2", 10) == 0) {
else if (strncmp (arg0, "Xception2", 9) == 0) {
*err2 = g_object_new (T_TEST_TYPE_XCEPTION2,
"errorCode", 2002);
"errorCode", 2002,
NULL);

g_object_get (*err2,
"struct_thing", &struct_thing,
Expand Down Expand Up @@ -783,6 +784,9 @@ thrift_test_handler_class_init (ThriftTestHandlerClass *klass)
base_class->test_double =
klass->test_double =
thrift_test_handler_test_double;
base_class->test_binary =
klass->test_binary =
thrift_test_handler_test_binary;
base_class->test_struct =
klass->test_struct =
thrift_test_handler_test_struct;
Expand Down
4 changes: 4 additions & 0 deletions test/c_glib/src/thrift_test_handler.h
Expand Up @@ -86,6 +86,10 @@ struct _ThriftTestHandlerClass {
gdouble*_return,
const gdouble thing,
GError **error);
gboolean (*test_binary) (TTestThriftTestIf *iface,
GByteArray **_return,
const GByteArray *thing,
GError **error);
gboolean (*test_struct) (TTestThriftTestIf *iface,
TTestXtruct **_return,
const TTestXtruct *thing,
Expand Down
4 changes: 2 additions & 2 deletions test/cpp/Makefile.am
Expand Up @@ -100,10 +100,10 @@ StressTestNonBlocking_LDADD = \
#
THRIFT = $(top_builddir)/compiler/cpp/thrift

gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_constants.cpp: $(top_srcdir)/test/ThriftTest.thrift
gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_constants.cpp: $(top_srcdir)/test/ThriftTest.thrift $(THRIFT)
$(THRIFT) --gen cpp:templates,cob_style -r $<

gen-cpp/StressTest_types.cpp gen-cpp/StressTest_constants.cpp gen-cpp/Service.cpp: $(top_srcdir)/test/StressTest.thrift
gen-cpp/StressTest_types.cpp gen-cpp/StressTest_constants.cpp gen-cpp/Service.cpp: $(top_srcdir)/test/StressTest.thrift $(THRIFT)
$(THRIFT) --gen cpp $<

AM_CPPFLAGS = $(BOOST_CPPFLAGS) $(LIBEVENT_CPPFLAGS) -I$(top_srcdir)/lib/cpp/src -Igen-cpp
Expand Down
2 changes: 1 addition & 1 deletion test/hs/Makefile.am
Expand Up @@ -19,7 +19,7 @@

THRIFT = $(top_builddir)/compiler/cpp/thrift

stubs: ../ConstantsDemo.thrift ../DebugProtoTest.thrift ../ThriftTest.thrift ../Include.thrift
stubs: $(THRIFT) ../ConstantsDemo.thrift ../DebugProtoTest.thrift ../ThriftTest.thrift ../Include.thrift
$(THRIFT) --gen hs ../ConstantsDemo.thrift
$(THRIFT) --gen hs ../DebugProtoTest.thrift
$(THRIFT) --gen hs ../ThriftTest.thrift
Expand Down

0 comments on commit 983bf7d

Please sign in to comment.