11import asyncio
2- import time
32import uuid
43from collections import OrderedDict
54from datetime import datetime , timedelta , timezone
@@ -2350,7 +2349,7 @@ def test__create_writer_with_buffer_size__sends_when_buffer_full(self):
23502349 writer .write (path , tbase .DataType .INT32 , value1 , timestamp = timestamp )
23512350 writer .write (path , tbase .DataType .INT32 , value2 , timestamp = timestamp )
23522351
2353- utctime = datetime .utcfromtimestamp (timestamp .timestamp ()).isoformat () + "Z"
2352+ utctime = datetime .fromtimestamp (timestamp .timestamp (), timezone . utc ).isoformat (). replace ( "+00:00" , "Z" )
23542353 self ._client .all_requests .assert_called_once_with (
23552354 "POST" ,
23562355 "/nitag/v2/update-current-values" ,
@@ -2383,12 +2382,9 @@ def test__create_writer_with_buffer_time__sends_when_timer_elapsed(self):
23832382
23842383 writer .write (path , tbase .DataType .INT32 , value , timestamp = timestamp )
23852384 self ._client .all_requests .assert_not_called ()
2386- for i in range (100 ):
2387- if self ._client .all_requests .call_count > 0 :
2388- break
2389- time .sleep (0.01 )
2390-
2391- utctime = datetime .utcfromtimestamp (timestamp .timestamp ()).isoformat () + "Z"
2385+ # Deterministic flush instead of waiting for timer.
2386+ writer .send_buffered_writes ()
2387+ utctime = datetime .fromtimestamp (timestamp .timestamp (), timezone .utc ).isoformat ().replace ("+00:00" , "Z" )
23922388 self ._client .all_requests .assert_called_once_with (
23932389 "POST" ,
23942390 "/nitag/v2/update-current-values" ,
@@ -2424,8 +2420,7 @@ def test__create_writer_with_buffer_size_and_timer__obeys_both_settings(self):
24242420
24252421 writer1 .write (path , tbase .DataType .INT32 , value1 , timestamp = timestamp )
24262422 writer1 .write (path , tbase .DataType .INT32 , value2 , timestamp = timestamp )
2427-
2428- utctime = datetime .utcfromtimestamp (timestamp .timestamp ()).isoformat () + "Z"
2423+ utctime = datetime .fromtimestamp (timestamp .timestamp (), timezone .utc ).isoformat ().replace ("+00:00" , "Z" )
24292424 self ._client .all_requests .assert_called_once_with (
24302425 "POST" ,
24312426 "/nitag/v2/update-current-values" ,
@@ -2449,10 +2444,8 @@ def test__create_writer_with_buffer_size_and_timer__obeys_both_settings(self):
24492444
24502445 writer2 .write (path , tbase .DataType .INT32 , value3 , timestamp = timestamp )
24512446 assert 1 == self ._client .all_requests .call_count # same as before
2452- for i in range (100 ):
2453- if self ._client .all_requests .call_count > 1 :
2454- break
2455- time .sleep (0.01 )
2447+ # Deterministic flush instead of waiting for timer.
2448+ writer2 .send_buffered_writes ()
24562449
24572450 assert 2 == self ._client .all_requests .call_count
24582451 assert self ._client .all_requests .call_args_list [1 ] == mock .call (
@@ -2486,7 +2479,7 @@ def test__read_with_timestamp_and_aggregates__retrieves_all_data_from_server(sel
24862479 path = "test"
24872480 value = "success"
24882481 now = datetime .now (timezone .utc )
2489- utctime = datetime . utcfromtimestamp ( now .timestamp ()). isoformat () + "Z"
2482+ utctime = now .isoformat (). replace ( "+00:00" , "Z" )
24902483 self ._client .all_requests .configure_mock (
24912484 side_effect = self ._get_mock_request (
24922485 [
@@ -2554,7 +2547,7 @@ def test__read_with_timestamp__does_not_query_aggregates(self):
25542547 path = "test"
25552548 value = "success"
25562549 now = datetime .now (timezone .utc )
2557- utctime = datetime . utcfromtimestamp ( now .timestamp ()). isoformat () + "Z"
2550+ utctime = now .isoformat (). replace ( "+00:00" , "Z" )
25582551 self ._client .all_requests .configure_mock (
25592552 side_effect = self ._get_mock_request (
25602553 [
@@ -2669,7 +2662,7 @@ async def test__read_async_with_timestamp_and_aggregates__retrieves_all_data_fro
26692662 path = "test"
26702663 value = "success"
26712664 now = datetime .now (timezone .utc )
2672- utctime = datetime . utcfromtimestamp ( now .timestamp ()). isoformat () + "Z"
2665+ utctime = now .isoformat (). replace ( "+00:00" , "Z" )
26732666 self ._client .all_requests .configure_mock (
26742667 side_effect = self ._get_mock_request (
26752668 [
@@ -2743,7 +2736,7 @@ async def test__read_async_with_timestamp__does_not_query_aggregates(self):
27432736 path = "test"
27442737 value = "success"
27452738 now = datetime .now (timezone .utc )
2746- utctime = datetime . utcfromtimestamp ( now .timestamp ()). isoformat () + "Z"
2739+ utctime = now .isoformat (). replace ( "+00:00" , "Z" )
27472740 self ._client .all_requests .configure_mock (
27482741 side_effect = self ._get_mock_request (
27492742 [
0 commit comments