Skip to content

Commit

Permalink
set asyncio_default_fixture_loop_scope=function for test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
SamDanielThangarajan committed Oct 5, 2024
1 parent 5e050c9 commit 96e9fe6
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 67 deletions.
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[pytest]
pythonpath = src
asyncio_mode=auto
asyncio_default_fixture_loop_scope=function
log_cli=true
log_level=INFO
log_level=DEBUG
log_format = %(name)-20s: %(message)s
log_date_format = %I:%M:%S
addopts = --cov=src --cov-fail-under=97
4 changes: 2 additions & 2 deletions src/nasdaq_protocols/soup/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ async def on_unsequenced(self, msg: UnSequencedData) -> None:
:param msg: UnSequencedData message.
"""

def send_seq_msg(self, data: bytes) -> None:
def send_seq_msg(self, data: bytes | SequencedData) -> None:
"""
Send sequenced data to the client.
Expand All @@ -251,7 +251,7 @@ def end_session(self):
self.initiate_close()

async def on_debug(self, msg: Debug) -> None:
self.log.info('%s> ++ client debug : %s', msg)
self.log.info('%s> ++ client debug : %s', self.session_id, msg)

async def send_heartbeat(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_common_asyncsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def client_session(mock_server_session) -> SampleTestClientSession:
event_loop = asyncio.get_running_loop()
port, server_session = mock_server_session
session_ = SampleTestClientSession(session_id=common.SessionId())
await event_loop.create_connection(lambda: session_, '', port)
_, session_ = await event_loop.create_connection(lambda: session_, '127.0.0.1', port=port)

# test server-client communication works
server_session.when(lambda x: x == b'echo').do(lambda session, _: session.send('echoed'))
Expand Down
12 changes: 6 additions & 6 deletions tests/test_fix_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def test__fix_session__login_successful(mock_server_session, session_facto
)

fix_session = await fix.connect_async(
('', port), ENTER_LOGIN_MSG, session_factory
('127.0.0.1', port), ENTER_LOGIN_MSG, session_factory
)

await fix_session.close()
Expand All @@ -71,7 +71,7 @@ async def test__fix_session__login_failed(mock_server_session, session_factory):

with pytest.raises(ConnectionRefusedError):
await fix.connect_async(
('', port), ENTER_LOGIN_MSG, session_factory
('127.0.0.1', port), ENTER_LOGIN_MSG, session_factory
)


Expand All @@ -87,7 +87,7 @@ async def test__fix_session__login_failed__server_closes_connection(mock_server_

with pytest.raises(ConnectionRefusedError):
await fix.connect_async(
('', port), ENTER_LOGIN_MSG, session_factory
('127.0.0.1', port), ENTER_LOGIN_MSG, session_factory
)


Expand All @@ -103,7 +103,7 @@ async def test__fix_session__no_server_heartbeats__session_closed(mock_server_se
)

session = await fix.connect_async(
('', port), ENTER_LOGIN_MSG,
('127.0.0.1', port), ENTER_LOGIN_MSG,
lambda : session_factory(
client_heartbeat_interval=100,
server_heartbeat_interval=server_heartbeat_interval
Expand All @@ -129,7 +129,7 @@ async def test__fix_session__client_heartbeats__session_is_active(mock_server_se
)

session = await fix.connect_async(
('', port), ENTER_LOGIN_MSG,
('127.0.0.1', port), ENTER_LOGIN_MSG,
lambda : session_factory(
client_heartbeat_interval=heart_beat_interval,
server_heartbeat_interval=100
Expand Down Expand Up @@ -170,7 +170,7 @@ async def test__fix_session__active_message_flow__no_heartbeats_sent(mock_server
)

session = await fix.connect_async(
('', port), ENTER_LOGIN_MSG,
('127.0.0.1', port), ENTER_LOGIN_MSG,
lambda : session_factory(
client_heartbeat_interval=heart_beat_interval,
server_heartbeat_interval=100
Expand Down
6 changes: 3 additions & 3 deletions tests/test_itch_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def test__itch_tools__tail_itch(mock_server_session, load_itch_tools):

# start tailing
tailer = asyncio.create_task(tail_itch(
('', port), 'test-u', 'test-p', '', 1,
('127.0.0.1', port), 'test-u', 'test-p', '', 1,
definitions.connect_async, 10, 10
))
assert not tailer.done()
Expand Down Expand Up @@ -114,7 +114,7 @@ async def test__itch_tools__tail_itch__login_failed(mock_server_session, load_it

# start tailing
tailer = asyncio.create_task(tail_itch(
('', port), 'test-u', 'test-p', '', 1,
('127.0.0.1', port), 'test-u', 'test-p', '', 1,
definitions.connect_async, 10, 10
))
# give some time for tail
Expand Down Expand Up @@ -149,7 +149,7 @@ async def test__itch_tools__tail_itch__ctrl_c(mock_server_session, load_itch_too

# start tailing
tailer = asyncio.create_task(tail_itch(
('', port), 'test-u', 'test-p', '', 1,
('127.0.0.1', port), 'test-u', 'test-p', '', 1,
definitions.connect_async, 10, 10
))
# give some time for tail
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ouch_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def connect_to_mock_ouch_server(mock_server_session, session_factory=None)

LOG.debug('connecting to server...')
client_session = await ouch.connect_async(
('', port), 'test-u', 'test-p', '',
('127.0.0.1', port), 'test-u', 'test-p', '',
session_factory=session_factory
)
assert client_session is not None
Expand Down
Loading

0 comments on commit 96e9fe6

Please sign in to comment.