From e72c26d2d5ffd407e41a9887cbb8a63f1292f1ba Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Fri, 25 Oct 2024 15:43:36 +0200 Subject: [PATCH] tests BUGFIX try to prevent multi-threading problems Could manifest mainly on systems with less cores and higher thread contention. --- tests/test_subscribe_filter.c | 12 ++++++++---- tests/test_subscribe_param.c | 11 ++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/test_subscribe_filter.c b/tests/test_subscribe_filter.c index 4e662167..ade560dc 100644 --- a/tests/test_subscribe_filter.c +++ b/tests/test_subscribe_filter.c @@ -56,19 +56,23 @@ reestablish_sub(void **state, const char *filter) { struct np2_test *st = *state; - /* Reestablish NETCONF connection */ + /* free the current session (with its subscription) */ nc_session_free(st->nc_sess, NULL); + + /* because of multithreading, try to prevent netconf-session-end being generated AFTER the new subscription is made */ + usleep(20000); + + /* create a new session */ st->nc_sess = nc_connect_unix(st->socket_path, (struct ly_ctx *)nc_session_get_ctx(st->nc_sess2)); assert_non_null(st->nc_sess); - /* Get a subscription to receive notifications */ + /* get a subscription to receive notifications */ st->rpc = nc_rpc_subscribe(NULL, filter, NULL, NULL, NC_PARAMTYPE_CONST); st->msgtype = nc_send_rpc(st->nc_sess, st->rpc, 1000, &st->msgid); assert_int_equal(NC_MSG_RPC, st->msgtype); - /* Check reply */ + /* check reply */ ASSERT_OK_REPLY(st); - FREE_TEST_VARS(st); } diff --git a/tests/test_subscribe_param.c b/tests/test_subscribe_param.c index 42959621..4e39af8c 100644 --- a/tests/test_subscribe_param.c +++ b/tests/test_subscribe_param.c @@ -38,17 +38,22 @@ reestablish_sub(void **state, const char *stream, const char *start_time, const { struct np2_test *st = *state; - /* Reestablish NETCONF connection */ + /* free the current session (with its subscription) */ nc_session_free(st->nc_sess, NULL); + + /* because of multithreading, try to prevent netconf-session-end being generated AFTER the new subscription is made */ + usleep(20000); + + /* create a new session */ st->nc_sess = nc_connect_unix(st->socket_path, (struct ly_ctx *)nc_session_get_ctx(st->nc_sess2)); assert_non_null(st->nc_sess); - /* Get a subscription to receive notifications */ + /* get a subscription to receive notifications */ st->rpc = nc_rpc_subscribe(stream, NULL, start_time, stop_time, NC_PARAMTYPE_CONST); st->msgtype = nc_send_rpc(st->nc_sess, st->rpc, 1000, &st->msgid); assert_int_equal(NC_MSG_RPC, st->msgtype); - /* Check reply */ + /* check reply */ ASSERT_OK_REPLY(st); FREE_TEST_VARS(st); }