Library/Application: switch CallQueue_test

This commit is contained in:
Fischlurch 2023-10-05 01:17:58 +02:00
parent 332ad0e920
commit 77622a3f2d
3 changed files with 23 additions and 18 deletions

View file

@ -27,13 +27,13 @@
#include "lib/test/run.hpp"
#include "lib/scoped-collection.hpp"
#include "vault/thread-wrapper.hpp"
#include "lib/sync-barrier.hpp"
#include "lib/thread.hpp"
#include "lib/sync.hpp"
#include "lib/util.hpp"
#include "lib/call-queue.hpp"
#include <functional>
#include <string>
@ -42,11 +42,11 @@ namespace lib {
namespace test{
using lib::Sync;
using vault::ThreadJoinable;
using lib::SyncBarrier;
using lib::ThreadJoinable;
using util::isnil;
using std::string;
using std::bind;
@ -103,8 +103,7 @@ namespace test{
* @test verify a helper component for dispatching functors through a threadsafe queue.
* - simple usage
* - enqueue and dequeue several functors
* - multithreaded stress test
*
* - multithreaded load test
* @see lib::CallQueue
* @see stage::NotificationService usage example
* @see [DemoGuiRoundtrip](http://issues.lumiera.org/ticket/1099 "Ticket #1099")
@ -181,12 +180,14 @@ namespace test{
struct Worker
: ThreadJoinable
: ThreadJoinable<>
, Sync<>
{
uint64_t producerSum = 0;
uint64_t consumerSum = 0;
SyncBarrier& trigger_;
void
countConsumerCall (uint increment)
{
@ -194,13 +195,13 @@ namespace test{
consumerSum += increment;
}
Worker(CallQueue& queue)
Worker(CallQueue& queue, SyncBarrier& commonTrigger)
: ThreadJoinable{"CallQueue_test: concurrent dispatch"
, [&]() {
uint cnt = rand() % MAX_RAND_STEPS;
uint delay = rand() % MAX_RAND_DELAY;
syncPoint(); // block until all threads are ready
trigger_.sync(); // block until all threads are ready
for (uint i=0; i<cnt; ++i)
{
uint increment = rand() % MAX_RAND_INCMT;
@ -210,6 +211,7 @@ namespace test{
queue.invoke(); // NOTE: dequeue one functor added during our sleep
} // and thus belonging to some random other thread
}}
, trigger_{commonTrigger}
{ }
};
@ -226,22 +228,24 @@ namespace test{
verify_ThreadSafety()
{
CallQueue queue;
SyncBarrier trigger{NUM_OF_THREADS + 1};
// Start a bunch of threads with random access pattern
Workers workers{NUM_OF_THREADS,
[&](Workers::ElementHolder& storage)
{
storage.create<Worker>(queue);
storage.create<Worker> (queue, trigger);
}
};
// unleash all worker functions
for (auto& thread : workers)
thread.sync();
trigger.sync();
// wait for termination of all threads
// wait for termination of all threads and detect possible exceptions
bool allFine{true};
for (auto& worker : workers)
worker.join();
allFine &= worker.join().isValid();
CHECK (allFine);
// collect the results of all worker threads
uint64_t globalProducerSum = 0;

View file

@ -69,7 +69,7 @@
** verify the checksum before all command instances have been triggered. To avoid this
** situation, make sure the delay between actions in the threads is not too long and
** start a sufficiently high number of producer threads.
**
**
*/
@ -88,7 +88,6 @@ extern "C" {
#include "lib/thread.hpp"
#include "lib/symbol.hpp"
#include "lib/util.hpp"
#include "lib/test/diagnostic-output.hpp"////////////////////TODO
#include <boost/lexical_cast.hpp>
#include <chrono>
@ -216,7 +215,7 @@ namespace test {
}
//-------------(End)FIXTURE
virtual void
run (Arg args_for_stresstest)
{

View file

@ -81084,7 +81084,9 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
</node>
</node>
</node>
<node CREATED="1696029465120" ID="ID_1705540772" MODIFIED="1696029510893" TEXT="call-queue-test.cpp (/zLumi/tests/basics)"/>
<node COLOR="#338800" CREATED="1696029465120" ID="ID_1705540772" MODIFIED="1696461340096" TEXT="CallQueue_test">
<icon BUILTIN="button_ok"/>
</node>
<node CREATED="1696029465120" ID="ID_1782746519" MODIFIED="1696029465120" TEXT="bus-term-test.cpp (/zLumi/tests/stage)"/>
</node>
<node CREATED="1696029465119" ID="ID_820648476" MODIFIED="1696029572456" TEXT="eigentliche Verwendungen">