Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/api_tst.test/runit
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ ${TESTSBUILDDIR}/cdb2api_localcache_systable ${DBNAME}
[[ $? -ne 0 ]] && echo "cdb2api_localcache_systable - fail" && exit 1
echo 'cdb2api_localcache_systable - pass'

${TESTSBUILDDIR}/cdb2api_sockpooltimeout ${DBNAME}
[[ $? -ne 0 ]] && echo "cdb2api_sockpooltimeout - fail" && exit 1
echo 'cdb2api_sockpooltimeout - pass'

echo 'comdb2_feature:discard_unread_socket_data=on' >> ${cfg}
${TESTSBUILDDIR}/cdb2api_unread_data ${DBNAME}
[[ $? -ne 0 ]] && echo "cdb2api_unread_data - fail" && exit 1
Expand Down
1 change: 1 addition & 0 deletions tests/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ add_exe(cdb2api_localcache_systable cdb2api_localcache_systable.cpp)
add_exe(cdb2api_read_intrans_results cdb2api_read_intrans_results.c)
add_exe(cdb2api_rte cdb2api_rte.cpp)
add_exe(cdb2api_setoptions cdb2api_setoptions.cpp)
add_exe(cdb2api_sockpooltimeout cdb2api_sockpooltimeout.cpp)
add_exe(cdb2api_sptrace cdb2api_sptrace.cpp)
add_exe(cdb2api_stmt_return_types cdb2api_stmt_return_types.cpp)
add_exe(cdb2api_string_escape cdb2api_string_escape.cpp)
Expand Down
114 changes: 114 additions & 0 deletions tests/tools/cdb2api_sockpooltimeout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#undef NDEBUG
#include <assert.h>
#include <libgen.h>
#include <signal.h>
#include <stdio.h>
#include <time.h>

#include <cdb2api.h>
#include <cdb2api_test.h>

static void sockpool_prod_timeout_test(const char *db)
{
int rc;
cdb2_effects_tp effects;
cdb2_hndl_tp *hndl = NULL;

// Should fail "quickly"
time_t start_time = time(NULL);
rc = cdb2_open(&hndl, db, "prod", 0);
time_t end_time = time(NULL);
printf("Total open time=%ld\n", end_time - start_time);
assert(rc != 0 && (end_time - start_time) < 10);
}

// Just a simple select 1
static void sockpool_test(const char *db, int line)
{
int rc;
cdb2_effects_tp effects;
cdb2_hndl_tp *hndl = NULL;

rc = cdb2_open(&hndl, db, "default", 0);
if (rc)
fprintf(stderr, "Line %d: open rc=%d errstr=%s\n", line, rc,
cdb2_errstr(hndl));
assert(rc == 0);

rc = cdb2_run_statement(hndl, "select 1");
if (rc)
fprintf(stderr, "Line %d: run_statement rc=%d errstr=%s\n", line, rc,
cdb2_errstr(hndl));
assert(rc == 0);

while ((rc = cdb2_next_record(hndl)) == CDB2_OK)
;
assert(rc == CDB2_OK_DONE);

rc = cdb2_close(hndl);
assert(rc == 0);
}

int main(int argc, char **argv)
{
const char *dbname;
signal(SIGPIPE, SIG_IGN);

/* bypass local cache code for this test needs to talk to sockpool */
setenv("COMDB2_CONFIG_MAX_LOCAL_CONNECTION_CACHE_ENTRIES", "0", 1);
test_process_env_vars();

if (argc != 2) {
fprintf(stderr, "Usage: %s dbname\n", argv[0]);
exit(1);
}
dbname = argv[1];
char *conf = getenv("CDB2_CONFIG");
if (conf)
cdb2_set_comdb2db_config(conf);

cdb2_enable_sockpool();

setenv("COMDB2_CONFIG_SOCKPOOL_SEND_TIMEOUTMS", "1", 1);
setenv("COMDB2_CONFIG_SOCKPOOL_RECV_TIMEOUTMS", "1", 1);
setenv("COMDB2_CONFIG_SOCKET_TIMEOUT", "1", 1);
setenv("COMDB2_CONFIG_CONNECT_TIMEOUT", "1", 1);

assert(0 == get_num_sockpool_send_timeouts());
assert(0 == get_num_sockpool_recv_timeouts());

// sockpool_prod_timeout_test("comdb2db");

// prod test causes lots of actual sockpool recv timeouts
int recv_timeouts = get_num_sockpool_recv_timeouts();

setenv("COMDB2_CONFIG_SOCKPOOL_SEND_TIMEOUTMS", "1000", 1);
setenv("COMDB2_CONFIG_SOCKPOOL_RECV_TIMEOUTMS", "1000", 1);
setenv("COMDB2_CONFIG_SOCKET_TIMEOUT", "100", 1);
setenv("COMDB2_CONFIG_CONNECT_TIMEOUT", "100", 1);

sockpool_test(dbname, __LINE__);

set_fail_timeout_sockpool_send(1);
sockpool_test(dbname, __LINE__);

assert(1 == get_num_sockpool_send_timeouts());
assert(recv_timeouts == get_num_sockpool_recv_timeouts());

set_fail_timeout_sockpool_recv(1);
sockpool_test(dbname, __LINE__);
assert(1 == get_num_sockpool_send_timeouts());
assert((recv_timeouts + 1) == get_num_sockpool_recv_timeouts());

set_fail_timeout_sockpool_send(2);
set_fail_timeout_sockpool_recv(2);
sockpool_test(dbname, __LINE__);
assert(3 == get_num_sockpool_send_timeouts());
int expected_recv_timeouts = getenv("CLUSTER") ? recv_timeouts + 2 : recv_timeouts + 1;
// int expected_recv_timeouts = recv_timeouts + 3;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works with +3 when testing with open api + bb plugins on internal machines. However when using roborivers with open api then get different value

fprintf(stderr, "Expected recv timeouts=%d actual=%d\n", expected_recv_timeouts,
get_num_sockpool_recv_timeouts());
assert((expected_recv_timeouts)== get_num_sockpool_recv_timeouts());

printf("%s - pass\n", basename(argv[0]));
}