Skip to content

Commit

Permalink
tests BUGFIX try to prevent multi-threading problems
Browse files Browse the repository at this point in the history
Could manifest mainly on systems with less cores
and higher thread contention.
  • Loading branch information
michalvasko committed Oct 25, 2024
1 parent 4826ce8 commit e72c26d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions tests/test_subscribe_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 8 additions & 3 deletions tests/test_subscribe_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e72c26d

Please sign in to comment.