mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Improve the udp_shutdown_read and udp_cancel_read tests
In the udp_shutdown_read unit test, delay the isc_loopmgr_shutdown() to the send callback, and in the udp_cancel_read test wait for a single timed out test, then read again, send an UDP packet and cancel the read from the send callback.
This commit is contained in:
committed by
Ondřej Surý
parent
eac8bc5c1a
commit
014da8599f
@@ -306,7 +306,6 @@ udp_noresponse_recv_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
static void
|
||||
udp_noresponse_read_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
isc_region_t *region, void *cbarg) {
|
||||
UNUSED(handle);
|
||||
UNUSED(region);
|
||||
UNUSED(cbarg);
|
||||
|
||||
@@ -339,9 +338,6 @@ udp_noresponse_connect_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
isc_nmhandle_t *readhandle = NULL;
|
||||
isc_nmhandle_t *sendhandle = NULL;
|
||||
|
||||
UNUSED(handle);
|
||||
UNUSED(cbarg);
|
||||
|
||||
isc_refcount_decrement(&active_cconnects);
|
||||
|
||||
assert_int_equal(eresult, ISC_R_SUCCESS);
|
||||
@@ -463,8 +459,6 @@ udp_timeout_recovery_connect_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
isc_nmhandle_t *readhandle = NULL;
|
||||
isc_nmhandle_t *sendhandle = NULL;
|
||||
|
||||
UNUSED(cbarg);
|
||||
|
||||
F();
|
||||
|
||||
isc_refcount_decrement(&active_cconnects);
|
||||
@@ -557,14 +551,50 @@ ISC_LOOP_TEST_IMPL(udp_shutdown_connect) {
|
||||
isc_job_run(loopmgr, udp_connect_udpconnect, netmgr);
|
||||
}
|
||||
|
||||
static void
|
||||
udp_shutdown_read_recv_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
isc_region_t *region, void *cbarg) {
|
||||
uint64_t magic = 0;
|
||||
|
||||
UNUSED(cbarg);
|
||||
|
||||
assert_non_null(handle);
|
||||
|
||||
F();
|
||||
|
||||
assert_int_equal(eresult, ISC_R_SUCCESS);
|
||||
|
||||
assert_true(region->length == sizeof(magic));
|
||||
|
||||
memmove(&magic, region->base, sizeof(magic));
|
||||
assert_true(magic == send_magic);
|
||||
}
|
||||
|
||||
static void
|
||||
udp_shutdown_read_send_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
void *cbarg) {
|
||||
UNUSED(cbarg);
|
||||
|
||||
F();
|
||||
|
||||
assert_non_null(handle);
|
||||
assert_int_equal(eresult, ISC_R_SUCCESS);
|
||||
|
||||
atomic_fetch_add(&csends, 1);
|
||||
|
||||
isc_loopmgr_shutdown(loopmgr);
|
||||
|
||||
isc_nmhandle_detach(&handle);
|
||||
isc_refcount_decrement(&active_csends);
|
||||
}
|
||||
|
||||
static void
|
||||
udp_shutdown_read_read_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
isc_region_t *region, void *cbarg) {
|
||||
UNUSED(handle);
|
||||
UNUSED(region);
|
||||
UNUSED(cbarg);
|
||||
|
||||
assert_int_equal(eresult, ISC_R_SHUTTINGDOWN);
|
||||
assert_true(eresult == ISC_R_SHUTTINGDOWN || eresult == ISC_R_TIMEDOUT);
|
||||
|
||||
isc_refcount_decrement(&active_creads);
|
||||
|
||||
@@ -577,21 +607,25 @@ static void
|
||||
udp_shutdown_read_connect_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
void *cbarg) {
|
||||
isc_nmhandle_t *readhandle = NULL;
|
||||
|
||||
UNUSED(handle);
|
||||
UNUSED(cbarg);
|
||||
isc_nmhandle_t *sendhandle = NULL;
|
||||
|
||||
isc_refcount_decrement(&active_cconnects);
|
||||
|
||||
assert_int_equal(eresult, ISC_R_SUCCESS);
|
||||
|
||||
/* Read */
|
||||
isc_refcount_increment0(&active_creads);
|
||||
isc_nmhandle_attach(handle, &readhandle);
|
||||
isc_nm_read(handle, udp_shutdown_read_read_cb, cbarg);
|
||||
|
||||
atomic_fetch_add(&cconnects, 1);
|
||||
/* Send */
|
||||
isc_refcount_increment0(&active_csends);
|
||||
isc_nmhandle_attach(handle, &sendhandle);
|
||||
isc_nmhandle_setwritetimeout(handle, T_IDLE);
|
||||
isc_nm_send(sendhandle, (isc_region_t *)&send_msg,
|
||||
udp_shutdown_read_send_cb, cbarg);
|
||||
|
||||
isc_loopmgr_shutdown(loopmgr);
|
||||
atomic_fetch_add(&cconnects, 1);
|
||||
}
|
||||
|
||||
ISC_SETUP_TEST_IMPL(udp_shutdown_read) {
|
||||
@@ -609,6 +643,8 @@ ISC_TEARDOWN_TEST_IMPL(udp_shutdown_read) {
|
||||
}
|
||||
|
||||
ISC_LOOP_TEST_IMPL(udp_shutdown_read) {
|
||||
start_listening(ISC_NM_LISTEN_ONE, udp_shutdown_read_recv_cb);
|
||||
|
||||
isc_refcount_increment0(&active_cconnects);
|
||||
isc_nm_udpconnect(netmgr, &udp_connect_addr, &udp_listen_addr,
|
||||
udp_shutdown_read_connect_cb, NULL, T_SOFT);
|
||||
@@ -618,7 +654,8 @@ static void
|
||||
udp_cancel_read_recv_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
isc_region_t *region, void *cbarg) {
|
||||
uint64_t magic = 0;
|
||||
isc_nmhandle_t *sendhandle = NULL;
|
||||
|
||||
UNUSED(cbarg);
|
||||
|
||||
assert_non_null(handle);
|
||||
|
||||
@@ -630,38 +667,6 @@ udp_cancel_read_recv_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
|
||||
memmove(&magic, region->base, sizeof(magic));
|
||||
assert_true(magic == send_magic);
|
||||
|
||||
isc_nmhandle_attach(handle, &sendhandle);
|
||||
isc_refcount_increment0(&active_ssends);
|
||||
isc_nmhandle_setwritetimeout(sendhandle, T_IDLE);
|
||||
isc_nm_send(sendhandle, (isc_region_t *)&send_msg, listen_send_cb,
|
||||
cbarg);
|
||||
}
|
||||
|
||||
static void
|
||||
udp_cancel_read_read_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
isc_region_t *region, void *cbarg) {
|
||||
UNUSED(handle);
|
||||
UNUSED(region);
|
||||
UNUSED(cbarg);
|
||||
|
||||
F();
|
||||
|
||||
switch (eresult) {
|
||||
case ISC_R_TIMEDOUT:
|
||||
case ISC_R_EOF:
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
isc_refcount_decrement(&active_creads);
|
||||
|
||||
atomic_fetch_add(&creads, 1);
|
||||
|
||||
isc_nmhandle_detach(&handle);
|
||||
|
||||
isc_loopmgr_shutdown(loopmgr);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -676,18 +681,56 @@ udp_cancel_read_send_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
|
||||
atomic_fetch_add(&csends, 1);
|
||||
|
||||
isc_nm_cancelread(handle);
|
||||
|
||||
isc_nmhandle_detach(&handle);
|
||||
isc_refcount_decrement(&active_csends);
|
||||
}
|
||||
|
||||
static void
|
||||
udp_cancel_read_read_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
isc_region_t *region, void *cbarg) {
|
||||
isc_nmhandle_t *sendhandle = NULL;
|
||||
isc_nmhandle_t *readhandle = NULL;
|
||||
|
||||
UNUSED(region);
|
||||
|
||||
F();
|
||||
|
||||
switch (eresult) {
|
||||
case ISC_R_TIMEDOUT:
|
||||
|
||||
/* Read again */
|
||||
isc_refcount_increment0(&active_creads);
|
||||
isc_nmhandle_attach(handle, &readhandle);
|
||||
isc_nm_read(handle, udp_cancel_read_read_cb, cbarg);
|
||||
|
||||
/* Send */
|
||||
isc_refcount_increment0(&active_csends);
|
||||
isc_nmhandle_attach(handle, &sendhandle);
|
||||
isc_nmhandle_setwritetimeout(handle, T_IDLE);
|
||||
isc_nm_send(sendhandle, (isc_region_t *)&send_msg,
|
||||
udp_cancel_read_send_cb, cbarg);
|
||||
break;
|
||||
case ISC_R_EOF:
|
||||
/* The read has been canceled */
|
||||
isc_loopmgr_shutdown(loopmgr);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
isc_refcount_decrement(&active_creads);
|
||||
|
||||
atomic_fetch_add(&creads, 1);
|
||||
|
||||
isc_nmhandle_detach(&handle);
|
||||
}
|
||||
|
||||
static void
|
||||
udp_cancel_read_connect_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
void *cbarg) {
|
||||
isc_nmhandle_t *readhandle = NULL;
|
||||
isc_nmhandle_t *sendhandle = NULL;
|
||||
|
||||
UNUSED(handle);
|
||||
UNUSED(cbarg);
|
||||
|
||||
isc_refcount_decrement(&active_cconnects);
|
||||
|
||||
@@ -697,22 +740,13 @@ udp_cancel_read_connect_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
isc_nmhandle_attach(handle, &readhandle);
|
||||
isc_nm_read(handle, udp_cancel_read_read_cb, cbarg);
|
||||
|
||||
/* Send */
|
||||
isc_refcount_increment0(&active_csends);
|
||||
isc_nmhandle_attach(handle, &sendhandle);
|
||||
isc_nmhandle_setwritetimeout(handle, T_IDLE);
|
||||
isc_nm_send(sendhandle, (isc_region_t *)&send_msg,
|
||||
udp_cancel_read_send_cb, readhandle);
|
||||
|
||||
isc_nm_cancelread(readhandle);
|
||||
|
||||
atomic_fetch_add(&cconnects, 1);
|
||||
}
|
||||
|
||||
ISC_SETUP_TEST_IMPL(udp_cancel_read) {
|
||||
setup_test(state);
|
||||
expected_cconnects = 1;
|
||||
expected_creads = 1;
|
||||
expected_creads = 2;
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -735,8 +769,6 @@ static void
|
||||
udp__send_cb(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
||||
isc_nmhandle_t *sendhandle = handle;
|
||||
|
||||
UNUSED(cbarg);
|
||||
|
||||
assert_non_null(sendhandle);
|
||||
|
||||
F();
|
||||
@@ -782,8 +814,6 @@ udp__connect_cb(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
||||
isc_nmhandle_t *readhandle = NULL;
|
||||
isc_nmhandle_t *sendhandle = NULL;
|
||||
|
||||
UNUSED(cbarg);
|
||||
|
||||
F();
|
||||
|
||||
isc_refcount_decrement(&active_cconnects);
|
||||
@@ -935,9 +965,6 @@ ISC_LOOP_TEST_IMPL(udp_recv_send) {
|
||||
|
||||
static void
|
||||
double_read_send_cb(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) {
|
||||
UNUSED(cbarg);
|
||||
UNUSED(eresult);
|
||||
|
||||
assert_non_null(handle);
|
||||
|
||||
F();
|
||||
@@ -1015,8 +1042,6 @@ double_read_cb(isc_nmhandle_t *handle, isc_result_t eresult,
|
||||
uint64_t magic = 0;
|
||||
bool detach = false;
|
||||
|
||||
UNUSED(cbarg);
|
||||
|
||||
assert_non_null(handle);
|
||||
|
||||
F();
|
||||
|
Reference in New Issue
Block a user