Skip to content

Commit

Permalink
[FIX] - test timing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ceppelli committed Jun 24, 2020
1 parent 7640e73 commit 4d3b42a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import traceback
import threading


from time import sleep
from magic_foundation import Container, Service, ServiceStatus, ServiceContext

Expand Down Expand Up @@ -50,7 +51,7 @@ def __init__(self, name:str):

async def initialize(self, ctx:ServiceContext):
log.info(f"[{self.name}] initialize")
await asyncio.sleep(0.5)
await asyncio.sleep(0)

async def run(self, ctx:ServiceContext):
log.info(f"[{self.name}] run")
Expand All @@ -75,12 +76,13 @@ def __init__(self, name:str, num_messages=0):
self.num_messages = num_messages

async def initialize(self, ctx:ServiceContext):
log.info(f"[{self.name}] initialize")
await asyncio.sleep(0.5)
log.info(f"[{self.name}] initialize")

async def run(self, ctx:ServiceContext):
log.info(f"[{self.name}] run")

await asyncio.sleep(0.5)

for i in range(self.num_messages):
await ctx.publish(queue_name="q://test", data={"index": i})
await asyncio.sleep(0)
Expand All @@ -92,8 +94,10 @@ async def terminate(self, ctx:ServiceContext):
class TestBase(TestCase):

def test_service_lifecycle_single_runloop(self):
log.info("\n")

main = Main()

service_1 = TestService(name="Service_1")
service_2 = TestService(name="Service_2")

Expand All @@ -118,6 +122,8 @@ def test_service_lifecycle_single_runloop(self):
self.assertEqual(service_2.status, ServiceStatus.terminated)

def test_service_lifecycle_multi_runloop(self):
log.info("\n")

main = Main()

service_1 = TestService(name="Service_1")
Expand Down Expand Up @@ -146,6 +152,8 @@ def test_service_lifecycle_multi_runloop(self):
self.assertEqual(service_2.status, ServiceStatus.terminated)

def test_message_single_runloop(self):
log.info("\n")

main = Main()

consumer = TestService(name="Consumer")
Expand All @@ -162,11 +170,15 @@ def test_message_single_runloop(self):

main.start()

sleep(1.0)

self.assertEqual(consumer.q_inbound.qsize(), 3)

main.stop()

def test_message_multi_runloop(self):
log.info("\n")

main = Main()

consumer = TestService(name="Consumer")
Expand All @@ -185,12 +197,8 @@ def test_message_multi_runloop(self):

main.start()

sleep(1.0)

self.assertEqual(consumer.q_inbound.qsize(), 3)

main.stop()






0 comments on commit 4d3b42a

Please sign in to comment.