sync thread for test sync
authorVolker Birk <vb@pep.foundation>
Wed, 22 Aug 2018 20:01:29 +0200
branchsync
changeset 2873ceaa29b309ef
parent 2872 ea6d9edc7001
child 2874 45531079b073
sync thread for test
test/include/locked_queue.hh
test/src/engine_tests/SyncTests.cc
     1.1 --- a/test/include/locked_queue.hh	Wed Aug 22 18:55:53 2018 +0200
     1.2 +++ b/test/include/locked_queue.hh	Wed Aug 22 20:01:29 2018 +0200
     1.3 @@ -52,5 +52,10 @@
     1.4              lock_guard<mutex> lg(_mtx);
     1.5              return _q.size();
     1.6          }
     1.7 +        bool empty()
     1.8 +        {
     1.9 +            lock_guard<mutex> lg(_mtx);
    1.10 +            return _q.empty();
    1.11 +        }
    1.12      };
    1.13  };
     2.1 --- a/test/src/engine_tests/SyncTests.cc	Wed Aug 22 18:55:53 2018 +0200
     2.2 +++ b/test/src/engine_tests/SyncTests.cc	Wed Aug 22 20:01:29 2018 +0200
     2.3 @@ -3,6 +3,7 @@
     2.4  
     2.5  #include <stdlib.h>
     2.6  #include <string>
     2.7 +#include <thread>
     2.8  
     2.9  #include "pEpEngine.h"
    2.10  #include "sync_api.h"
    2.11 @@ -41,14 +42,30 @@
    2.12      static Sync_event_t *retrieve_next_sync_event(void *management)
    2.13      {
    2.14          auto adapter = static_cast< Sync_Adapter *>(management);
    2.15 -        return adapter->q.pop_front();
    2.16 +        while (adapter->q.empty()) {
    2.17 +            sleep(1);
    2.18 +        }
    2.19 +        Sync_event_t *result = adapter->q.pop_front();
    2.20 +        if (result)
    2.21 +            cout << "retrieving sync event\n";
    2.22 +        else
    2.23 +            cout << "retrieving shutdown\n";
    2.24 +        return result;
    2.25      }
    2.26  
    2.27      static PEP_STATUS messageToSend(void *obj, struct _message *msg)
    2.28      {
    2.29          assert(msg);
    2.30 +        cout << "messageToSend\n";
    2.31          return PEP_STATUS_OK;
    2.32      }
    2.33 +
    2.34 +    static void sync_thread(PEP_SESSION session, Sync_Adapter *adapter)
    2.35 +    {
    2.36 +        cout << "sync_thread: startup\n";
    2.37 +        do_sync_protocol(session, adapter);
    2.38 +        cout << "sync_thread: shutdown\n";
    2.39 +    }
    2.40  };
    2.41  
    2.42  SyncTests::SyncTests(string suitename, string test_home_dir) :
    2.43 @@ -61,6 +78,7 @@
    2.44  {
    2.45      Sync_Adapter adapter;
    2.46      PEP_SESSION sync = NULL;
    2.47 +    thread *sync_thread;
    2.48  
    2.49      PEP_STATUS status = init(&sync, Sync_Adapter::messageToSend);
    2.50      TEST_ASSERT(status == PEP_STATUS_OK);
    2.51 @@ -73,8 +91,14 @@
    2.52              Sync_Adapter::retrieve_next_sync_event
    2.53          );
    2.54      TEST_ASSERT(status == PEP_STATUS_OK);
    2.55 +    TEST_ASSERT(sync->sync_state.keysync.state == Sole);
    2.56  
    2.57 -    TEST_ASSERT(sync->sync_state.keysync.state == Sole);
    2.58 +    cout << "creating thread for sync\n";
    2.59 +    sync_thread = new thread(Sync_Adapter::sync_thread, sync, &adapter);
    2.60 + 
    2.61 +    cout << "sending shutdown to sync thread\n";
    2.62 +    adapter.q.push_front(nullptr);
    2.63 +    sync_thread->join();
    2.64  
    2.65      unregister_sync_callbacks(sync);
    2.66      release(sync);