Преглед изворни кода

Remove unused sleep calls from test suite to run faster

Signed-off-by: Stan Janssen <stan.janssen@elaad.nl>
Stan Janssen пре 4 година
родитељ
комит
66c6bf3692

+ 6 - 6
test/integration_tests/test_event_warnings_errors.py

@@ -34,7 +34,7 @@ async def test_client_no_event_handler(caplog):
     server.add_handler('on_create_party_registration', on_create_party_registration)
     print("Running server")
     await server.run_async()
-    await asyncio.sleep(0.1)
+    # await asyncio.sleep(0.1)
     print("Running client")
     await client.run()
 
@@ -72,7 +72,7 @@ async def test_client_faulty_event_handler(caplog):
     server.add_handler('on_create_party_registration', on_create_party_registration)
     print("Running server")
     await server.run_async()
-    await asyncio.sleep(0.1)
+    # await asyncio.sleep(0.1)
     print("Running client")
     await client.run()
 
@@ -109,7 +109,7 @@ async def test_client_exception_event_handler(caplog):
     server.add_handler('on_create_party_registration', on_create_party_registration)
     print("Running server")
     await server.run_async()
-    await asyncio.sleep(0.1)
+    # await asyncio.sleep(0.1)
     print("Running client")
     await client.run()
 
@@ -148,7 +148,7 @@ async def test_client_good_event_handler(caplog):
     server.add_handler('on_create_party_registration', on_create_party_registration)
     print("Running server")
     await server.run_async()
-    await asyncio.sleep(0.1)
+    # await asyncio.sleep(0.1)
     print("Running client")
     await client.run()
 
@@ -170,7 +170,7 @@ async def test_client_good_event_handler(caplog):
     assert len(caplog.records) == 0
     await client.stop()
     await server.stop()
-    await asyncio.sleep(1)
+    # await asyncio.sleep(1)
 
 @pytest.mark.asyncio
 async def test_server_warning_conflicting_poll_methods(caplog):
@@ -321,7 +321,7 @@ async def test_client_warning_no_update_event_handler(caplog):
                            vtn_url='http://localhost:8080/OpenADR2/Simple/2.0b')
     client.add_handler('on_event', good_on_event)
     await server.run_async()
-    await asyncio.sleep(0.5)
+    # await asyncio.sleep(0.5)
     await client.run()
     await asyncio.sleep(2)
     assert ("You should implement your own on_update_event handler. This handler receives "

+ 3 - 3
test/test_certificates.py

@@ -46,7 +46,7 @@ async def test_ssl_certificates():
     server.add_handler('on_create_party_registration', partial(on_create_party_registration,
                                                                future=registration_future))
     await server.run_async()
-    await asyncio.sleep(1)
+    #await asyncio.sleep(1)
     # Run the client
     client = OpenADRClient(ven_name='myven',
                            vtn_url='https://localhost:8080/OpenADR2/Simple/2.0b',
@@ -62,7 +62,7 @@ async def test_ssl_certificates():
 
     await client.stop()
     await server.stop()
-    await asyncio.sleep(0)
+    #await asyncio.sleep(0)
 
 @pytest.mark.asyncio
 async def test_ssl_certificates_wrong_cert():
@@ -78,7 +78,7 @@ async def test_ssl_certificates_wrong_cert():
     server.add_handler('on_create_party_registration', partial(on_create_party_registration,
                                                                future=registration_future))
     await server.run_async()
-    await asyncio.sleep(1)
+    #await asyncio.sleep(1)
 
     # Run the client
     client = OpenADRClient(ven_name='myven',

+ 4 - 4
test/test_failures.py

@@ -50,10 +50,10 @@ async def test_vtn_no_create_party_registration_handler(caplog):
     client = OpenADRClient(ven_name='myven', vtn_url='http://localhost:8080/OpenADR2/Simple/2.0b')
     await server.run_async()
     await client.run()
-    await asyncio.sleep(0.5)
+    #await asyncio.sleep(0.5)
     await server.stop()
     await client.stop()
-    await asyncio.sleep(0)
+    #await asyncio.sleep(0)
     assert 'No VEN ID received from the VTN, aborting.' in caplog.messages
     assert ("You should implement and register your own on_create_party_registration "
             "handler if you want VENs to be able to connect to you. This handler will "
@@ -94,7 +94,7 @@ async def test_server_handler_exception(caplog):
     client = OpenADRClient(ven_name='myven',
                            vtn_url=f'http://localhost:{SERVER_PORT}/OpenADR2/Simple/2.0b')
     await client.run()
-    await asyncio.sleep(0.5)
+    #await asyncio.sleep(0.5)
     await client.stop()
     await server.stop()
     for message in caplog.messages:
@@ -116,7 +116,7 @@ async def test_throw_protocol_error(caplog):
     client = OpenADRClient(ven_name='myven',
                            vtn_url=f'http://localhost:{SERVER_PORT}/OpenADR2/Simple/2.0b')
     await client.run()
-    await asyncio.sleep(0.5)
+    #await asyncio.sleep(0.5)
     await client.stop()
     await server.stop()
     assert 'We got a non-OK OpenADR response from the server: 450: OUT OF SEQUENCE' in caplog.messages

+ 29 - 0
test/test_message_conversion.py

@@ -21,7 +21,10 @@ from pprint import pprint
 from termcolor import colored
 from datetime import datetime, timezone, timedelta
 import pytest
+from pprint import pprint, pformat
+from lxml import etree
 from dataclasses import asdict
+import re
 
 DATE_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
 
@@ -280,8 +283,34 @@ testcases = [
 
 @pytest.mark.parametrize('message_type,data', testcases)
 def test_message(message_type, data):
+    # file = open('representations.rst', 'a')
+    # print(f".. _{message_type}:", file=file)
+    # print("", file=file)
+    # print(message_type, file=file)
+    # print("="*len(message_type), file=file)
+    # print("", file=file)
+    # print("OpenADR payload:", file=file)
+    # print("", file=file)
+    # print(".. code-block:: xml", file=file)
+    # print("    ", file=file)
     message = create_message(message_type, **data)
+    # message = re.sub(r"\s\s+","",message)
+    # message = message.replace("\n","")
+    # xml_lines = etree.tostring(etree.fromstring(message.replace('\n', '').encode('utf-8')), pretty_print=True).decode('utf-8').splitlines()
+    # for line in xml_lines:
+    #      print("    " + line, file=file)
+    # print("", file=file)
+    # print("OpenLEADR representation:", file=file)
+    # print("    ", file=file)
+    # print(".. code-block:: python3", file=file)
+    # print("    ", file=file)
+    validate_xml_schema(message)
     parsed = parse_message(message)[1]
+    # dict_lines = pformat(parsed).splitlines()
+    # for line in dict_lines:
+    #     print("    " + line, file=file)
+    # print("", file=file)
+    # print("", file=file)
     if message_type == 'oadrRegisterReport':
         for report in data['reports']:
             for rd in report['report_descriptions']:

+ 8 - 8
test/test_queues.py

@@ -54,9 +54,9 @@ async def test_internal_message_queue():
                      callback=partial(event_callback, future=event_callback_future))
 
     await server.run_async()
-    await asyncio.sleep(1)
+    #await asyncio.sleep(1)
     await client.run()
-    await asyncio.sleep(1)
+    #await asyncio.sleep(1)
     status = await event_callback_future
     assert status == 'optIn'
 
@@ -66,7 +66,7 @@ async def test_internal_message_queue():
     message_type, message_payload = await asyncio.wait_for(client.poll(), 0.5)
     assert message_type == 'oadrResponse'
 
-    await asyncio.sleep(1)  # Wait for the event to be completed
+    #await asyncio.sleep(1)  # Wait for the event to be completed
     await client.stop()
     await server.stop()
 
@@ -95,7 +95,7 @@ async def test_event_status_opt_in():
 
     assert server.services['event_service'].pending_events[event_id][0].event_descriptor.event_status == 'far'
     await server.run_async()
-    await asyncio.sleep(0.5)
+    #await asyncio.sleep(0.5)
     await client.run()
 
     await event_callback_future
@@ -117,7 +117,7 @@ async def test_event_status_opt_in():
 
     await client.stop()
     await server.stop()
-    await asyncio.sleep(0)
+    #await asyncio.sleep(0)
 
 @pytest.mark.asyncio
 async def test_event_status_opt_in_with_ramp_up():
@@ -144,7 +144,7 @@ async def test_event_status_opt_in_with_ramp_up():
 
     assert server.services['event_service'].pending_events[event_id][0].event_descriptor.event_status == 'far'
     await server.run_async()
-    await asyncio.sleep(0.5)
+    #await asyncio.sleep(0.5)
     await client.run()
 
     await event_callback_future
@@ -164,11 +164,11 @@ async def test_event_status_opt_in_with_ramp_up():
     print("Watiting for event future 4")
     result = await event_update_futures[2]
     assert result['event_descriptor']['event_status'] == 'completed'
-    await asyncio.sleep(0.5)
+    #await asyncio.sleep(0.5)
 
     await client.stop()
     await server.stop()
-    await asyncio.sleep(1)
+    #await asyncio.sleep(1)
 
 
 @pytest.mark.asyncio

+ 10 - 10
test/test_reports.py

@@ -115,7 +115,7 @@ async def test_report_registration():
                       unit='V')
 
     asyncio.create_task(server.run_async())
-    await asyncio.sleep(1)
+    #await asyncio.sleep(1)
     # Register the client
     await client.create_party_registration()
 
@@ -171,7 +171,7 @@ async def test_report_registration_with_status_report():
                       resource_id='Device001')
 
     asyncio.create_task(server.run_async())
-    await asyncio.sleep(1)
+    # await asyncio.sleep(1)
     # Register the client
     await client.create_party_registration()
 
@@ -222,7 +222,7 @@ async def test_report_registration_full():
 
 
     await server.run_async()
-    await asyncio.sleep(0.1)
+    # await asyncio.sleep(0.1)
     # Register the client
     await client.create_party_registration()
 
@@ -294,7 +294,7 @@ async def test_update_reports():
 
     assert len(client.reports) == 2
     asyncio.create_task(server.run_async())
-    await asyncio.sleep(1)
+    # await asyncio.sleep(1)
 
     # Run the client asynchronously
     print("Running the client")
@@ -364,7 +364,7 @@ async def test_incremental_reports():
                        partial(on_create_party_registration, future=party_future))
 
     loop.create_task(server.run_async())
-    await asyncio.sleep(1)
+    # await asyncio.sleep(1)
     await client.run()
     print("Awaiting party future")
     await party_future
@@ -376,7 +376,7 @@ async def test_incremental_reports():
     await collect_futures[0]
     print("check")
 
-    await asyncio.sleep(1)
+    # await asyncio.sleep(1)
     print("Checking that the report was not yet sent... ", end="")
     assert update_report_future.done() is False
     print("check")
@@ -390,7 +390,7 @@ async def test_incremental_reports():
 
     await server.stop()
     await client.stop()
-    await asyncio.sleep(0)
+    # await asyncio.sleep(0)
 
 
 
@@ -428,18 +428,18 @@ async def test_update_report_data_collection_mode_full():
                                                      receive_futures=[report_received_future]))
 
     await server.run_async()
-    await asyncio.sleep(0.1)
+    # await asyncio.sleep(0.1)
 
     print(f"The time is now {datetime.now()}")
     t = time.time()
     wait_for = int(t/2) * 2 + 2 - t
-    await asyncio.sleep(wait_for)
+    # await asyncio.sleep(wait_for)
     print(f"The time is now {datetime.now()}, running client")
     await client.run()
 
     await party_registration_future
     await report_register_future
-    await asyncio.sleep(1)
+    # await asyncio.sleep(1)
     print(f"The time is now {datetime.now()}, checking if report was triggered")
     assert data_collection_future.done() is False