diff --git a/src/hio/base/tyming.py b/src/hio/base/tyming.py index 01b35e71..051bcabd 100644 --- a/src/hio/base/tyming.py +++ b/src/hio/base/tyming.py @@ -45,7 +45,8 @@ def __init__(self, tyme=0.0, tock=None, **kwa): """ super(Tymist,self).__init__(**kwa) # Mixin for Mult-inheritance MRO self.tyme = float(tyme) - self.tock = float(tock) if tock is not None else self.Tock + # Use setter which applies abs() for consistency with Doer.tock + self.tock = tock if tock is not None else self.Tock @property def tyme(self): @@ -74,8 +75,9 @@ def tock(self): def tock(self, tock): """ cycle time increment property setter, set ._tock to tock + Uses abs() for consistency with Doer.tock setter (doing.py). """ - self._tock= float(tock) + self._tock = abs(float(tock)) def tick(self, tock=None): """ diff --git a/tests/base/test_tyming.py b/tests/base/test_tyming.py index 204afc8c..eebcd76d 100644 --- a/tests/base/test_tyming.py +++ b/tests/base/test_tyming.py @@ -53,6 +53,40 @@ def test_tymist(): """End Test """ +def test_tymist_tock_abs_guard(): + """ + Test Tymist.tock setter applies abs() for consistency with Doer.tock. + + This guards against negative tock values which would cause tyme to + decrement on tick(), breaking all scheduling invariants: + - Tyme monotonicity violated + - Tymers never expire + - Periodic Doers' retymes never reached + """ + tymist = tyming.Tymist() + + # Negative tock should be converted to positive + tymist.tock = -1.0 + assert tymist.tock == 1.0, "Tymist.tock setter should apply abs()" + + # Verify tyme always increases after tick + tymist.tyme = 0.0 + tymist.tick() + assert tymist.tyme == 1.0, "tick() should increase tyme" + + # Even with negative input, tyme should still increase + tymist.tock = -0.5 + assert tymist.tock == 0.5 + tymist.tick() + assert tymist.tyme == 1.5, "tick() should continue to increase tyme" + + # Test negative tock in constructor + tymist2 = tyming.Tymist(tock=-0.25) + assert tymist2.tock == 0.25, "Constructor should also apply abs()" + + """End Test """ + + def test_tymee(): """ Test Tymee class