🧪 test(mq): add mq clean test case
This commit is contained in:
@@ -135,6 +135,63 @@ TEST(mq_runtime, new_and_free) {
|
||||
|
||||
}
|
||||
|
||||
struct test_pub_and_clean_env
|
||||
{
|
||||
struct mq_schema *s;
|
||||
struct mq_runtime *rt;
|
||||
int N_round;
|
||||
int current_round;
|
||||
int topic_id;
|
||||
int on_msg_free_called;
|
||||
int on_msg_called;
|
||||
};
|
||||
|
||||
void test_pub_and_clean_free(void *msg, void *msg_free_arg)
|
||||
{
|
||||
struct test_pub_and_clean_env *env = (struct test_pub_and_clean_env *)msg_free_arg;
|
||||
env->on_msg_free_called+=1;
|
||||
FREE(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
void test_pub_and_clean_on_msg(int topic_id, void *msg, void *sub_arg)
|
||||
{
|
||||
struct test_pub_and_clean_env *env = (struct test_pub_and_clean_env *)sub_arg;
|
||||
env->on_msg_called+=1;
|
||||
return;
|
||||
}
|
||||
|
||||
TEST(mq_runtime, pub_then_clean) {
|
||||
|
||||
struct test_pub_and_clean_env env={};
|
||||
env.s = mq_schema_new();
|
||||
EXPECT_TRUE(env.s!=NULL);
|
||||
|
||||
env.topic_id=mq_schema_create_topic(env.s,"TEST", NULL, NULL, test_pub_and_clean_free , &env);
|
||||
EXPECT_EQ(mq_schema_subscribe(env.s, env.topic_id, test_pub_and_clean_on_msg, &env), 0);
|
||||
|
||||
env.N_round=10;
|
||||
env.rt=mq_runtime_new(env.s);
|
||||
EXPECT_TRUE(env.rt!=NULL);
|
||||
|
||||
for(int i=0; i<env.N_round;i++)
|
||||
{
|
||||
env.current_round=i;
|
||||
void *msg = CALLOC(int, 1);
|
||||
EXPECT_TRUE(msg!=NULL);
|
||||
*(int *)msg=i;
|
||||
EXPECT_EQ(mq_runtime_publish_message(env.rt, env.topic_id, msg), 0);
|
||||
mq_runtime_clean(env.rt);
|
||||
}
|
||||
|
||||
|
||||
mq_runtime_free(env.rt);
|
||||
mq_schema_free(env.s);
|
||||
|
||||
EXPECT_EQ(env.on_msg_free_called, env.N_round);
|
||||
EXPECT_EQ(env.on_msg_called, 0);
|
||||
|
||||
}
|
||||
|
||||
#define PACKET_EXDATA_NUM 2
|
||||
#define PACKET_TOPIC_NUM 2
|
||||
@@ -362,7 +419,7 @@ static void test_dispatch_on_msg(int topic_id, void *msg, void *sub_arg)
|
||||
return;
|
||||
}
|
||||
|
||||
TEST(mq_runtime, call_dispatch_on_msg_dispatch)
|
||||
TEST(mq_runtime, call_dispatch_when_dispatch)
|
||||
{
|
||||
struct test_dispatch_on_msg_env env={};
|
||||
env.s=mq_schema_new();
|
||||
|
||||
Reference in New Issue
Block a user