@@ -72,12 +72,18 @@ def _db_matches(self, patt, item):
7272 regex = re .compile (patt )
7373 return regex .match (item ) is not None
7474
75+ def _db_connect (self , * args , ** kwargs ):
76+ timeout = runtime ().get_option ('storage/0/sqlite_conn_timeout' )
77+ kwargs .setdefault ('timeout' , timeout )
78+ with getprofiler ().time_region ('sqlite connect' ):
79+ return sqlite3 .connect (* args , ** kwargs )
80+
7581 def _db_create (self ):
7682 clsname = type (self ).__name__
7783 getlogger ().debug (
7884 f'{ clsname } : creating results database in { self .__db_file } ...'
7985 )
80- with sqlite3 . connect (self .__db_file ) as conn :
86+ with self . _db_connect (self .__db_file ) as conn :
8187 conn .execute ('CREATE TABLE IF NOT EXISTS sessions('
8288 'uuid TEXT PRIMARY KEY, '
8389 'session_start_unix REAL, '
@@ -100,13 +106,13 @@ def _db_create(self):
100106 'schema_version TEXT)' )
101107
102108 def _db_schema_check (self ):
103- with sqlite3 . connect (self .__db_file ) as conn :
109+ with self . _db_connect (self .__db_file ) as conn :
104110 results = conn .execute (
105111 'SELECT schema_version FROM metadata' ).fetchall ()
106112
107113 if not results :
108114 # DB is new, insert the schema version
109- with sqlite3 . connect (self .__db_file ) as conn :
115+ with self . _db_connect (self .__db_file ) as conn :
110116 conn .execute ('INSERT INTO metadata VALUES(:schema_version)' ,
111117 {'schema_version' : self .SCHEMA_VERSION })
112118 else :
@@ -159,14 +165,14 @@ def _db_store_report(self, conn, report, report_file_path):
159165
160166 def store (self , report , report_file = None ):
161167 prefix = os .path .dirname (self .__db_file )
162- with sqlite3 . connect (self ._db_file ()) as conn :
168+ with self . _db_connect (self ._db_file ()) as conn :
163169 with FileLock (os .path .join (prefix , '.db.lock' )):
164170 return self ._db_store_report (conn , report , report_file )
165171
166172 @time_function
167173 def _fetch_testcases_raw (self , condition ):
168174 getprofiler ().enter_region ('sqlite query' )
169- with sqlite3 . connect (self ._db_file ()) as conn :
175+ with self . _db_connect (self ._db_file ()) as conn :
170176 query = ('SELECT session_uuid, testcases.uuid as uuid, json_blob '
171177 'FROM testcases '
172178 'JOIN sessions ON session_uuid == sessions.uuid '
@@ -207,7 +213,7 @@ def _fetch_testcases_raw(self, condition):
207213
208214 @time_function
209215 def fetch_session_time_period (self , session_uuid ):
210- with sqlite3 . connect (self ._db_file ()) as conn :
216+ with self . _db_connect (self ._db_file ()) as conn :
211217 query = ('SELECT session_start_unix, session_end_unix '
212218 f'FROM sessions WHERE uuid == "{ session_uuid } " '
213219 'LIMIT 1' )
@@ -231,7 +237,7 @@ def fetch_testcases_time_period(self, ts_start, ts_end, name_pattern=None):
231237
232238 @time_function
233239 def fetch_testcases_from_session (self , session_uuid , name_pattern = None ):
234- with sqlite3 . connect (self ._db_file ()) as conn :
240+ with self . _db_connect (self ._db_file ()) as conn :
235241 query = ('SELECT json_blob from sessions '
236242 f'WHERE uuid == "{ session_uuid } "' )
237243 getlogger ().debug (query )
@@ -246,7 +252,7 @@ def fetch_testcases_from_session(self, session_uuid, name_pattern=None):
246252
247253 @time_function
248254 def fetch_sessions_time_period (self , ts_start = None , ts_end = None ):
249- with sqlite3 . connect (self ._db_file ()) as conn :
255+ with self . _db_connect (self ._db_file ()) as conn :
250256 query = 'SELECT json_blob from sessions'
251257 if ts_start or ts_end :
252258 query += ' WHERE ('
@@ -269,7 +275,7 @@ def fetch_sessions_time_period(self, ts_start=None, ts_end=None):
269275
270276 @time_function
271277 def fetch_session_json (self , uuid ):
272- with sqlite3 . connect (self ._db_file ()) as conn :
278+ with self . _db_connect (self ._db_file ()) as conn :
273279 query = f'SELECT json_blob FROM sessions WHERE uuid == "{ uuid } "'
274280 getlogger ().debug (query )
275281 results = conn .execute (query ).fetchall ()
@@ -279,7 +285,7 @@ def fetch_session_json(self, uuid):
279285 def _do_remove (self , uuid ):
280286 prefix = os .path .dirname (self .__db_file )
281287 with FileLock (os .path .join (prefix , '.db.lock' )):
282- with sqlite3 . connect (self ._db_file ()) as conn :
288+ with self . _db_connect (self ._db_file ()) as conn :
283289 # Check first if the uuid exists
284290 query = f'SELECT * FROM sessions WHERE uuid == "{ uuid } "'
285291 getlogger ().debug (query )
@@ -294,7 +300,7 @@ def _do_remove2(self, uuid):
294300 '''Remove a session using the RETURNING keyword'''
295301 prefix = os .path .dirname (self .__db_file )
296302 with FileLock (os .path .join (prefix , '.db.lock' )):
297- with sqlite3 . connect (self ._db_file ()) as conn :
303+ with self . _db_connect (self ._db_file ()) as conn :
298304 query = (f'DELETE FROM sessions WHERE uuid == "{ uuid } " '
299305 'RETURNING *' )
300306 getlogger ().debug (query )
0 commit comments