diff --git a/tests/simple_archiver.c b/tests/simple_archiver.c index 85c24ada8e1355ca775da8c0094511f50de9afa8..83d0057d475d98cc8940d0f6d4e6a76debb9b5ba 100644 --- a/tests/simple_archiver.c +++ b/tests/simple_archiver.c @@ -51,6 +51,45 @@ #define ERR(...) LOG_ERR(MSTRO_LOG_MODULE_USER,__VA_ARGS__) +// a list (used as stack) to store CDO handles +CHEAT_DECLARE( + struct cdo_list_entry { + mstro_cdo cdo; + struct cdo_list_entry *next; + }; + + struct cdo_list_entry *g_cdo_handles = NULL; + + struct cdo_list_entry * + push_cdo(mstro_cdo c) + { + struct cdo_list_entry *e = malloc(sizeof(struct cdo_list_entry)); + if(e!=NULL) { + e->cdo = c; + e->next = g_cdo_handles; + g_cdo_handles = e; + } + return e; + } + + mstro_cdo + pop_cdo() + { + struct cdo_list_entry *e = NULL; + if(g_cdo_handles!=NULL) { + e=g_cdo_handles; + g_cdo_handles=g_cdo_handles->next; + }; + if(e) { + mstro_cdo c = e->cdo; + free(e); + return c; + } else + return NULL; + } + + ) + CHEAT_DECLARE( const mstro_nanosec_t MAX_WAIT = ((mstro_nanosec_t)15)*1000*1000*1000; /* 10s */ @@ -152,8 +191,15 @@ CHEAT_TEST(simple_archiver, case MSTRO_POOL_EVENT_OFFER: /* FIXME: Immediately post a REQUIRE for it */ cdo_name = tmp->offer.cdo_name; + mstro_cdo c; + cheat_assert(MSTRO_OK==mstro_cdo_declare( + tmp->offer.cdo_name, + MSTRO_ATTR_DEFAULT, + &c)); + cheat_assert(MSTRO_OK==mstro_cdo_require(c)); + cheat_assert(NULL!=push_cdo(c)); break; - + case MSTRO_POOL_EVENT_DECLARE: cdo_name = tmp->offer.cdo_name; break; @@ -210,11 +256,22 @@ CHEAT_TEST(simple_archiver, } DEBUG("Left polling loop\n"); + + DEBUG("retracting all outstanding requires\n"); + { + mstro_cdo c; + while((c=pop_cdo())!=NULL) { + cheat_assert(MSTRO_OK==mstro_cdo_retract(c)); + cheat_assert(MSTRO_OK==mstro_cdo_dispose(c)); + } + } cheat_assert(MSTRO_OK == mstro_subscription_dispose(cdo_subscription)); cheat_assert(MSTRO_OK == mstro_subscription_dispose(join_leave_subscription)); + + cheat_assert(MSTRO_OK == mstro_finalize()); )