From 6e1166c2c7d80dd738a763aaa046c44cf0a558ed Mon Sep 17 00:00:00 2001
From: Tobias Winchen <tobias.winchen@rwth-aachen.de>
Date: Wed, 3 May 2023 10:13:59 +0000
Subject: [PATCH] Sync time of packetizer noise diode always starts on full
 seconds (except specified to fraction via noise diode window

---
 mpikat/pipelines/digpack_controller.py | 2 +-
 tests/test_digpack_client.py           | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/mpikat/pipelines/digpack_controller.py b/mpikat/pipelines/digpack_controller.py
index 05f13f12..d2250e9a 100644
--- a/mpikat/pipelines/digpack_controller.py
+++ b/mpikat/pipelines/digpack_controller.py
@@ -141,7 +141,7 @@ def get_shared_sync_time(redis_db, key, delay):
     pipeline = redis_db.pipeline()
     # Create a new key only when not existing. Set a expiry of the key with the
     # delay time
-    pipeline.set(key, time.time() + delay, nx=True, ex=delay)
+    pipeline.set(key, int(time.time()) + delay, nx=True, ex=delay)
     pipeline.get(key)
     r, v = pipeline.execute()
     # return the key
diff --git a/tests/test_digpack_client.py b/tests/test_digpack_client.py
index bf6e08c2..7ac5e134 100644
--- a/tests/test_digpack_client.py
+++ b/tests/test_digpack_client.py
@@ -66,6 +66,11 @@ class TestSharedSyncTime(unittest.TestCase):
         self.assertNotEqual(a, get_shared_sync_time(self.client, 'foo', 1))
 
 
+    def test_sync_time_starts_on_full_Second(self):
+        a = get_shared_sync_time(self.client, 'foo', 1)
+        self.assertLessEqual(abs(a - int(a)), 1E-9)
+
+
 
 
 if __name__ == '__main__':
-- 
GitLab