Workforce: demonstrate controlled worker-stop

- workers can be controlled by the return-value from the work functor
- this test could be brittle, since it's based on timing and CPU speed
This commit is contained in:
Fischlurch 2023-09-08 14:32:37 +02:00
parent ef5365057a
commit 67a3e87dbc
2 changed files with 48 additions and 9 deletions

View file

@ -28,7 +28,8 @@
#include "lib/test/run.hpp"
#include "vault/gear/work-force.hpp"
//#include "lib/time/timevalue.hpp"
#include "lib/format-cout.hpp" ///////////////////////////////WIP
//#include "lib/format-cout.hpp" ///////////////////////////////WIP
#include "lib/test/diagnostic-output.hpp" ///////////////////////////////WIP
//#include "lib/util.hpp"
//#include <utility>
@ -150,12 +151,27 @@ namespace test {
/** @test TODO
* @todo WIP 9/23 define implement
/** @test can cause a worker to terminate by return-value from the work-functor
*/
void
verify_workerHalt()
{
atomic<uint> check{0};
atomic<activity::Proc> control{activity::PASS};
WorkForce wof{setup ([&]{ ++check; return activity::Proc(control); })};
wof.incScale();
sleep_for(1ms);
uint invocations = check;
CHECK (0 < invocations);
control = activity::HALT;
sleep_for(1ms);
invocations = check;
sleep_for(10ms);
CHECK (invocations == check);
}
@ -234,12 +250,31 @@ namespace test {
/** @test TODO
* @todo WIP 9/23 define implement
/** @test dynamically determine count of currently active workers.
*/
void
verify_countActive()
{
atomic<uint> check{0};
WorkForce wof{setup ([&]{
++check;
if (check == 100'000 or check == 100'110)
return activity::HALT;
else
return activity::PASS;
})};
CHECK (0 == wof.size());
wof.incScale();
wof.incScale();
wof.incScale();
sleep_for(10us); // this may be fragile; must be sufficiently short
CHECK (3 == wof.size());
sleep_for(50ms);
CHECK (1 == wof.size());
}

View file

@ -80041,8 +80041,8 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node COLOR="#338800" CREATED="1694098758090" ID="ID_1594595049" MODIFIED="1694174633952" TEXT="verify_pullWork: f&#xfc;hrt den Work-Funktor wiederholt aus">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1694098814770" ID="ID_495507864" MODIFIED="1694099559955" TEXT="verify_workerHalt: terminiert auf Anweisung">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1694098814770" ID="ID_495507864" MODIFIED="1694175245569" TEXT="verify_workerHalt: terminiert auf Anweisung">
<icon BUILTIN="button_ok"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1694098789389" ID="ID_1077314922" MODIFIED="1694099559954" TEXT="verify_workerSleep: schl&#xe4;ft auf Anweisung">
<icon BUILTIN="flag-yellow"/>
@ -80069,8 +80069,12 @@ Date:&#160;&#160;&#160;Thu Apr 20 18:53:17 2023 +0200<br/>
<node CREATED="1694099029004" ID="ID_910692339" MODIFIED="1694099041032" TEXT="skaliert auf genau N worker"/>
<node CREATED="1694099061344" ID="ID_758198253" MODIFIED="1694099067644" TEXT="skaliert um einen Worker hoch"/>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1694099080950" ID="ID_542625093" MODIFIED="1694099566207" TEXT="verify_countActive: ermittelt Zahl aktiver Worker">
<icon BUILTIN="flag-yellow"/>
<node COLOR="#338800" CREATED="1694099080950" ID="ID_542625093" MODIFIED="1694176109416" TEXT="verify_countActive: ermittelt Zahl aktiver Worker">
<icon BUILTIN="button_ok"/>
<node CREATED="1694176125532" ID="ID_1861823619" MODIFIED="1694176149434" TEXT="lasse das work-&#x3bb; zweimal ein HALT zur&#xfc;ckgeben"/>
<node CREATED="1694176110582" ID="ID_129912527" MODIFIED="1694176151624" TEXT="etwas fragil, da ich genau timen mu&#xdf;">
<icon BUILTIN="messagebox_warning"/>
</node>
</node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1694099160252" ID="ID_950338764" MODIFIED="1694099567838" TEXT="verify_dtor_blocks">
<icon BUILTIN="flag-yellow"/>