Scheduler: access invocation time for test
...find a way to sneak out the "now" parameter passed on Invocation ...this is prerequisite to demonstrate expected behaviour of the work-Function
This commit is contained in:
parent
7da88b772f
commit
5164ead929
5 changed files with 81 additions and 6 deletions
|
|
@ -194,6 +194,9 @@ namespace time {
|
|||
/** @internal diagnostics */
|
||||
operator std::string () const;
|
||||
|
||||
/** @return is in-domain, not a boundary value */
|
||||
bool isRegular() const;
|
||||
|
||||
// Supporting totally_ordered
|
||||
friend bool operator< (TimeValue const& t1, TimeValue const& t2) { return t1.t_ < t2.t_; }
|
||||
friend bool operator< (TimeValue const& t1, gavl_time_t t2) { return t1.t_ < t2 ; }
|
||||
|
|
@ -768,6 +771,13 @@ namespace time {
|
|||
: TimeSpan{start, extension};
|
||||
}
|
||||
|
||||
inline bool
|
||||
TimeValue::isRegular() const
|
||||
{
|
||||
return Time::MIN < *this
|
||||
and *this < Time::MAX;
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
TimeVar::TimeVar (FSecs const& fractionalSeconds)
|
||||
|
|
|
|||
|
|
@ -262,10 +262,16 @@ namespace test {
|
|||
Activity& probe = detector.buildActivationProbe (someID);
|
||||
CHECK (probe.is (Activity::HOOK));
|
||||
|
||||
CHECK (not detector.wasInvoked (probe));
|
||||
|
||||
Time realTime = RealClock::now();
|
||||
probe.activate (realTime, detector.executionCtx);
|
||||
|
||||
CHECK (detector.verifyInvocation(someID).timeArg(realTime));
|
||||
|
||||
// Probe instance recalls last invocation "now" argument
|
||||
CHECK (realTime == detector.invokeTime (probe));
|
||||
CHECK (detector.wasInvoked (probe));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -345,16 +345,18 @@ namespace test {
|
|||
*/
|
||||
class ActivityProbe
|
||||
: public Activity
|
||||
, activity::Hook
|
||||
, public activity::Hook
|
||||
{
|
||||
Logger log_;
|
||||
|
||||
TimeVar invoked_{Time::ANYTIME};
|
||||
|
||||
activity::Proc
|
||||
activation ( Activity& thisHook
|
||||
, Time now
|
||||
, void* executionCtx) override
|
||||
{
|
||||
REQUIRE (thisHook.is (Activity::HOOK));
|
||||
invoked_ = now;
|
||||
if (data_.callback.arg == 0)
|
||||
{// no adapted target; just record this activation
|
||||
log_(util::toString(now) + " ⧐ ");
|
||||
|
|
@ -375,6 +377,7 @@ namespace test {
|
|||
, void* executionCtx) override
|
||||
{
|
||||
REQUIRE (thisHook.is (Activity::HOOK));
|
||||
invoked_ = now;
|
||||
if (data_.callback.arg == 0)
|
||||
{// no adapted target; just record this notification
|
||||
log_(util::toString(now) + " --notify-↯• ");
|
||||
|
|
@ -412,6 +415,19 @@ namespace test {
|
|||
{
|
||||
return diagnostic();
|
||||
}
|
||||
|
||||
|
||||
static Time
|
||||
lastInvoked (Activity const* act)
|
||||
{
|
||||
if (act and act->verb_ == HOOK)
|
||||
{
|
||||
ActivityProbe* probe = dynamic_cast<ActivityProbe*> (act->data_.callback.hook);
|
||||
if (probe)
|
||||
return probe->invoked_;
|
||||
}
|
||||
return Time::NEVER;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -543,6 +559,12 @@ namespace test {
|
|||
}
|
||||
|
||||
|
||||
Time invokeTime (Activity const* hook) { return ActivityProbe::lastInvoked (hook); }
|
||||
bool wasInvoked (Activity const* hook) { return invokeTime(hook).isRegular(); }
|
||||
Time invokeTime (Activity const& hook) { return invokeTime (&hook); }
|
||||
bool wasInvoked (Activity const& hook) { return wasInvoked (&hook); }
|
||||
|
||||
|
||||
struct FakeExecutionCtx;
|
||||
using SIG_post = activity::Proc(Time, Activity*, FakeExecutionCtx&);
|
||||
using SIG_work = void(Time, size_t);
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include "vault/gear/scheduler.hpp"
|
||||
#include "lib/time/timevalue.hpp"
|
||||
#include "lib/format-cout.hpp"
|
||||
#include "lib/test/diagnostic-output.hpp"///////////////TODO
|
||||
//#include "lib/util.hpp"
|
||||
|
||||
//#include <utility>
|
||||
|
|
@ -106,6 +107,14 @@ namespace test {
|
|||
cout << detector.showLog()<<endl; // HINT: use this for investigation...
|
||||
CHECK (detector.verifyInvocation("testProbe"));
|
||||
////////////////////////////////////////////////////////////////////////////////////TODO need a way to get the actual time passed to the Probe
|
||||
SHOW_EXPR(now)
|
||||
SHOW_EXPR(detector.invokeTime(probe))
|
||||
|
||||
auto wasClose = [](TimeValue a, TimeValue b)
|
||||
{
|
||||
return Duration{Offset{a,b}} < Duration{FSecs{1,2000}}; // 500µs are considered "close"
|
||||
};
|
||||
CHECK (wasClose (now, detector.invokeTime (probe)));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -88132,11 +88132,39 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="pencil"/>
|
||||
<node CREATED="1698243387222" ID="ID_1151484757" MODIFIED="1698243397453" TEXT="und zwar direkten Aufruf, ohne WorkForce"/>
|
||||
<node CREATED="1698243399946" ID="ID_525069730" MODIFIED="1698243412341" TEXT="es kann zu Sleeps kommen"/>
|
||||
<node CREATED="1698243426549" ID="ID_1975979569" MODIFIED="1698243431240" TEXT="das bedeutet: Zeitmessung"/>
|
||||
<node CREATED="1698243426549" ID="ID_1975979569" MODIFIED="1698243431240" TEXT="das bedeutet: Zeitmessung">
|
||||
<node CREATED="1698269582160" ID="ID_211702790" MODIFIED="1698269611010" TEXT="und Prüfen unscharfer Zeitabstände">
|
||||
<icon BUILTIN="messagebox_warning"/>
|
||||
<node CREATED="1698269686974" ID="ID_586911111" MODIFIED="1698269697257" TEXT="wie viel Genauigkeit kann man da überhaupt erwarten?"/>
|
||||
<node CREATED="1698269698148" ID="ID_220147663" MODIFIED="1698269740149" TEXT="RealClock::wasRecently setzt 1ms an">
|
||||
<richcontent TYPE="NOTE"><html>
|
||||
<head>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<p>
|
||||
...und das erscheint adäquat für moderne Maschinen
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
</richcontent>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1698269741040" ID="ID_868809913" MODIFIED="1698269752607" TEXT="verusche mal mein Glück mit 500µs">
|
||||
<icon BUILTIN="pencil"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1698269618101" ID="ID_561925985" MODIFIED="1698269648550" TEXT="...das macht diesen Test ziemlich fragwürdig">
|
||||
<icon BUILTIN="broken-line"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1698269656739" ID="ID_851832685" MODIFIED="1698269684671" TEXT="muß auf sehr deutliche Zeitungerschiede abzielen">
|
||||
<icon BUILTIN="yes"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#f0d5c5" COLOR="#990033" CREATED="1698243664309" ID="ID_654541946" MODIFIED="1698243687277" TEXT="was kann man sinnvollerweise prüfen?">
|
||||
<icon BUILTIN="help"/>
|
||||
<node CREATED="1698243697817" ID="ID_83311166" MODIFIED="1698243708627" TEXT="eine eingespiele Activity wird aufgerufen"/>
|
||||
<node CREATED="1698243756225" ID="ID_489965107" MODIFIED="1698243775440" TEXT="was fällig ist, wird sofort aufgerufen"/>
|
||||
<node CREATED="1698243756225" ID="ID_489965107" MODIFIED="1698268874810" TEXT="was fällig ist, wird direkt vom post() aufgerufen"/>
|
||||
<node CREATED="1698243756225" ID="ID_831882516" MODIFIED="1698268923359" TEXT="was fällig wurde, wird unverzögert aufgerufen"/>
|
||||
<node CREATED="1698243881573" ID="ID_1520192624" MODIFIED="1698243892539" TEXT="es wird genau eine scheduled Activity aufgerufen"/>
|
||||
<node CREATED="1698243927930" ID="ID_1326757783" MODIFIED="1698243935709" TEXT="die Zeit wird in etwa eingehalten"/>
|
||||
<node CREATED="1698243794737" ID="ID_1290805695" MODIFIED="1698243800463" TEXT="das Delay-Regime">
|
||||
|
|
@ -88163,8 +88191,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="info"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1698246249997" ID="ID_221908219" MODIFIED="1698246271187" TEXT="muß mir die now-Zeit in ActivityProbe speichern">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1698246249997" ID="ID_221908219" MODIFIED="1698269566601" TEXT="muß mir die now-Zeit in ActivityProbe speichern">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1698246275186" ID="ID_389803917" MODIFIED="1698246286348" TEXT="bei jedem Aufruf im Objekt speichern"/>
|
||||
<node CREATED="1698246286912" ID="ID_1611070007" MODIFIED="1698246292046" TEXT="Zugriffs-Funktion schaffen"/>
|
||||
</node>
|
||||
|
|
|
|||
Loading…
Reference in a new issue