diff --git a/src/keri/app/agenting.py b/src/keri/app/agenting.py index 0596f948a..cebd520a3 100644 --- a/src/keri/app/agenting.py +++ b/src/keri/app/agenting.py @@ -14,7 +14,7 @@ from socket import gaierror -from . import httping, forwarding +from . import httping, forwarding, tocking from .. import help from .. import kering from .. import core @@ -295,7 +295,7 @@ def __init__(self, hby, msgs=None, cues=None, force=False, auths=None, **kwa): super(WitnessReceiptor, self).__init__(doers=[doing.doify(self.receiptDo)], **kwa) - def receiptDo(self, tymth=None, tock=0.0, **kwa): + def receiptDo(self, tymth=None, tock=None, **kwa): """ Returns doifiable Doist compatible generator method (doer dog) @@ -309,7 +309,7 @@ def receiptDo(self, tymth=None, tock=0.0, **kwa): """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.WitnessReceiptorTock _ = (yield self.tock) while True: @@ -450,7 +450,7 @@ def __init__(self, hby, reger=None, msgs=None, klas=None, **kwa): super(WitnessInquisitor, self).__init__(doers=[doing.doify(self.msgDo)], **kwa) - def msgDo(self, tymth=None, tock=1.0, **opts): + def msgDo(self, tymth=None, tock=None, **opts): """ Returns doifiable Doist compatible generator method (doer dog) @@ -458,7 +458,7 @@ def msgDo(self, tymth=None, tock=1.0, **opts): add result of doify on this method to doers list """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.WitnessInquisitorTock _ = (yield self.tock) while True: @@ -588,7 +588,7 @@ def __init__(self, hby, msgs=None, cues=None, **kwa): self.cues = cues if cues is not None else decking.Deck() super(WitnessPublisher, self).__init__(doers=[doing.doify(self.sendDo)], **kwa) - def sendDo(self, tymth=None, tock=0.0, **opts): + def sendDo(self, tymth=None, tock=None, **opts): """ Returns doifiable Doist compatible generator method (doer dog) @@ -596,7 +596,7 @@ def sendDo(self, tymth=None, tock=0.0, **opts): add result of doify on this method to doers list """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.WitnessPublisherTock _ = (yield self.tock) while True: diff --git a/src/keri/app/directing.py b/src/keri/app/directing.py index 6c72fc987..5da16998c 100644 --- a/src/keri/app/directing.py +++ b/src/keri/app/directing.py @@ -8,6 +8,7 @@ import itertools from hio.base import doing +from . import tocking from .. import help from ..core import eventing, routing from ..core import parsing @@ -207,7 +208,7 @@ def wind(self, tymth): self.client.wind(tymth) - def msgDo(self, tymth=None, tock=0.0, **opts): + def msgDo(self, tymth=None, tock=None, **opts): """ Returns doifiable Doist compatibile generator method (doer dog) to process incoming message stream of .kevery @@ -227,14 +228,16 @@ def msgDo(self, tymth=None, tock=0.0, **opts): Usage: add result of doify on this method to doers list """ - yield # enter context + self.wind(tymth) + self.tock = tock if tock is not None else tocking.ReactorMsgTock + _ = (yield self.tock) # enter context if self.parser.ims: logger.info("Client %s received:\n%s\n...\n", self.hab.name, self.parser.ims[:1024]) done = yield from self.parser.parsator(local=True) # process messages continuously return done # should nover get here except forced close - def cueDo(self, tymth=None, tock=0.0, **opts): + def cueDo(self, tymth=None, tock=None, **opts): """ Returns doifiable Doist compatibile generator method (doer dog) to process .kevery.cues deque @@ -253,15 +256,17 @@ def cueDo(self, tymth=None, tock=0.0, **opts): Usage: add result of doify on this method to doers list """ - yield # enter context + self.wind(tymth) + self.tock = tock if tock is not None else tocking.ReactorCueTock + _ = (yield self.tock) # enter context while True: for msg in self.hab.processCuesIter(self.kevery.cues): self.sendMessage(msg, label="chit or receipt") - yield # throttle just do one cue at a time - yield + yield self.tock # throttle just do one cue at a time + yield self.tock return False # should never get here except forced close - def escrowDo(self, tymth=None, tock=0.0, **opts): + def escrowDo(self, tymth=None, tock=None, **opts): """ Returns doifiable Doist compatibile generator method (doer dog) to process .kevery escrows. @@ -280,12 +285,14 @@ def escrowDo(self, tymth=None, tock=0.0, **opts): Usage: add result of doify on this method to doers list """ - yield # enter context + self.wind(tymth) + self.tock = tock if tock is not None else tocking.ReactorEscrowTock + _ = (yield self.tock) # enter context while True: self.kevery.processEscrows() if self.tvy is not None: self.tvy.processEscrows() - yield + yield self.tock return False # should never get here except forced close def sendMessage(self, msg, label=""): @@ -561,7 +568,7 @@ def wind(self, tymth): self.remoter.wind(tymth) - def msgDo(self, tymth=None, tock=0.0, **opts): + def msgDo(self, tymth=None, tock=None, **opts): """ Returns doifiable Doist compatibile generator method (doer dog) to process incoming message stream of .kevery @@ -581,7 +588,9 @@ def msgDo(self, tymth=None, tock=0.0, **opts): Usage: add result of doify on this method to doers list """ - yield # enter context + self.wind(tymth) + self.tock = tock if tock is not None else tocking.ReactantMsgTock + _ = (yield self.tock) # enter context if self.parser.ims: logger.info("Server %s: received:\n%s\n...\n", self.hab.name, self.parser.ims[:1024]) @@ -589,7 +598,7 @@ def msgDo(self, tymth=None, tock=0.0, **opts): return done # should nover get here except forced close - def cueDo(self, tymth=None, tock=0.0, **opts): + def cueDo(self, tymth=None, tock=None, **opts): """ Returns doifiable Doist compatibile generator method (doer dog) to process .kevery.cues deque @@ -608,19 +617,21 @@ def cueDo(self, tymth=None, tock=0.0, **opts): Usage: add result of doify on this method to doers list """ - yield # enter context + self.wind(tymth) + self.tock = tock if tock is not None else tocking.ReactantCueTock + _ = (yield self.tock) # enter context while True: for msg in self.hab.processCuesIter(self.kevery.cues): if isinstance(msg, list): msg = bytearray(itertools.chain(*msg)) self.sendMessage(msg, label="chit or receipt or replay") - yield # throttle just do one cue at a time - yield + yield self.tock # throttle just do one cue at a time + yield self.tock return False # should never get here except forced close - def escrowDo(self, tymth=None, tock=0.0, **opts): + def escrowDo(self, tymth=None, tock=None, **opts): """ Returns doifiable Doist compatibile generator method (doer dog) to process .kevery escrows. @@ -639,12 +650,14 @@ def escrowDo(self, tymth=None, tock=0.0, **opts): Usage: add result of doify on this method to doers list """ - yield # enter context + self.wind(tymth) + self.tock = tock if tock is not None else tocking.ReactantEscrowTock + _ = (yield self.tock) # enter context while True: self.kevery.processEscrows() if self.tevery is not None: self.tevery.processEscrows() - yield + yield self.tock return False # should never get here except forced close def sendMessage(self, msg, label=""): diff --git a/src/keri/app/indirecting.py b/src/keri/app/indirecting.py index 91b77e098..f722c0408 100644 --- a/src/keri/app/indirecting.py +++ b/src/keri/app/indirecting.py @@ -19,7 +19,7 @@ from hio.help import decking import keri.app.oobiing -from . import directing, storing, httping, forwarding, agenting, oobiing +from . import directing, storing, httping, forwarding, agenting, oobiing, tocking from .habbing import GroupHab from .. import help, kering from ..core import (eventing, parsing, routing, coring, serdering, @@ -181,7 +181,7 @@ def start(self, tymth=None, tock=0.0, **kwa): print("Witness", self.hab.name, ":", self.hab.pre) - def msgDo(self, tymth=None, tock=0.0, **kwa): + def msgDo(self, tymth=None, tock=None, **kwa): """ Returns doifiable Doist compatibile generator method (doer dog) to process incoming message stream of .kevery @@ -195,7 +195,7 @@ def msgDo(self, tymth=None, tock=0.0, **kwa): add result of doify on this method to doers list """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.WitnessMsgTock _ = (yield self.tock) if self.parser.ims: @@ -203,7 +203,7 @@ def msgDo(self, tymth=None, tock=0.0, **kwa): done = yield from self.parser.parsator(local=True) # process messages continuously return done # should nover get here except forced close - def escrowDo(self, tymth=None, tock=0.0, **kwa): + def escrowDo(self, tymth=None, tock=None, **kwa): """ Returns doifiable Doist compatibile generator method (doer dog) to process .kevery and .tevery escrows. @@ -217,7 +217,7 @@ def escrowDo(self, tymth=None, tock=0.0, **kwa): add result of doify on this method to doers list """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.WitnessEscrowTock _ = (yield self.tock) while True: @@ -227,9 +227,9 @@ def escrowDo(self, tymth=None, tock=0.0, **kwa): self.tvy.processEscrows() self.exc.processEscrow() - yield + yield self.tock - def cueDo(self, tymth=None, tock=0.0, **kwa): + def cueDo(self, tymth=None, tock=None, **kwa): """ Returns doifiable Doist compatibile generator method (doer dog) to process .kevery.cues deque @@ -248,7 +248,7 @@ def cueDo(self, tymth=None, tock=0.0, **kwa): add result of doify on this method to doers list """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.WitnessCueTock _ = (yield self.tock) while True: @@ -365,7 +365,7 @@ def wind(self, tymth): super(Indirector, self).wind(tymth) self.client.wind(tymth) - def msgDo(self, tymth=None, tock=0.0, **kwa): + def msgDo(self, tymth=None, tock=None, **kwa): """ Returns doifiable Doist compatibile generator method (doer dog) to process incoming message stream of .kevery @@ -384,7 +384,7 @@ def msgDo(self, tymth=None, tock=0.0, **kwa): add result of doify on this method to doers list """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.IndirectorMsgTock _ = (yield self.tock) if self.parser.ims: @@ -392,7 +392,7 @@ def msgDo(self, tymth=None, tock=0.0, **kwa): done = yield from self.parser.parsator(local=True) # process messages continuously return done # should nover get here except forced close - def cueDo(self, tymth=None, tock=0.0, **kwa): + def cueDo(self, tymth=None, tock=None, **kwa): """ Returns doifiable Doist compatibile generator method (doer dog) to process .kevery.cues deque @@ -411,16 +411,16 @@ def cueDo(self, tymth=None, tock=0.0, **kwa): add result of doify on this method to doers list """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.IndirectorCueTock _ = (yield self.tock) while True: for msg in self.hab.processCuesIter(self.kevery.cues): self.sendMessage(msg, label="chit or receipt") - yield # throttle just do one cue at a time - yield + yield self.tock # throttle just do one cue at a time + yield self.tock - def escrowDo(self, tymth=None, tock=0.0, **kwa): + def escrowDo(self, tymth=None, tock=None, **kwa): """ Returns doifiable Doist compatibile generator method (doer dog) to process .kevery escrows. @@ -439,12 +439,12 @@ def escrowDo(self, tymth=None, tock=0.0, **kwa): add result of doify on this method to doers list """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.IndirectorEscrowTock _ = (yield self.tock) while True: self.kevery.processEscrows() - yield + yield self.tock def sendMessage(self, msg, label=""): """ @@ -580,7 +580,7 @@ def wind(self, tymth): """ super(MailboxDirector, self).wind(tymth) - def pollDo(self, tymth=None, tock=0.0, **kwa): + def pollDo(self, tymth=None, tock=None, **kwa): """ Returns: doifiable Doist compatible generator method @@ -590,7 +590,7 @@ def pollDo(self, tymth=None, tock=0.0, **kwa): """ # enter context self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.MailboxPollTock _ = (yield self.tock) habs = list(self.hby.habs.values()) @@ -658,7 +658,7 @@ def processPollIter(self): msg = mail.pop(0) yield msg - def msgDo(self, tymth=None, tock=0.0, **kwa): + def msgDo(self, tymth=None, tock=None, **kwa): """ Returns doifiable Doist compatibile generator method (doer dog) to process incoming message stream of .kevery @@ -677,13 +677,13 @@ def msgDo(self, tymth=None, tock=0.0, **kwa): add result of doify on this method to doers list """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.MailboxMsgTock _ = (yield self.tock) done = yield from self.parser.parsator(local=True) # process messages continuously return done # should nover get here except forced close - def escrowDo(self, tymth=None, tock=0.0, **kwa): + def escrowDo(self, tymth=None, tock=None, **kwa): """ Returns doifiable Doist compatibile generator method (doer dog) to process .kevery escrows. @@ -702,7 +702,7 @@ def escrowDo(self, tymth=None, tock=0.0, **kwa): add result of doify on this method to doers list """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.MailboxEscrowTock _ = (yield self.tock) while True: @@ -715,7 +715,7 @@ def escrowDo(self, tymth=None, tock=0.0, **kwa): if self.verifier is not None: self.verifier.processEscrows() - yield + yield self.tock @property def times(self): @@ -756,7 +756,7 @@ def __init__(self, hab, witness, topics, msgs=None, retry=1000, **kwa): super(Poller, self).__init__(doers=doers, **kwa) - def eventDo(self, tymth=None, tock=0.0, **kwa): + def eventDo(self, tymth=None, tock=None, **kwa): """ Returns: doifiable Doist compatible generator method @@ -765,7 +765,7 @@ def eventDo(self, tymth=None, tock=0.0, **kwa): add result of doify on this method to doers list """ self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.PollerEventTock _ = (yield self.tock) witrec = self.hab.db.tops.get((self.pre, self.witness)) @@ -1154,7 +1154,7 @@ def on_get(self, req, rep): rep.status = falcon.HTTP_200 rep.data = rct - def interceptDo(self, tymth=None, tock=0.0, **kwa): + def interceptDo(self, tymth=None, tock=None, **kwa): """ Returns doifiable Doist compatibile generator method (doer dog) to process Kevery and Tevery cues deque @@ -1164,7 +1164,7 @@ def interceptDo(self, tymth=None, tock=0.0, **kwa): """ # enter context self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.ReceiptInterceptTock _ = (yield self.tock) while True: diff --git a/src/keri/app/storing.py b/src/keri/app/storing.py index db858a8b4..4a687130d 100644 --- a/src/keri/app/storing.py +++ b/src/keri/app/storing.py @@ -8,7 +8,7 @@ from hio.help import decking from ordered_set import OrderedSet as oset -from . import forwarding +from . import forwarding, tocking from .. import help from ..core import coring, serdering from ..core.coring import MtrDex @@ -232,7 +232,7 @@ def responseDo(self, tymth=None, tock=0.0, **kwa): yield self.tock - def cueDo(self, tymth=None, tock=0.0, **kwa): + def cueDo(self, tymth=None, tock=None, **kwa): """ Returns doifiable Doist compatibile generator method (doer dog) to process Kevery and Tevery cues deque @@ -242,7 +242,7 @@ def cueDo(self, tymth=None, tock=0.0, **kwa): """ # enter context self.wind(tymth) - self.tock = tock + self.tock = tock if tock is not None else tocking.RespondantCueTock _ = (yield self.tock) while True: diff --git a/src/keri/app/tocking.py b/src/keri/app/tocking.py new file mode 100644 index 000000000..a97d6264c --- /dev/null +++ b/src/keri/app/tocking.py @@ -0,0 +1,89 @@ +# -*- encoding: utf-8 -*- +""" +keri.app.tocking module + +Centralized tock configuration for doer timing control. +Environment variables allow production tuning without code changes. + +Tock values control how frequently doer methods execute: +- 0.0 = run as soon as possible (~31ms doist interval) +- 1.0 = run once per second +- Higher values = less frequent execution, lower CPU usage + +""" +import os + +# Witness component tocks (indirecting.py - WitnessStart) +KERI_WITNESS_MSG_TOCK_KEY = "KERI_WITNESS_MSG_TOCK" +KERI_WITNESS_ESCROW_TOCK_KEY = "KERI_WITNESS_ESCROW_TOCK" +KERI_WITNESS_CUE_TOCK_KEY = "KERI_WITNESS_CUE_TOCK" + +WitnessMsgTock = float(os.getenv(KERI_WITNESS_MSG_TOCK_KEY, "0.0")) +WitnessEscrowTock = float(os.getenv(KERI_WITNESS_ESCROW_TOCK_KEY, "1.0")) +WitnessCueTock = float(os.getenv(KERI_WITNESS_CUE_TOCK_KEY, "0.25")) + +# Indirector component tocks (indirecting.py - Indirector) +KERI_INDIRECTOR_MSG_TOCK_KEY = "KERI_INDIRECTOR_MSG_TOCK" +KERI_INDIRECTOR_CUE_TOCK_KEY = "KERI_INDIRECTOR_CUE_TOCK" +KERI_INDIRECTOR_ESCROW_TOCK_KEY = "KERI_INDIRECTOR_ESCROW_TOCK" + +IndirectorMsgTock = float(os.getenv(KERI_INDIRECTOR_MSG_TOCK_KEY, "0.0")) +IndirectorCueTock = float(os.getenv(KERI_INDIRECTOR_CUE_TOCK_KEY, "0.25")) +IndirectorEscrowTock = float(os.getenv(KERI_INDIRECTOR_ESCROW_TOCK_KEY, "1.0")) + +# MailboxDirector component tocks (indirecting.py - MailboxDirector) +KERI_MAILBOX_POLL_TOCK_KEY = "KERI_MAILBOX_POLL_TOCK" +KERI_MAILBOX_MSG_TOCK_KEY = "KERI_MAILBOX_MSG_TOCK" +KERI_MAILBOX_ESCROW_TOCK_KEY = "KERI_MAILBOX_ESCROW_TOCK" + +MailboxPollTock = float(os.getenv(KERI_MAILBOX_POLL_TOCK_KEY, "0.5")) +MailboxMsgTock = float(os.getenv(KERI_MAILBOX_MSG_TOCK_KEY, "0.0")) +MailboxEscrowTock = float(os.getenv(KERI_MAILBOX_ESCROW_TOCK_KEY, "1.0")) + +# Poller component tocks (indirecting.py - Poller) +KERI_POLLER_EVENT_TOCK_KEY = "KERI_POLLER_EVENT_TOCK" + +PollerEventTock = float(os.getenv(KERI_POLLER_EVENT_TOCK_KEY, "0.5")) + +# ReceiptEnd component tocks (indirecting.py - ReceiptEnd) +KERI_RECEIPT_INTERCEPT_TOCK_KEY = "KERI_RECEIPT_INTERCEPT_TOCK" + +ReceiptInterceptTock = float(os.getenv(KERI_RECEIPT_INTERCEPT_TOCK_KEY, "0.1")) + +# Reactor component tocks (directing.py - Reactor) +KERI_REACTOR_MSG_TOCK_KEY = "KERI_REACTOR_MSG_TOCK" +KERI_REACTOR_CUE_TOCK_KEY = "KERI_REACTOR_CUE_TOCK" +KERI_REACTOR_ESCROW_TOCK_KEY = "KERI_REACTOR_ESCROW_TOCK" + +ReactorMsgTock = float(os.getenv(KERI_REACTOR_MSG_TOCK_KEY, "0.0")) +ReactorCueTock = float(os.getenv(KERI_REACTOR_CUE_TOCK_KEY, "0.25")) +ReactorEscrowTock = float(os.getenv(KERI_REACTOR_ESCROW_TOCK_KEY, "1.0")) + +# Reactant component tocks (directing.py - Reactant) +KERI_REACTANT_MSG_TOCK_KEY = "KERI_REACTANT_MSG_TOCK" +KERI_REACTANT_CUE_TOCK_KEY = "KERI_REACTANT_CUE_TOCK" +KERI_REACTANT_ESCROW_TOCK_KEY = "KERI_REACTANT_ESCROW_TOCK" + +ReactantMsgTock = float(os.getenv(KERI_REACTANT_MSG_TOCK_KEY, "0.0")) +ReactantCueTock = float(os.getenv(KERI_REACTANT_CUE_TOCK_KEY, "0.25")) +ReactantEscrowTock = float(os.getenv(KERI_REACTANT_ESCROW_TOCK_KEY, "1.0")) + +# Respondant component tocks (storing.py - Respondant) +KERI_RESPONDANT_CUE_TOCK_KEY = "KERI_RESPONDANT_CUE_TOCK" + +RespondantCueTock = float(os.getenv(KERI_RESPONDANT_CUE_TOCK_KEY, "0.25")) + +# WitnessReceiptor component tocks (agenting.py) +KERI_WITNESS_RECEIPTOR_TOCK_KEY = "KERI_WITNESS_RECEIPTOR_TOCK" + +WitnessReceiptorTock = float(os.getenv(KERI_WITNESS_RECEIPTOR_TOCK_KEY, "0.0")) + +# WitnessInquisitor component tocks (agenting.py) +KERI_WITNESS_INQUISITOR_TOCK_KEY = "KERI_WITNESS_INQUISITOR_TOCK" + +WitnessInquisitorTock = float(os.getenv(KERI_WITNESS_INQUISITOR_TOCK_KEY, "1.0")) + +# WitnessPublisher component tocks (agenting.py) +KERI_WITNESS_PUBLISHER_TOCK_KEY = "KERI_WITNESS_PUBLISHER_TOCK" + +WitnessPublisherTock = float(os.getenv(KERI_WITNESS_PUBLISHER_TOCK_KEY, "0.25")) diff --git a/tests/app/test_tocking.py b/tests/app/test_tocking.py new file mode 100644 index 000000000..1a03bcae8 --- /dev/null +++ b/tests/app/test_tocking.py @@ -0,0 +1,258 @@ +# -*- encoding: utf-8 -*- +""" +tests.app.test_tocking module + +Tests for centralized tock configuration. +""" +import os +import importlib + +import pytest + + +def test_tocking_defaults(): + """ + Test default tock values when no environment variables are set + """ + # Clear any existing env vars that might affect the test + env_keys = [ + "KERI_WITNESS_MSG_TOCK", + "KERI_WITNESS_ESCROW_TOCK", + "KERI_WITNESS_CUE_TOCK", + "KERI_INDIRECTOR_MSG_TOCK", + "KERI_INDIRECTOR_CUE_TOCK", + "KERI_INDIRECTOR_ESCROW_TOCK", + "KERI_MAILBOX_POLL_TOCK", + "KERI_MAILBOX_MSG_TOCK", + "KERI_MAILBOX_ESCROW_TOCK", + "KERI_POLLER_EVENT_TOCK", + "KERI_RECEIPT_INTERCEPT_TOCK", + "KERI_REACTOR_MSG_TOCK", + "KERI_REACTOR_CUE_TOCK", + "KERI_REACTOR_ESCROW_TOCK", + "KERI_REACTANT_MSG_TOCK", + "KERI_REACTANT_CUE_TOCK", + "KERI_REACTANT_ESCROW_TOCK", + "KERI_RESPONDANT_CUE_TOCK", + "KERI_WITNESS_RECEIPTOR_TOCK", + "KERI_WITNESS_INQUISITOR_TOCK", + "KERI_WITNESS_PUBLISHER_TOCK", + ] + + # Save and clear existing env vars + saved_env = {} + for key in env_keys: + if key in os.environ: + saved_env[key] = os.environ.pop(key) + + try: + # Reload module to pick up cleared env vars + from keri.app import tocking + importlib.reload(tocking) + + # Witness component tocks + assert tocking.WitnessMsgTock == 0.0 + assert tocking.WitnessEscrowTock == 1.0 + assert tocking.WitnessCueTock == 0.25 + + # Indirector component tocks + assert tocking.IndirectorMsgTock == 0.0 + assert tocking.IndirectorCueTock == 0.25 + assert tocking.IndirectorEscrowTock == 1.0 + + # MailboxDirector component tocks + assert tocking.MailboxPollTock == 0.5 + assert tocking.MailboxMsgTock == 0.0 + assert tocking.MailboxEscrowTock == 1.0 + + # Poller component tocks + assert tocking.PollerEventTock == 0.5 + + # ReceiptEnd component tocks + assert tocking.ReceiptInterceptTock == 0.1 + + # Reactor component tocks + assert tocking.ReactorMsgTock == 0.0 + assert tocking.ReactorCueTock == 0.25 + assert tocking.ReactorEscrowTock == 1.0 + + # Reactant component tocks + assert tocking.ReactantMsgTock == 0.0 + assert tocking.ReactantCueTock == 0.25 + assert tocking.ReactantEscrowTock == 1.0 + + # Respondant component tocks + assert tocking.RespondantCueTock == 0.25 + + # WitnessReceiptor component tocks + assert tocking.WitnessReceiptorTock == 0.0 + + # WitnessInquisitor component tocks + assert tocking.WitnessInquisitorTock == 1.0 + + # WitnessPublisher component tocks + assert tocking.WitnessPublisherTock == 0.25 + + finally: + # Restore saved env vars + for key, value in saved_env.items(): + os.environ[key] = value + # Reload to restore original state + importlib.reload(tocking) + + """Done Test""" + + +def test_tocking_env_override(): + """ + Test that environment variables properly override default tock values + """ + # Save existing env vars + env_overrides = { + "KERI_WITNESS_MSG_TOCK": "2.5", + "KERI_WITNESS_ESCROW_TOCK": "3.0", + "KERI_WITNESS_CUE_TOCK": "0.5", + "KERI_INDIRECTOR_MSG_TOCK": "1.0", + "KERI_INDIRECTOR_CUE_TOCK": "0.75", + "KERI_INDIRECTOR_ESCROW_TOCK": "2.0", + "KERI_MAILBOX_POLL_TOCK": "1.5", + "KERI_MAILBOX_MSG_TOCK": "0.1", + "KERI_MAILBOX_ESCROW_TOCK": "2.5", + "KERI_POLLER_EVENT_TOCK": "1.0", + "KERI_RECEIPT_INTERCEPT_TOCK": "0.5", + "KERI_REACTOR_MSG_TOCK": "0.5", + "KERI_REACTOR_CUE_TOCK": "0.5", + "KERI_REACTOR_ESCROW_TOCK": "2.0", + "KERI_REACTANT_MSG_TOCK": "0.5", + "KERI_REACTANT_CUE_TOCK": "0.5", + "KERI_REACTANT_ESCROW_TOCK": "2.0", + "KERI_RESPONDANT_CUE_TOCK": "0.5", + "KERI_WITNESS_RECEIPTOR_TOCK": "0.5", + "KERI_WITNESS_INQUISITOR_TOCK": "2.0", + "KERI_WITNESS_PUBLISHER_TOCK": "0.5", + } + + # Save and set env vars + saved_env = {} + for key, value in env_overrides.items(): + if key in os.environ: + saved_env[key] = os.environ[key] + os.environ[key] = value + + try: + # Reload module to pick up new env vars + from keri.app import tocking + importlib.reload(tocking) + + # Witness component tocks + assert tocking.WitnessMsgTock == 2.5 + assert tocking.WitnessEscrowTock == 3.0 + assert tocking.WitnessCueTock == 0.5 + + # Indirector component tocks + assert tocking.IndirectorMsgTock == 1.0 + assert tocking.IndirectorCueTock == 0.75 + assert tocking.IndirectorEscrowTock == 2.0 + + # MailboxDirector component tocks + assert tocking.MailboxPollTock == 1.5 + assert tocking.MailboxMsgTock == 0.1 + assert tocking.MailboxEscrowTock == 2.5 + + # Poller component tocks + assert tocking.PollerEventTock == 1.0 + + # ReceiptEnd component tocks + assert tocking.ReceiptInterceptTock == 0.5 + + # Reactor component tocks + assert tocking.ReactorMsgTock == 0.5 + assert tocking.ReactorCueTock == 0.5 + assert tocking.ReactorEscrowTock == 2.0 + + # Reactant component tocks + assert tocking.ReactantMsgTock == 0.5 + assert tocking.ReactantCueTock == 0.5 + assert tocking.ReactantEscrowTock == 2.0 + + # Respondant component tocks + assert tocking.RespondantCueTock == 0.5 + + # WitnessReceiptor component tocks + assert tocking.WitnessReceiptorTock == 0.5 + + # WitnessInquisitor component tocks + assert tocking.WitnessInquisitorTock == 2.0 + + # WitnessPublisher component tocks + assert tocking.WitnessPublisherTock == 0.5 + + finally: + # Restore or remove env vars + for key in env_overrides: + if key in saved_env: + os.environ[key] = saved_env[key] + else: + os.environ.pop(key, None) + # Reload to restore original state + importlib.reload(tocking) + + """Done Test""" + + +def test_tocking_keys(): + """ + Test that environment variable keys are correctly defined + """ + from keri.app import tocking + + # Witness component keys + assert tocking.KERI_WITNESS_MSG_TOCK_KEY == "KERI_WITNESS_MSG_TOCK" + assert tocking.KERI_WITNESS_ESCROW_TOCK_KEY == "KERI_WITNESS_ESCROW_TOCK" + assert tocking.KERI_WITNESS_CUE_TOCK_KEY == "KERI_WITNESS_CUE_TOCK" + + # Indirector component keys + assert tocking.KERI_INDIRECTOR_MSG_TOCK_KEY == "KERI_INDIRECTOR_MSG_TOCK" + assert tocking.KERI_INDIRECTOR_CUE_TOCK_KEY == "KERI_INDIRECTOR_CUE_TOCK" + assert tocking.KERI_INDIRECTOR_ESCROW_TOCK_KEY == "KERI_INDIRECTOR_ESCROW_TOCK" + + # MailboxDirector component keys + assert tocking.KERI_MAILBOX_POLL_TOCK_KEY == "KERI_MAILBOX_POLL_TOCK" + assert tocking.KERI_MAILBOX_MSG_TOCK_KEY == "KERI_MAILBOX_MSG_TOCK" + assert tocking.KERI_MAILBOX_ESCROW_TOCK_KEY == "KERI_MAILBOX_ESCROW_TOCK" + + # Poller component keys + assert tocking.KERI_POLLER_EVENT_TOCK_KEY == "KERI_POLLER_EVENT_TOCK" + + # ReceiptEnd component keys + assert tocking.KERI_RECEIPT_INTERCEPT_TOCK_KEY == "KERI_RECEIPT_INTERCEPT_TOCK" + + # Reactor component keys + assert tocking.KERI_REACTOR_MSG_TOCK_KEY == "KERI_REACTOR_MSG_TOCK" + assert tocking.KERI_REACTOR_CUE_TOCK_KEY == "KERI_REACTOR_CUE_TOCK" + assert tocking.KERI_REACTOR_ESCROW_TOCK_KEY == "KERI_REACTOR_ESCROW_TOCK" + + # Reactant component keys + assert tocking.KERI_REACTANT_MSG_TOCK_KEY == "KERI_REACTANT_MSG_TOCK" + assert tocking.KERI_REACTANT_CUE_TOCK_KEY == "KERI_REACTANT_CUE_TOCK" + assert tocking.KERI_REACTANT_ESCROW_TOCK_KEY == "KERI_REACTANT_ESCROW_TOCK" + + # Respondant component keys + assert tocking.KERI_RESPONDANT_CUE_TOCK_KEY == "KERI_RESPONDANT_CUE_TOCK" + + # WitnessReceiptor component keys + assert tocking.KERI_WITNESS_RECEIPTOR_TOCK_KEY == "KERI_WITNESS_RECEIPTOR_TOCK" + + # WitnessInquisitor component keys + assert tocking.KERI_WITNESS_INQUISITOR_TOCK_KEY == "KERI_WITNESS_INQUISITOR_TOCK" + + # WitnessPublisher component keys + assert tocking.KERI_WITNESS_PUBLISHER_TOCK_KEY == "KERI_WITNESS_PUBLISHER_TOCK" + + """Done Test""" + + +if __name__ == "__main__": + test_tocking_defaults() + test_tocking_env_override() + test_tocking_keys()