diff --git a/tests/cdb2api_tests.test/runit b/tests/cdb2api_tests.test/runit index c9c5002cbc..41eca2b0d9 100755 --- a/tests/cdb2api_tests.test/runit +++ b/tests/cdb2api_tests.test/runit @@ -1,4 +1,17 @@ #!/usr/bin/env bash bash -n "$0" | exit 1 +cfg=$DBDIR/comdb2db.cfg +echo 'comdb2_feature:discard_unread_socket_data=on' >> ${cfg} +echo 'comdb2_config:max_local_connection_cache_entries=4' >> ${cfg} +echo 'comdb2_config:max_local_connection_cache_age=10' >> ${cfg} +echo 'comdb2_config:local_connection_cache_use_sbuf=1' >> ${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}" +sed -i '/comdb2_config:max_local_connection_cache_entries=4/d' "${cfg}" +sed -i '/comdb2_config:max_local_connection_cache_age=10/d' "${cfg}" +sed -i '/comdb2_config:local_connection_cache_use_sbuf=1/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..ff9f29da37 --- /dev/null +++ b/tests/tools/cdb2api_unread_data.cpp @@ -0,0 +1,57 @@ +#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); + + int rc = test_unread_record(db, "default"); + + return rc; +}