@@ -80,6 +80,25 @@ class _CompTaskChangeParams:
8080 expected_calls : list [str ]
8181
8282
83+ async def _assert_listener_triggers (
84+ mock_project_subsystem : dict [str , mock .Mock ], expected_calls : list [str ]
85+ ) -> None :
86+ for call_name , mocked_call in mock_project_subsystem .items ():
87+ if call_name in expected_calls :
88+ async for attempt in AsyncRetrying (
89+ wait = wait_fixed (1 ),
90+ stop = stop_after_delay (10 ),
91+ retry = retry_if_exception_type (AssertionError ),
92+ before_sleep = before_sleep_log (logger , logging .INFO ),
93+ reraise = True ,
94+ ):
95+ with attempt :
96+ mocked_call .assert_called_once ()
97+
98+ else :
99+ mocked_call .assert_not_called ()
100+
101+
83102@pytest .mark .parametrize (
84103 "task_class" , [NodeClass .COMPUTATIONAL , NodeClass .INTERACTIVE , NodeClass .FRONTEND ]
85104)
@@ -128,7 +147,7 @@ class _CompTaskChangeParams:
128147 ],
129148)
130149@pytest .mark .parametrize ("user_role" , [UserRole .USER ])
131- async def test_listen_comp_tasks_task (
150+ async def test_db_listener_triggers_on_event (
132151 sqlalchemy_async_engine : AsyncEngine ,
133152 mock_project_subsystem : dict [str , mock .Mock ],
134153 logged_user : UserInfoDict ,
@@ -148,27 +167,12 @@ async def test_listen_comp_tasks_task(
148167 outputs = json .dumps ({}),
149168 node_class = task_class ,
150169 )
151- async with sqlalchemy_async_engine .connect () as conn :
170+ async with sqlalchemy_async_engine .begin () as conn :
152171 # let's update some values
153172 await conn .execute (
154173 comp_tasks .update ()
155174 .values (** params .update_values )
156175 .where (comp_tasks .c .task_id == task ["task_id" ])
157176 )
158- await conn .commit ()
159-
160- # tests whether listener gets executed
161- for call_name , mocked_call in mock_project_subsystem .items ():
162- if call_name in params .expected_calls :
163- async for attempt in AsyncRetrying (
164- wait = wait_fixed (1 ),
165- stop = stop_after_delay (10 ),
166- retry = retry_if_exception_type (AssertionError ),
167- before_sleep = before_sleep_log (logger , logging .INFO ),
168- reraise = True ,
169- ):
170- with attempt :
171- mocked_call .assert_called_once ()
172-
173- else :
174- mocked_call .assert_not_called ()
177+
178+ await _assert_listener_triggers (mock_project_subsystem , params .expected_calls )
0 commit comments