Commit 84842639 authored by Ghislain MARY's avatar Ghislain MARY

Use own functions for resolver error and delay simulation.

parent 8d2b876f
......@@ -71,6 +71,17 @@ BELLESIP_EXPORT void belle_sip_stack_set_tx_delay(belle_sip_stack_t *stack, int
BELLESIP_EXPORT void belle_sip_stack_set_send_error(belle_sip_stack_t *stack, int send_error);
/**
* Can be used to simulate network transmission delays, for tests.
**/
BELLESIP_EXPORT void belle_sip_stack_set_resolver_tx_delay(belle_sip_stack_t *stack, int delay_ms);
/**
* Can be used to simulate network sending error, for tests.
* @param stack
* @param send_error if <0, will cause the resolver to fail with this error code.
**/
BELLESIP_EXPORT void belle_sip_stack_set_resolver_send_error(belle_sip_stack_t *stack, int send_error);
BELLE_SIP_END_DECLS
......
......@@ -462,7 +462,8 @@ struct belle_sip_stack{
int dns_timeout;
int tx_delay; /*used to simulate network transmission delay, for tests*/
int send_error; /* used to simulate network error. if <0, channel_send will return this value*/
int resolver_tx_delay; /*used to simulate network transmission delay, for tests*/
int resolver_send_error; /* used to simulate network error*/
};
belle_sip_hop_t* belle_sip_hop_create(const char* transport, const char* host,int port);
......
......@@ -159,13 +159,13 @@ static int resolver_process_a_data(belle_sip_resolver_context_t *ctx, unsigned i
static int _resolver_start_query(belle_sip_resolver_context_t *ctx, belle_sip_source_func_t datafunc, enum dns_type type, int timeout) {
int error;
if (!ctx->stack->send_error) {
if (!ctx->stack->resolver_send_error) {
error = dns_res_submit(ctx->R, ctx->name, type, DNS_C_IN);
if (error)
belle_sip_error("%s dns_res_submit error [%s]: %s", __FUNCTION__, ctx->name, dns_strerror(error));
} else {
/* Error simulation */
error = ctx->stack->send_error;
error = ctx->stack->resolver_send_error;
belle_sip_error("%s dns_res_submit error [%s]: simulated error %d", __FUNCTION__, ctx->name, error);
}
if (error < 0) {
......@@ -220,15 +220,15 @@ static int resolver_start_query(belle_sip_resolver_context_t *ctx, belle_sip_sou
return -1;
}
if (ctx->stack->tx_delay > 0) {
if (ctx->stack->resolver_tx_delay > 0) {
delayed_send_t *ds = belle_sip_new(delayed_send_t);
ds->ctx = (belle_sip_resolver_context_t *)belle_sip_object_ref(ctx);
ds->datafunc = datafunc;
ds->type = type;
ds->timeout = timeout;
belle_sip_main_loop_add_timeout(ctx->stack->ml, (belle_sip_source_func_t)on_delayed_send_do, ds, ctx->stack->tx_delay);
belle_sip_main_loop_add_timeout(ctx->stack->ml, (belle_sip_source_func_t)on_delayed_send_do, ds, ctx->stack->resolver_tx_delay);
belle_sip_socket_source_init((belle_sip_source_t*)ctx, datafunc, ctx, dns_res_pollfd(ctx->R), BELLE_SIP_EVENT_READ | BELLE_SIP_EVENT_TIMEOUT, timeout);
belle_sip_message("%s DNS resolution delayed by %d ms", __FUNCTION__, ctx->stack->tx_delay);
belle_sip_message("%s DNS resolution delayed by %d ms", __FUNCTION__, ctx->stack->resolver_tx_delay);
return 0;
} else {
return _resolver_start_query(ctx, datafunc, type, timeout);
......
......@@ -126,6 +126,14 @@ void belle_sip_stack_set_send_error(belle_sip_stack_t *stack, int send_error){
stack->send_error=send_error;
}
void belle_sip_stack_set_resolver_tx_delay(belle_sip_stack_t *stack, int delay_ms) {
stack->resolver_tx_delay = delay_ms;
}
void belle_sip_stack_set_resolver_send_error(belle_sip_stack_t *stack, int send_error) {
stack->resolver_send_error = send_error;
}
const char* belle_sip_version_to_string() {
return PACKAGE_VERSION;
}
......@@ -119,21 +119,21 @@ static void resolve(void) {
reset_endpoint(client);
family = AF_INET;
peer_name = IPV4_SIP_DOMAIN;
belle_sip_stack_set_send_error(client->stack, -1);
belle_sip_stack_set_resolver_send_error(client->stack, -1);
client->resolver_id = belle_sip_resolve(client->stack, peer_name, peer_port, family, resolve_done, client, belle_sip_stack_get_main_loop(client->stack));
CU_ASSERT_EQUAL(client->resolver_id, 0);
belle_sip_stack_set_send_error(client->stack, 0);
belle_sip_stack_set_resolver_send_error(client->stack, 0);
/* IPv4 A query timeout */
reset_endpoint(client);
family = AF_INET;
peer_name = IPV4_SIP_DOMAIN;
belle_sip_stack_set_tx_delay(client->stack, timeout);
belle_sip_stack_set_resolver_tx_delay(client->stack, timeout);
client->resolver_id = belle_sip_resolve(client->stack, peer_name, peer_port, family, resolve_done, client, belle_sip_stack_get_main_loop(client->stack));
CU_ASSERT_NOT_EQUAL(client->resolver_id, 0);
CU_ASSERT_FALSE(wait_for(client->stack, &client->resolve_done, 1, timeout));
CU_ASSERT_PTR_EQUAL(client->result, NULL);
belle_sip_stack_set_tx_delay(client->stack, 0);
belle_sip_stack_set_resolver_tx_delay(client->stack, 0);
/* Successful IPv6 AAAA query */
reset_endpoint(client);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment