Skip to content

Commit

Permalink
Fix "socket already in use", "frozen router" bugs in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clenk committed Feb 8, 2024
1 parent e293ba0 commit 7d6a4c8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/api/packs/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, services):
self.rest_svc = services.get('rest_svc')

async def enable(self):
self.app_svc.application.router._frozen = False
self.app_svc.application.router.add_route('GET', '/advanced/sources', self._section_sources)
self.app_svc.application.router.add_route('GET', '/advanced/objectives', self._section_objectives)
self.app_svc.application.router.add_route('GET', '/advanced/planners', self._section_planners)
Expand Down
1 change: 1 addition & 0 deletions app/api/packs/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, services):
self.rest_svc = services.get('rest_svc')

async def enable(self):
self.app_svc.application.router._frozen = False
self.app_svc.application.router.add_route('GET', '/campaign/agents', self._section_agent)
self.app_svc.application.router.add_route('GET', '/campaign/abilities', self._section_abilities)
self.app_svc.application.router.add_route('GET', '/campaign/adversaries', self._section_profiles)
Expand Down
7 changes: 6 additions & 1 deletion app/contacts/contact_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ def __init__(self, services):
self.contact_svc = services.get('contact_svc')
self.domain = self.get_config('app.contact.dns.domain')
self.handler = Handler(self.domain, services, self.name)
self.transport = None

async def start(self):
loop = asyncio.get_event_loop()
dns = self.get_config('app.contact.dns.socket')
addr, port = dns.split(':')
await loop.create_datagram_endpoint(lambda: self.handler, local_addr=(addr, port))
self.transport, _ = await loop.create_datagram_endpoint(lambda: self.handler, local_addr=(addr, port))

async def stop(self):
if self.transport:
self.transport.close()


class DnsPacket:
Expand Down
7 changes: 6 additions & 1 deletion app/contacts/contact_udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ def __init__(self, services):
self.log = self.create_logger('contact_udp')
self.contact_svc = services.get('contact_svc')
self.handler = Handler(services)
self.transport = None

async def start(self):
loop = asyncio.get_event_loop()
udp = self.get_config('app.contact.udp')
addr, port = udp.split(':')
loop.create_task(loop.create_datagram_endpoint(lambda: self.handler, local_addr=(addr, port)))
self.transport, _ = await loop.create_task(loop.create_datagram_endpoint(lambda: self.handler, local_addr=(addr, port)))

async def stop(self):
if self.transport:
self.transport.close()


class Handler(asyncio.DatagramProtocol):
Expand Down

0 comments on commit 7d6a4c8

Please sign in to comment.