Commit 5d8f1072 authored by Simon Morlat's avatar Simon Morlat

emulate tests with delay

parent d8189345
......@@ -55,6 +55,11 @@ void belle_sip_stack_sleep(belle_sip_stack_t *stack, unsigned int milliseconds);
void belle_sip_hop_free(belle_sip_hop_t *hop);
/**
* Can be used to simulate network transmission delays, for tests.
**/
void belle_sip_stack_set_tx_delay(belle_sip_stack_t *stack, int delay_ms);
BELLE_SIP_END_DECLS
#endif
......
......@@ -476,6 +476,7 @@ struct belle_sip_stack{
belle_sip_object_t base;
belle_sip_main_loop_t *ml;
belle_sip_timer_config_t timer_config;
int tx_delay; /*used to simulate network transmission delay, for tests*/
};
void belle_sip_stack_get_next_hop(belle_sip_stack_t *stack, belle_sip_request_t *req, belle_sip_hop_t *hop);
......
......@@ -287,7 +287,8 @@ void channel_set_state(belle_sip_channel_t *obj, belle_sip_channel_state_t state
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_state_changed,obj,state);
}
static void send_message(belle_sip_channel_t *obj, belle_sip_message_t *msg){
static void _send_message(belle_sip_channel_t *obj, belle_sip_message_t *msg){
char buffer[belle_sip_network_buffer_size];
int len;
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_sending,obj,msg);
......@@ -302,6 +303,31 @@ static void send_message(belle_sip_channel_t *obj, belle_sip_message_t *msg){
}
}
/* just to emulate network transmission delay */
typedef struct delayed_send{
belle_sip_channel_t *chan;
belle_sip_message_t *msg;
}delayed_send_t;
static int on_delayed_send_do(delayed_send_t *ds){
if (ds->chan->state==BELLE_SIP_CHANNEL_READY){
_send_message(ds->chan,ds->msg);
}
belle_sip_object_unref(ds->chan);
belle_sip_object_unref(ds->msg);
belle_sip_free(ds);
return FALSE;
}
static void send_message(belle_sip_channel_t *obj, belle_sip_message_t *msg){
if (obj->stack->tx_delay>0){
delayed_send_t *ds=belle_sip_new(delayed_send_t);
ds->chan=(belle_sip_channel_t*)belle_sip_object_ref(obj);
ds->msg=(belle_sip_message_t*)belle_sip_object_ref(msg);
belle_sip_main_loop_add_timeout(obj->stack->ml,(belle_sip_source_func_t)on_delayed_send_do,ds,obj->stack->tx_delay);
}else _send_message(obj,msg);
}
void belle_sip_channel_prepare(belle_sip_channel_t *obj){
obj->prepare=1;
......
......@@ -140,3 +140,7 @@ void belle_sip_hop_free(belle_sip_hop_t *hop){
}
}
void belle_sip_stack_set_tx_delay(belle_sip_stack_t *stack, int delay_ms){
stack->tx_delay=delay_ms;
}
......@@ -179,9 +179,16 @@ static void stateful_register_udp(void){
register_test(NULL,1);
}
static void stateful_register_udp_delayed(void){
belle_sip_stack_set_tx_delay(stack,1000);
register_test(NULL,1);
belle_sip_stack_set_tx_delay(stack,0);
}
static void stateful_register_tcp(void){
register_test("tcp",1);
}
static void stateful_register_tls(void){
register_test("tls",1);
}
......@@ -192,6 +199,9 @@ int belle_sip_register_test_suite(){
if (NULL == CU_add_test(pSuite, "stateful udp register", stateful_register_udp)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "stateful udp register with network delay", stateful_register_udp_delayed)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "stateful tcp register", stateful_register_tcp)) {
return CU_get_error();
}
......
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