2020import pytest
2121import unittest
2222import asyncio
23+ from typing import Optional
2324from chaski .utils .auto import create_nodes
24- from . test_base import TestBase
25+ from chaski . node import ChaskiNode
2526
2627
27- class TestSubscriptions (unittest .IsolatedAsyncioTestCase , TestBase ):
28+ class TestSubscriptions (unittest .IsolatedAsyncioTestCase ):
2829 """
2930 Test case for testing a single subscription scenario in ChaskiNodes.
3031
@@ -35,6 +36,67 @@ class TestSubscriptions(unittest.IsolatedAsyncioTestCase, TestBase):
3536 nodes = []
3637 host = "127.0.0.1"
3738
39+ async def asyncTearDown (self ):
40+ for node in self .nodes :
41+ print (f"Closing node { node .port } " )
42+ await node .stop ()
43+
44+ def assertConnection (
45+ self , node1 : ChaskiNode , node2 : ChaskiNode , msg : Optional [str ] = None
46+ ):
47+ """
48+ Assert that two ChaskiNodes are connected to each other.
49+
50+ This method checks if `node1` is connected to `node2` and vice versa.
51+ It raises an assertion error if the connection is not established in
52+ both directions.
53+
54+ Parameters
55+ ----------
56+ node1 : ChaskiNode
57+ The first ChaskiNode to check connection from.
58+ node2 : ChaskiNode
59+ The second ChaskiNode to check connection to.
60+ msg : str, optional
61+ An optional message to include in the assertion error if the
62+ nodes are not connected.
63+
64+ Raises
65+ ------
66+ AssertionError
67+ If `node1` is not connected to `node2` or `node2` is not connected to `node1`.
68+ """
69+ conn = node1 .is_connected_to (node2 ) and node2 .is_connected_to (node1 )
70+ return self .assertTrue (conn , msg )
71+
72+ def assertNoConnection (
73+ self , node1 : ChaskiNode , node2 : ChaskiNode , msg : Optional [str ] = None
74+ ):
75+ """
76+ Assert that two ChaskiNodes are not connected to each other.
77+
78+ This method checks if `node1` is connected to `node2` and vice versa.
79+ It raises an assertion error if the connection is established in
80+ either direction.
81+
82+ Parameters
83+ ----------
84+ node1 : ChaskiNode
85+ The first ChaskiNode to check connection from.
86+ node2 : ChaskiNode
87+ The second ChaskiNode to check connection to.
88+ msg : str, optional
89+ An optional message to include in the assertion error if the
90+ nodes are connected.
91+
92+ Raises
93+ ------
94+ AssertionError
95+ If `node1` is connected to `node2` or `node2` is connected to `node1`.
96+ """
97+ conn = node1 .is_connected_to (node2 ) and node2 .is_connected_to (node1 )
98+ return self .assertFalse (conn , msg )
99+
38100 @pytest .mark .asyncio
39101 async def test_single_subscription_no_disconnect (self ):
40102 """
0 commit comments