66
77import pytest
88from sqlmodel import select
9- from sqlmodel .ext .asyncio .session import AsyncSession
109
11- from lsst .cmservice .common .daemon_v2 import consider_campaigns , consider_nodes
10+ from lsst .cmservice .common .daemon_v2 import DaemonContext , consider_campaigns , consider_nodes
1211from lsst .cmservice .common .launchers import LauncherCheckResponse
1312from lsst .cmservice .models .db .campaigns import Campaign , Node , Task
1413from lsst .cmservice .models .enums import StatusEnum
1817
1918
2019async def test_daemon_campaign (
21- caplog : pytest .LogCaptureFixture , test_campaign : str , session : AsyncSession
20+ caplog : pytest .LogCaptureFixture , test_campaign : str , daemon_context : DaemonContext
2221) -> None :
2322 """Tests the handling of campaigns during daemon iteration, which is
2423 primarily done by checking side effects. This test assesses a test campaign
@@ -27,11 +26,12 @@ async def test_daemon_campaign(
2726 continue to traverse the campaign graph and visit more nodes until the
2827 END node is reached.
2928 """
29+ session = daemon_context .session
3030
3131 # At first, the test_campaign in a waiting state is not subject to daemon
3232 # consideration
3333 caplog .clear ()
34- await consider_campaigns (session )
34+ await consider_campaigns (daemon_context )
3535
3636 # extract the test campaign id from the fixture url
3737 campaign_id = urlparse (test_campaign ).path .split ("/" )[- 2 :][0 ]
@@ -47,7 +47,7 @@ async def test_daemon_campaign(
4747
4848 # now the daemon should consider the running campaign
4949 caplog .clear ()
50- await consider_campaigns (session )
50+ await consider_campaigns (daemon_context )
5151 found_log_messages = 0
5252 for r in caplog .records :
5353 if any (["considering campaign" in r .message , "considering node" in r .message ]):
@@ -66,7 +66,7 @@ async def test_daemon_campaign(
6666 await session .commit ()
6767
6868 caplog .clear ()
69- await consider_campaigns (session )
69+ await consider_campaigns (daemon_context )
7070 tasks = (await session .exec (select (Task ))).all ()
7171 # One additional task should be in the table now
7272 assert len (tasks ) == 2
@@ -76,7 +76,7 @@ async def test_daemon_campaign(
7676
7777 # The next assessment should produce two nodes to be handled in parallel
7878 caplog .clear ()
79- await consider_campaigns (session )
79+ await consider_campaigns (daemon_context )
8080 tasks = (await session .exec (select (Task ))).all ()
8181 # Two additional tasks should be in the table now
8282 assert len (tasks ) == 4
@@ -89,7 +89,7 @@ async def test_daemon_campaign(
8989
9090 # The next assessment should produce the END node
9191 caplog .clear ()
92- await consider_campaigns (session )
92+ await consider_campaigns (daemon_context )
9393 tasks = (await session .exec (select (Task ))).all ()
9494 # One additional task should be in the table now
9595 assert len (tasks ) == 5
@@ -114,8 +114,9 @@ async def test_daemon_node(
114114 mock_launch : Mock ,
115115 caplog : pytest .LogCaptureFixture ,
116116 test_campaign : str ,
117- session : AsyncSession ,
117+ daemon_context : DaemonContext ,
118118) -> None :
119+ session = daemon_context .session
119120 # set the campaign to running (without involving a campaign machine)
120121 campaign_id = urlparse (url = test_campaign ).path .split ("/" )[- 2 :][0 ]
121122 campaign = await session .get_one (Campaign , campaign_id )
@@ -124,8 +125,8 @@ async def test_daemon_node(
124125
125126 # after the equivalent of a single iteration, the test campaign's START
126127 # Node will be on the task list with a transition from waiting->ready.
127- await consider_campaigns (session )
128- await consider_nodes (session )
128+ await consider_campaigns (daemon_context )
129+ await consider_nodes (daemon_context )
129130
130131 # As we continue to iterate the daemon over the campaign's 5 nodes
131132 # (including its START and END), each node in the graph is evolved.
@@ -139,8 +140,8 @@ async def test_daemon_node(
139140 i = 12
140141 while end_node .status is not StatusEnum .accepted :
141142 i -= 1
142- await consider_campaigns (session )
143- await consider_nodes (session )
143+ await consider_campaigns (daemon_context )
144+ await consider_nodes (daemon_context )
144145 # the end node is expunged from the session as a side effect when the
145146 # graph is built
146147 session .add (end_node )
0 commit comments