11from threading import Thread
22
33import pytest
4+ import uvicorn
45
56from unittest .mock import patch
67from pathlib import Path
1213from src .modules .sidecars .performance .collector .collector import PerformanceCollector
1314from src .modules .common .types import FrameConfig
1415from src .modules .sidecars .performance .common .db import Duty
15- from src .modules .sidecars .performance .web .server import serve
16+ from src .modules .sidecars .performance .web .server import app
1617from src .utils .range import sequence
1718from src .web3py .types import Web3
1819from tests .fork .conftest import first_slot_of_epoch
1920
21+ # pylint: disable=protected-access
22+
2023
2124@pytest .fixture ()
2225def hash_consensus_bin ():
@@ -40,12 +43,19 @@ def performance_local_db(testrun_path):
4043
4144 def mock_get_database_url (self ):
4245 db_path = Path (testrun_path ) / "test_duties.db"
46+ db_path .parent .mkdir (parents = True , exist_ok = True )
4347 return f"sqlite:///{ db_path } "
4448
49+ def mock_build_engine (self , connect_timeout ):
50+ return create_engine (
51+ self ._get_database_url (),
52+ echo = False ,
53+ pool_pre_ping = True ,
54+ )
55+
4556 def mock_init (self , * args , ** kwargs ):
46- # pylint: disable=protected-access
47- self .engine = create_engine (self ._get_database_url (), echo = False )
48- # pylint: disable=protected-access
57+ self ._statement_timeout_ms = kwargs .get ('statement_timeout_ms' )
58+ self .engine = self ._build_engine (kwargs .get ('connect_timeout' ))
4959 self ._setup_database ()
5060
5161 table = Duty .__table__
@@ -54,8 +64,9 @@ def mock_init(self, *args, **kwargs):
5464 table .c [col_name ].type = JSON ()
5565
5666 with patch ('src.modules.sidecars.performance.common.db.DutiesDB._get_database_url' , mock_get_database_url ):
57- with patch ('src.modules.sidecars.performance.common.db.DutiesDB.__init__' , mock_init ):
58- yield mock_get_database_url , mock_init
67+ with patch ('src.modules.sidecars.performance.common.db.DutiesDB._build_engine' , mock_build_engine ):
68+ with patch ('src.modules.sidecars.performance.common.db.DutiesDB.__init__' , mock_init ):
69+ yield mock_get_database_url , mock_init
5970
6071
6172@pytest .fixture ()
@@ -65,7 +76,9 @@ def performance_collector(performance_local_db, web3: Web3, frame_config: FrameC
6576
6677@pytest .fixture ()
6778def performance_web_server (performance_local_db ):
68- Thread (target = serve , daemon = True ).start ()
79+ Thread (
80+ target = uvicorn .run , args = (app ,), kwargs = {'host' : '127.0.0.1' , 'port' : 9020 , 'log_level' : 'error' }, daemon = True
81+ ).start ()
6982 yield
7083
7184
@@ -98,19 +111,12 @@ def missed_initial_frame(frame_config: FrameConfig, cycle_iterations):
98111@pytest .mark .fork
99112@pytest .mark .parametrize (
100113 'module' ,
101- [
102- csm_module ,
103- # cm_module
104- ],
114+ [csm_module , cm_module ],
105115 indirect = True ,
106116)
107117@pytest .mark .parametrize (
108118 'running_finalized_slots' ,
109- [
110- # start_before_initial_epoch,
111- start_after_initial_epoch ,
112- # missed_initial_frame
113- ],
119+ [start_before_initial_epoch , start_after_initial_epoch , missed_initial_frame ],
114120 indirect = True ,
115121)
116122def test_csm_module_report (
0 commit comments