X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=tests%2Ftest_xapps.py;h=cd806ac1a651a9ce26fa3d5e1be544e667a61e4d;hb=db26ba217530985dbdcf739640c16c6cecd54a1d;hp=f80d3754cb8407e0ad18c2749a96afc1a57b7a9a;hpb=f9cd5cc676355485c2d9c8bc2be22ddad4874382;p=ric-plt%2Fxapp-frame-py.git diff --git a/tests/test_xapps.py b/tests/test_xapps.py index f80d375..cd806ac 100644 --- a/tests/test_xapps.py +++ b/tests/test_xapps.py @@ -17,45 +17,44 @@ import json import time from contextlib import suppress -from ricxappframe.xapp_frame import Xapp, RMRXapp +from ricxappframe.xapp_frame import Xapp, RMRXapp, RIC_HEALTH_CHECK_REQ, RIC_HEALTH_CHECK_RESP rmr_xapp = None +rmr_xapp_health = None gen_xapp = None -def test_flow(): +def test_rmr_init(): # test variables - def_called = 0 - sixty_called = 0 + def_pay = None + sixty_pay = None # create rmr app - global rmr_xapp - - def post_init(self): - print("hey") def default_handler(self, summary, sbuf): - nonlocal def_called - def_called += 1 - assert json.loads(summary["payload"]) == {"test send 60001": 1} + nonlocal def_pay + def_pay = json.loads(summary["payload"]) self.rmr_free(sbuf) - rmr_xapp = RMRXapp(default_handler, post_init=post_init, rmr_port=4564, rmr_wait_for_ready=False, use_fake_sdl=True) - def sixtythou_handler(self, summary, sbuf): - nonlocal sixty_called - sixty_called += 1 - assert json.loads(summary["payload"]) == {"test send 60000": 1} + nonlocal sixty_pay + sixty_pay = json.loads(summary["payload"]) self.rmr_free(sbuf) + global rmr_xapp + rmr_xapp = RMRXapp(default_handler, rmr_port=4564, use_fake_sdl=True) rmr_xapp.register_callback(sixtythou_handler, 60000) - rmr_xapp.run() + rmr_xapp.run(thread=True) # in unit tests we need to thread here or else execution is not returned! time.sleep(1) + # create a general xapp that will demonstrate some SDL functionality and launch some requests against the rmr xapp + def entry(self): + time.sleep(1) + self.sdl_set("testns", "mykey", 6) assert self.sdl_get("testns", "mykey") == 6 assert self.sdl_find_and_get("testns", "myk") == {"mykey": 6} @@ -68,13 +67,41 @@ def test_flow(): self.rmr_send(val, 60001) global gen_xapp - gen_xapp = Xapp(entrypoint=entry, rmr_wait_for_ready=False, use_fake_sdl=True) + gen_xapp = Xapp(entrypoint=entry, use_fake_sdl=True) gen_xapp.run() time.sleep(1) - assert def_called == 1 - assert sixty_called == 1 + assert def_pay == {"test send 60001": 2} + assert sixty_pay == {"test send 60000": 1} + + +def test_rmr_healthcheck(): + # thanos uses the rmr xapp to healthcheck the rmr xapp + + # test variables + health_pay = None + + def post_init(self): + self.rmr_send(b"", RIC_HEALTH_CHECK_REQ) + + def default_handler(self, summary, sbuf): + pass + + global rmr_xapp_health + rmr_xapp_health = RMRXapp(default_handler, post_init=post_init, rmr_port=4666, use_fake_sdl=True) + + def health_handler(self, summary, sbuf): + nonlocal health_pay + health_pay = summary["payload"] + self.rmr_free(sbuf) + + rmr_xapp_health.register_callback(health_handler, RIC_HEALTH_CHECK_RESP) + rmr_xapp_health.run(thread=True) # in unit tests we need to thread here or else execution is not returned! + + time.sleep(1) + + assert health_pay == b"OK\n" def teardown_module(): @@ -87,3 +114,5 @@ def teardown_module(): gen_xapp.stop() with suppress(Exception): rmr_xapp.stop() + with suppress(Exception): + rmr_xapp_health.stop()