From dbb98fc7deaa8ad2c3924bfb8a8b3aaf2bbe2d98 Mon Sep 17 00:00:00 2001
From: Utz-Uwe Haus <uhaus@cray.com>
Date: Tue, 13 Apr 2021 17:52:47 +0200
Subject: [PATCH] REQUIRE every OFFERed CDO in simple_archiver

In an attempt to reproduce #20; not reproducing it on MacOS, needs check
on other systems.
---
 tests/simple_archiver.c | 59 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/tests/simple_archiver.c b/tests/simple_archiver.c
index 85c24ada..83d0057d 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());
            )
 
-- 
GitLab