From 177ebba9bb1019a87823cb82dd424134d980c513 Mon Sep 17 00:00:00 2001 From: Marek Miller Date: Sat, 19 Nov 2022 00:01:46 +0100 Subject: [PATCH 1/3] Add test --- tests/osc/test_osc_OscMessage.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/osc/test_osc_OscMessage.py b/tests/osc/test_osc_OscMessage.py index 6ccf1b036..07455c2eb 100644 --- a/tests/osc/test_osc_OscMessage.py +++ b/tests/osc/test_osc_OscMessage.py @@ -51,3 +51,8 @@ def test(): ), ['a', 'b', ['c', 'd']]) """ ) + + +def test_new_ntp_era(): + datagram = supriya.osc.OscBundle._encode_date(seconds=2085978496) + assert datagram.hex() == "0000000000000000" From c04905d18b08d179ebbe30952484e7a306ba9073 Mon Sep 17 00:00:00 2001 From: Marek Miller Date: Fri, 18 Nov 2022 22:16:48 +0100 Subject: [PATCH 2/3] Watch for NTP timestamp overflow --- supriya/osc/messages.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/supriya/osc/messages.py b/supriya/osc/messages.py index 46efb48da..a56039679 100644 --- a/supriya/osc/messages.py +++ b/supriya/osc/messages.py @@ -362,7 +362,8 @@ def _encode_date(seconds, realtime=True): return IMMEDIATELY if realtime: seconds = seconds + NTP_DELTA - return struct.pack(">Q", int(seconds * SECONDS_TO_NTP_TIMESTAMP)) + if seconds >= 4294967296: # 2**32 + seconds = seconds % 4294967296 return struct.pack(">Q", int(seconds * SECONDS_TO_NTP_TIMESTAMP)) ### PUBLIC METHODS ### From 8058451b5aa5d11095e66a56c507394c52d6b364 Mon Sep 17 00:00:00 2001 From: Marek Miller Date: Sat, 19 Nov 2022 00:29:59 +0100 Subject: [PATCH 3/3] Document the test --- tests/osc/test_osc_OscMessage.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/osc/test_osc_OscMessage.py b/tests/osc/test_osc_OscMessage.py index 07455c2eb..71d759849 100644 --- a/tests/osc/test_osc_OscMessage.py +++ b/tests/osc/test_osc_OscMessage.py @@ -54,5 +54,9 @@ def test(): def test_new_ntp_era(): - datagram = supriya.osc.OscBundle._encode_date(seconds=2085978496) - assert datagram.hex() == "0000000000000000" + """ + Check for NTP timestamp overflow. + """ + seconds = 2**32 - supriya.osc.messages.NTP_DELTA + 1 + datagram = supriya.osc.OscBundle._encode_date(seconds=seconds) + assert datagram.hex() == "0000000100000000"