Skip to content
Draft
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
13 changes: 13 additions & 0 deletions tests/cdb2api_tests.test/runit
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
57 changes: 57 additions & 0 deletions tests/tools/cdb2api_unread_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <signal.h>
#include <stdio.h>
#include <cdb2api.h>
#include <cdb2api_test.h>

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;
}