Skip to content
Merged
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 cdb2api/cdb2api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions tests/api_tests.test/runit

This file was deleted.

File renamed without changes.
25 changes: 25 additions & 0 deletions tests/api_tst.test/runit
Original file line number Diff line number Diff line change
@@ -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}
Copy link
Contributor Author

@chands10 chands10 Dec 2, 2025

Choose a reason for hiding this comment

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

Test name (apitst) must be at most 6 letters otherwise sockpool will not be used lol

[[ $? -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
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
59 changes: 59 additions & 0 deletions tests/tools/cdb2api_unread_data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#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);

cdb2_enable_sockpool();

int rc = test_unread_record(db, "default");

return rc;
}