Skip to content

Commit 1eea739

Browse files
carlgsmithblairsteven
authored andcommitted
Traverse all children on a query
Only the first path of a multi branch query were being hit due to g_node_traverse being called with the first child. Use g_node_children_foreach instead.
1 parent 577b1a8 commit 1eea739

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

apteryxd.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ collect_provided_paths_query(GNode *query)
18941894
return matches;
18951895
}
18961896

1897-
static gboolean _refresh_paths (GNode *node, gpointer data)
1897+
static void _refresh_paths (GNode *node, gpointer data)
18981898
{
18991899
char *path = NULL;
19001900

@@ -1906,7 +1906,7 @@ static gboolean _refresh_paths (GNode *node, gpointer data)
19061906
_node_to_path (node->parent, &path);
19071907
refreshers_traverse (path, cb_all);
19081908
free (path);
1909-
return FALSE;
1909+
return;
19101910
}
19111911

19121912
/* Handle direct matches */
@@ -1916,12 +1916,12 @@ static gboolean _refresh_paths (GNode *node, gpointer data)
19161916
_node_to_path (node, &path);
19171917
call_refreshers (path, false);
19181918
free (path);
1919-
return FALSE;
1919+
return;
19201920
}
19211921

19221922
/* Traverse children */
1923-
g_node_traverse (node->children, G_PRE_ORDER, G_TRAVERSE_NON_LEAFS, 1, _refresh_paths, NULL);
1924-
return FALSE;
1923+
g_node_children_foreach (node, G_TRAVERSE_NON_LEAFS, _refresh_paths, NULL);
1924+
return;
19251925
}
19261926

19271927
static bool
@@ -1967,7 +1967,7 @@ handle_query (rpc_message msg)
19671967
free (root_path);
19681968

19691969
/* Traverse the tree calling refreshers */
1970-
g_node_traverse (query_head, G_PRE_ORDER, G_TRAVERSE_NON_LEAFS, 1, _refresh_paths, NULL);
1970+
g_node_children_foreach (query_head, G_TRAVERSE_NON_LEAFS, _refresh_paths, NULL);
19711971

19721972
/* Query the database */
19731973
root = db_query (query_head);

test.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4858,6 +4858,35 @@ test_query_refreshed_multi_wildcard()
48584858
apteryx_prune (TEST_PATH);
48594859
}
48604860

4861+
void
4862+
test_query_refreshed_multi_branches()
4863+
{
4864+
const char *path = TEST_PATH"/devices/*";
4865+
GNode *root , *node, *rroot;
4866+
4867+
_cb_count = 0;
4868+
_cb_timeout = 5000;
4869+
apteryx_refresh (path, refresh_state_callback);
4870+
4871+
root = g_node_new (g_strdup (TEST_PATH));
4872+
node = APTERYX_NODE (root, g_strdup ("cars"));
4873+
node = APTERYX_NODE (node, g_strdup ("*"));
4874+
node = APTERYX_NODE (root, g_strdup ("devices"));
4875+
node = APTERYX_NODE (node, g_strdup ("*"));
4876+
node = APTERYX_NODE (node, g_strdup ("interfaces"));
4877+
node = APTERYX_NODE (node, g_strdup ("*"));
4878+
node = APTERYX_NODE (node, g_strdup ("state"));
4879+
rroot = apteryx_query (root);
4880+
CU_ASSERT (rroot && g_node_n_nodes (rroot, G_TRAVERSE_LEAVES) == 1);
4881+
apteryx_free_tree (rroot);
4882+
apteryx_free_tree (root);
4883+
CU_ASSERT (_cb_count == 1);
4884+
4885+
apteryx_unrefresh (path, refresh_state_callback);
4886+
apteryx_set (TEST_PATH"/devices/dut/interfaces/eth1/state", NULL);
4887+
apteryx_prune (TEST_PATH);
4888+
}
4889+
48614890
void
48624891
test_query_refreshed_once()
48634892
{
@@ -8101,6 +8130,7 @@ static CU_TestInfo tests_api_tree[] = {
81018130
{ "query refreshed simple", test_query_refreshed_simple},
81028131
{ "query refreshed mid wildcard", test_query_refreshed_mid_wildcard},
81038132
{ "query refreshed multi wildcard", test_query_refreshed_multi_wildcard},
8133+
{ "query refreshed multi branches", test_query_refreshed_multi_branches},
81048134
{ "query refreshed once", test_query_refreshed_once},
81058135
{ "query not refreshed one path", test_query_not_refreshed_one_path},
81068136
{ "query not refreshed two paths", test_query_not_refreshed_two_paths},

0 commit comments

Comments
 (0)