X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=test%2Fimport-export.c;h=15981ed9f673b032740ebbf9371482661ac4de41;hb=HEAD;hp=15e213447eedd211f643aba6a2608e9939db7aef;hpb=6b125b5b68e2657eae9b36f23d7f569fb9e49f8d;p=meshlink diff --git a/test/import-export.c b/test/import-export.c index 15e21344..15981ed9 100644 --- a/test/import-export.c +++ b/test/import-export.c @@ -13,6 +13,7 @@ #include "utils.h" static struct sync_flag bar_reachable; +static struct sync_flag pmtu_flag; static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { (void)mesh; @@ -22,8 +23,17 @@ static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reach } } +static void pmtu_cb(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t pmtu) { + (void)mesh; + + if(pmtu && !strcmp(node->name, "bar")) { + set_sync_flag(&pmtu_flag, true); + } +} + int main(void) { init_sync_flag(&bar_reachable); + init_sync_flag(&pmtu_flag); meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb); @@ -79,30 +89,23 @@ int main(void) { // Start both instances meshlink_set_node_status_cb(mesh1, status_cb); + meshlink_set_node_pmtu_cb(mesh1, pmtu_cb); assert(meshlink_start(mesh1)); assert(meshlink_start(mesh2)); // Wait for the two to connect. - assert(wait_sync_flag(&bar_reachable, 20)); + assert(wait_sync_flag(&bar_reachable, 10)); // Wait for UDP communication to become possible. - int pmtu = meshlink_get_pmtu(mesh2, meshlink_get_node(mesh2, "bar")); - - for(int i = 0; i < 10 && !pmtu; i++) { - sleep(1); - pmtu = meshlink_get_pmtu(mesh2, meshlink_get_node(mesh2, "bar")); - } - - assert(pmtu); + assert(wait_sync_flag(&pmtu_flag, 10)); // Check that we now have reachability information assert(meshlink_get_node_reachability(mesh1, bar, &last_reachable, &last_unreachable)); assert(last_reachable); - assert(!last_unreachable); // Stop the meshes.