diff --git a/src/vault/gear/work-force.hpp b/src/vault/gear/work-force.hpp index 213889b9f..14a2b747f 100644 --- a/src/vault/gear/work-force.hpp +++ b/src/vault/gear/work-force.hpp @@ -42,6 +42,7 @@ #include "lib/nocopy.hpp" //#include "lib/symbol.hpp" #include "lib/util.hpp" +#include "lib/format-cout.hpp"////////////////////WIP //#include #include @@ -108,6 +109,8 @@ namespace gear { break; if (res == activity::WAIT) res = idleWait(); + else + idleCycles = 0; if (res != activity::PASS) break; } @@ -120,10 +123,16 @@ namespace gear { activity::Proc idleWait() { - std::this_thread::sleep_for (CONF::IDLE_WAIT); - ////////////////////////////////WIP extended inactivity detector here - return activity::PASS; + ++idleCycles; + if (idleCycles < CONF::DISMISS_CYCLES) + { + std::this_thread::sleep_for (CONF::IDLE_WAIT); + return activity::PASS; + } + else // idle beyond threshold => terminate worker + return activity::HALT; } + size_t idleCycles{0}; }; }//(End)namespace work diff --git a/tests/vault/gear/work-force-test.cpp b/tests/vault/gear/work-force-test.cpp index bc4673d4d..ac426a082 100644 --- a/tests/vault/gear/work-force-test.cpp +++ b/tests/vault/gear/work-force-test.cpp @@ -197,8 +197,7 @@ namespace test { - /** @test TODO - * @todo WIP 9/23 ⟶ define ⟶ implement + /** @test a worker can be sent to sleep, reducing the poll frequency. */ void verify_workerSleep() @@ -215,18 +214,34 @@ namespace test { sleep_for(10us); CHECK (1 == check); - sleep_for(10ms); // after waiting one sleep-period... + sleep_for(12ms); // after waiting one sleep-period... CHECK (2 == check); // ...functor invoked again } - /** @test TODO - * @todo WIP 9/23 ⟶ define ⟶ implement + /** @test when a worker is sent into sleep-cycles for an extended time, + * the worker terminates itself */ void verify_workerDismiss() { + atomic check{0}; + WorkForce wof{setup ([&]{ ++check; return activity::WAIT; }) + .withSleepPeriod (10ms) + .dismissAfter(5)}; + + wof.incScale(); + sleep_for(20us); + + CHECK (1 == check); + + sleep_for(10ms); + CHECK (2 == check); // after one wait cycle, one further invocation + + sleep_for(100ms); + CHECK (5 == check); // only 5 invocations total... + CHECK (0 == wof.size()); // ...after that, the worker terminated } @@ -293,7 +308,7 @@ namespace test { atomic check{0}; WorkForce wof{setup ([&]{ ++check; - if (check == 10'000 or check == 10'110) + if (check == 5'000 or check == 5'110) return activity::HALT; else return activity::PASS; @@ -308,7 +323,8 @@ namespace test { CHECK (3 == wof.size()); - sleep_for(200ms); // ...sufficiently long to count way beyond 10'000 + sleep_for(500ms); // ...sufficiently long to count way beyond 10'000 + CHECK (check > 6'000); CHECK (1 == wof.size()); } diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index d6f38b113..700671488 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -80047,8 +80047,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + +