summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author郑超 <[email protected]>2018-09-30 16:55:20 +0800
committer郑超 <[email protected]>2018-09-30 16:55:20 +0800
commita141d4b90ce4df3a9cf36c4bc591542e9d0880ec (patch)
treeffdf01b4e514bc5e926866ff2534a5cce2f9a289
parent0f554ff9503cbd15aa6697a80c1c09b03b53bbc2 (diff)
parent6b1e8d5866439712166acc5466ced1ee4f408395 (diff)
Merge branch 'bugfix-error-when-append-one-more-cmd' into 'master'v2.3.1
Bug修复:在append多条配置时,只有第一条写入成功。 See merge request MESA_framework/maat!4
-rw-r--r--src/entry/Maat_command.cpp2
-rw-r--r--test/test_maatframe.cpp22
2 files changed, 14 insertions, 10 deletions
diff --git a/src/entry/Maat_command.cpp b/src/entry/Maat_command.cpp
index 3a30724..0e8bc64 100644
--- a/src/entry/Maat_command.cpp
+++ b/src/entry/Maat_command.cpp
@@ -2223,7 +2223,7 @@ int Maat_cmd_commit(Maat_feather_t feather)
for(i=0,p=_feather->cmd_qhead;i<_feather->cmd_q_cnt;i++)
{
- serial_rule_idx+=build_serial_rule(_feather,p,s_rule, serial_rule_num-serial_rule_idx);
+ serial_rule_idx+=build_serial_rule(_feather,p,s_rule+serial_rule_idx, serial_rule_num-serial_rule_idx);
p=p->next;
}
assert(serial_rule_idx==serial_rule_num);
diff --git a/test/test_maatframe.cpp b/test/test_maatframe.cpp
index 6edb1cd..7279984 100644
--- a/test/test_maatframe.cpp
+++ b/test/test_maatframe.cpp
@@ -718,11 +718,6 @@ int test_add_expr_command(Maat_feather_t feather,const char* region_table,int co
}
//cmd has been saved in feather, so free cmd before commit is allowed.
Maat_free_cmd(cmd);
- ret=Maat_cmd_commit(feather);
- if(ret<0)
- {
- printf("Commit Maat command %d failed.\n",rule.config_id);
- }
return 0;
}
@@ -765,10 +760,14 @@ TEST_F(MaatCmdTest, SetExpr)
Maat_str_escape(escape_buff1, sizeof(escape_buff1),keywords1);
Maat_str_escape(escape_buff2, sizeof(escape_buff2),keywords2);
snprintf(keywords,sizeof(keywords),"%s&%s",escape_buff1,escape_buff2);
- config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
+ config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 2);
ret=Maat_read_state(feather,MAAT_STATE_VERSION, &version_before, sizeof(version_before));
+ test_add_expr_command(feather,table_name,config_id-1, 0, label_id, keywords);
test_add_expr_command(feather,table_name,config_id, 0, label_id, keywords);
+
+ ret=Maat_cmd_commit(feather);
+ EXPECT_TRUE(ret>=0);
usleep(WAIT_FOR_EFFECTIVE_US);//waiting for commands go into effect
ret=Maat_read_state(feather,MAAT_STATE_VERSION, &version_after, sizeof(version_after));
@@ -782,15 +781,17 @@ TEST_F(MaatCmdTest, SetExpr)
&result,NULL, 1,
&mid, 0);
EXPECT_GT(ret, 0);
- EXPECT_EQ(result.config_id, config_id);
+ EXPECT_TRUE(result.config_id==config_id||result.config_id==config_id-1);
Maat_clean_status(&mid);
output_id_cnt=Maat_cmd_select(feather,label_id, output_ids, 4);
- EXPECT_EQ(output_id_cnt, 1);
- EXPECT_EQ(output_ids[0], config_id);
+ EXPECT_EQ(output_id_cnt, 2);
+ EXPECT_TRUE(output_ids[0]==config_id||output_ids[0]==config_id-1);
usleep(WAIT_FOR_EFFECTIVE_US);//waiting for commands go into effect
+ del_command(feather, config_id-1);
del_command(feather, config_id);
+
usleep(WAIT_FOR_EFFECTIVE_US);//waiting for commands go into effect
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
&result,NULL, 1,
@@ -801,6 +802,9 @@ TEST_F(MaatCmdTest, SetExpr)
timeout=1;
config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
test_add_expr_command(feather,table_name,config_id, timeout, label_id, keywords);
+ ret=Maat_cmd_commit(feather);
+ EXPECT_TRUE(ret>=0);
+
usleep(timeout*1000*1000+WAIT_FOR_EFFECTIVE_US);
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
&result,NULL, 1,