Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests #315

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ax_interface/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def __init__(self, mib_cls, update_frequency, loop):
self.loop = loop

# synchronization events
self.run_enabled = asyncio.Event(loop=loop)
self.oid_updaters_enabled = asyncio.Event(loop=loop)
self.stopped = asyncio.Event(loop=loop)
self.run_enabled = asyncio.Event()
self.oid_updaters_enabled = asyncio.Event()
self.stopped = asyncio.Event()

# Initialize our MIB
self.mib_table = MIBTable(mib_cls, update_frequency)
Expand Down Expand Up @@ -46,7 +46,7 @@ async def run_in_event_loop(self):
# signal background tasks to halt
self.oid_updaters_enabled.clear()
# wait for handlers to come back
await asyncio.wait_for(background_task, BACKGROUND_WAIT_TIMEOUT, loop=self.loop)
await asyncio.wait_for(background_task, BACKGROUND_WAIT_TIMEOUT)

# signal that we're done!
self.stopped.set()
Expand Down
2 changes: 1 addition & 1 deletion src/ax_interface/mib.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def start_background_tasks(self, event):
fut = asyncio.ensure_future(updater.start())
fut.add_done_callback(MIBTable._done_background_task_callback)
tasks.append(fut)
return asyncio.gather(*tasks, loop=event._loop)
return asyncio.gather(*tasks)

def _find_parent_prefix(self, item):
oids = sorted(self.prefixes)
Expand Down
2 changes: 1 addition & 1 deletion src/ax_interface/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, mib_table, loop):
self.loop = loop
self.session_id = -1
self.mib_table = mib_table
self.closed = asyncio.Event(loop=loop)
self.closed = asyncio.Event()
self.counter = 0

def send_pdu(self, pdu):
Expand Down
27 changes: 27 additions & 0 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import asyncio
import os
import sys
import time
from unittest import TestCase

modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(modules_path, 'src'))

import ax_interface

class SonicMIB(metaclass=ax_interface.mib.MIBMeta):
"""
Test
"""

class TestAgentLoop(TestCase):

async def delayed_shutdown(self, agent):
await asyncio.sleep(5)
await agent.shutdown()

def test_agent_loop(self):
event_loop = asyncio.get_event_loop()
agent = ax_interface.Agent(SonicMIB, 5, event_loop)
event_loop.create_task(self.delayed_shutdown(agent))
event_loop.run_until_complete(agent.run_in_event_loop())
Loading