diff --git a/cdb2api/cdb2api.c b/cdb2api/cdb2api.c index 42a0f8deb7..7e2aef060f 100644 --- a/cdb2api/cdb2api.c +++ b/cdb2api/cdb2api.c @@ -3193,7 +3193,11 @@ void cdb2_socket_pool_donate_ext(const cdb2_hndl_tp *hndl, const char *typestr, close(sockpool_fd); sockpool_fd = -1; } + } else if (sockpool_fd != -1) { + fprintf(stderr, "%s: typestr too long to donate to sockpool, length %ld max %ld\n", __func__, + strlen(typestr), sizeof(msg.typestr) - 1); } + if (sockpool_fd != -1) { pthread_mutex_lock(&cdb2_sockpool_mutex); int closeit = 0; diff --git a/tests/api_tests.test/runit b/tests/api_tests.test/runit deleted file mode 100755 index c9c5002cbc..0000000000 --- a/tests/api_tests.test/runit +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -bash -n "$0" | exit 1 - -exit 0 diff --git a/tests/api_tests.test/Makefile b/tests/api_tst.test/Makefile similarity index 100% rename from tests/api_tests.test/Makefile rename to tests/api_tst.test/Makefile diff --git a/tests/api_tst.test/runit b/tests/api_tst.test/runit new file mode 100755 index 0000000000..d4332fd940 --- /dev/null +++ b/tests/api_tst.test/runit @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +bash -n "$0" | exit 1 + +pgrep cdb2sockpool +if [ $? -ne 0 ]; then + echo 'SOCKPOOL IS REQUIRED TO RUN THE TEST BUT IS NOT RUNNING.' >&2 + echo 'TRYING TO BRING IT UP' + ${BUILDDIR}/tools/cdb2sockpool/cdb2sockpool + sleep 1 + pgrep cdb2sockpool + if [ $? -ne 0 ]; then + echo 'FAILED BRINGING UP SOCKPOOL' >&2 + exit 1 + fi +fi + + +cfg=$DBDIR/comdb2db.cfg +echo 'comdb2_feature:discard_unread_socket_data=on' >> ${cfg} +${TESTSBUILDDIR}/cdb2api_unread_data ${DBNAME} +[[ $? -ne 0 ]] && echo "cdb2api_unread_data - fail" && exit 1 +sed -i '/comdb2_feature:discard_unread_socket_data=on/d' "${cfg}" +echo 'cdb2api_unread_data - pass' + +exit 0 diff --git a/tests/tools/CMakeLists.txt b/tests/tools/CMakeLists.txt index 49e9f0b6ee..bd3b1d46dd 100644 --- a/tests/tools/CMakeLists.txt +++ b/tests/tools/CMakeLists.txt @@ -37,6 +37,7 @@ add_exe(cdb2api_chunk cdb2api_chunk.cpp) add_exe(cdb2api_drain cdb2api_drain.cpp) add_exe(cdb2api_effects_on_chunk_error cdb2api_effects_on_chunk_error.c) add_exe(cdb2api_read_intrans_results cdb2api_read_intrans_results.c) +add_exe(cdb2api_unread_data cdb2api_unread_data.cpp) add_exe(cdb2bind cdb2bind.c) add_exe(cldeadlock cldeadlock.c) add_exe(close_old_connections close_old_connections.c) diff --git a/tests/tools/cdb2api_unread_data.cpp b/tests/tools/cdb2api_unread_data.cpp new file mode 100644 index 0000000000..616cd49841 --- /dev/null +++ b/tests/tools/cdb2api_unread_data.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include + +int test_unread_record(char *dbname, char *type) +{ + int rc = 0; + + cdb2_hndl_tp *cdb2h = NULL; + int num_connects = get_num_tcp_connects(); + num_connects++; // Expect atleast 1 connect + + for (int i =0; i < 1000; i++) { + rc = cdb2_open(&cdb2h, dbname, type, 0); + if (rc != CDB2_OK) { + fprintf(stderr, "%s Failed to open db %s rc=%d errstr=%s\n", __func__, dbname, rc, cdb2_errstr(cdb2h)); + return -1; + } + rc = cdb2_run_statement(cdb2h, "select 1"); + if (rc != CDB2_OK) { + fprintf(stderr, "%s Failed to run statement rc=%d errstr=%s\n", __func__, rc, cdb2_errstr(cdb2h)); + return -1; + } + rc = cdb2_next_record (cdb2h); + if (rc != CDB2_OK) { + fprintf(stderr, "%s Failed to get record rc=%d errstr=%s\n", __func__, rc, cdb2_errstr(cdb2h)); + return -1; + } + rc = cdb2_close(cdb2h); + if (rc != CDB2_OK) { + fprintf(stderr, "%s Failed to close db rc=%d errstr=%s\n", __func__, rc, cdb2_errstr(cdb2h)); + return -1; + } + } + + if (get_num_tcp_connects() > num_connects + 2) { + fprintf(stderr, "%s Failed: expected connects: %d got: %d\n", __func__, num_connects, get_num_tcp_connects()); + return -1; + } + + return 0; +} + + +int main(int argc, char **argv) +{ + signal(SIGPIPE, SIG_IGN); + char *db = argv[1]; + char *conf = getenv("CDB2_CONFIG"); + if (conf) + cdb2_set_comdb2db_config(conf); + + cdb2_enable_sockpool(); + + int rc = test_unread_record(db, "default"); + + return rc; +}