Spaces:
Runtime error
Runtime error
Updated the offline save to save the actual request and response text
Browse files- data/sqlite/test_records.db +2 -2
- src/testing.py +15 -9
data/sqlite/test_records.db
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:77eafc9e7568c68f874f45e17a46440e3ccf207f676cc08330627350f594eb75
|
3 |
+
size 200704
|
src/testing.py
CHANGED
@@ -66,10 +66,12 @@ class ArchitectureRequestRecord:
|
|
66 |
self.end = end
|
67 |
self.elapsed = end - start
|
68 |
|
69 |
-
def __init__(self, arch: str, response_len: int, start: int, end: int,
|
70 |
elapsed: int, tags: List[str], test_group: Optional[str],
|
71 |
comment: str, steps: List[ArchitectureRequestRecord.ArchStep]):
|
72 |
self.arch = arch
|
|
|
|
|
73 |
self.response_len = response_len
|
74 |
self.start = start
|
75 |
self.end = end
|
@@ -82,10 +84,13 @@ class ArchitectureRequestRecord:
|
|
82 |
@classmethod
|
83 |
def from_dict(cls, test: Dict) -> ArchitectureRequestRecord:
|
84 |
arch = test['architecture']
|
|
|
|
|
85 |
if len(test['request']['response_evolution']) == 0:
|
86 |
response_len = 0
|
87 |
else:
|
88 |
response_len = len(test['request']['response_evolution'][-1])
|
|
|
89 |
start = test['trace']['steps'][0]['start_ms']
|
90 |
end = test['trace']['steps'][-1]['end_ms']
|
91 |
elapsed = end - start
|
@@ -98,7 +103,7 @@ class ArchitectureRequestRecord:
|
|
98 |
steps = []
|
99 |
for s in test['trace']['steps']:
|
100 |
steps.append(ArchitectureRequestRecord.ArchStep(s['name'], s['start_ms'], s['end_ms']))
|
101 |
-
return ArchitectureRequestRecord(
|
102 |
|
103 |
@classmethod
|
104 |
def load_all(cls, reload=False) -> None:
|
@@ -242,14 +247,14 @@ class TestGroup:
|
|
242 |
|
243 |
for tg_id, tg_name in tg_id_names:
|
244 |
tg = TestGroup(tg_name)
|
245 |
-
sql = f"SELECT id, arch_name, response_len, start, end, comment FROM arch_requests WHERE test_group_id={tg_id}"
|
246 |
cur.execute(sql)
|
247 |
-
arch_requests = [(r[0], r[1], r[2], r[3], r[4], r[5]) for r in cur.fetchall()]
|
248 |
-
for ar_id, ar_arch_name, ar_resp_len, ar_start, ar_end, ar_comment in arch_requests:
|
249 |
sql = f"SELECT name, start, end FROM arch_req_steps WHERE arch_req_id={ar_id}"
|
250 |
cur.execute(sql)
|
251 |
steps = [ArchitectureRequestRecord.ArchStep(r[0], r[1], r[2]) for r in cur.fetchall()]
|
252 |
-
arch_req_record = ArchitectureRequestRecord(ar_arch_name, ar_resp_len, ar_start, ar_end, (ar_end - ar_start), [tg_name], tg_name, f"(DB persisted) {ar_comment}", steps)
|
253 |
tg.add_record(arch_req_record)
|
254 |
test_groups.append(tg)
|
255 |
return test_groups
|
@@ -310,7 +315,7 @@ def move_test_records_to_db(hf_hub_token: str) -> None:
|
|
310 |
sql = "CREATE TABLE test_groups (id INTEGER PRIMARY KEY AUTOINCREMENT, test_group TEXT NOT NULL, start INTEGER NOT NULL, end INTEGER NOT NULL);"
|
311 |
con.execute(sql)
|
312 |
|
313 |
-
sql = "CREATE TABLE arch_requests (id INTEGER PRIMARY KEY AUTOINCREMENT, arch_name TEXT NOT NULL, response_len INTEGER NOT NULL, start INTEGER NOT NULL, end INTEGER NOT NULL, comment TEXT NOT NULL, test_group_id INTEGER NOT NULL, FOREIGN KEY (test_group_id) REFERENCES test_groups (id))"
|
314 |
con.execute(sql)
|
315 |
|
316 |
sql = "CREATE TABLE arch_req_steps (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, start INTEGER NOT NULL, end INTEGER NOT NULL, arch_req_id INTEGER NOT NULL, FOREIGN KEY (arch_req_id) REFERENCES arch_requests(id))"
|
@@ -339,8 +344,9 @@ def move_test_records_to_db(hf_hub_token: str) -> None:
|
|
339 |
tg_id = con.execute(sql).lastrowid
|
340 |
|
341 |
for arr in test_group.arch_request_records:
|
342 |
-
|
343 |
-
|
|
|
344 |
|
345 |
for s in arr.steps:
|
346 |
sql= f'INSERT INTO arch_req_steps (name, start, end, arch_req_id) VALUES ("{s.name}", {s.start}, {s.end}, {arr_id})'
|
|
|
66 |
self.end = end
|
67 |
self.elapsed = end - start
|
68 |
|
69 |
+
def __init__(self, arch: str, request: str, response: str, response_len: int, start: int, end: int,
|
70 |
elapsed: int, tags: List[str], test_group: Optional[str],
|
71 |
comment: str, steps: List[ArchitectureRequestRecord.ArchStep]):
|
72 |
self.arch = arch
|
73 |
+
self.request = request
|
74 |
+
self.response = response
|
75 |
self.response_len = response_len
|
76 |
self.start = start
|
77 |
self.end = end
|
|
|
84 |
@classmethod
|
85 |
def from_dict(cls, test: Dict) -> ArchitectureRequestRecord:
|
86 |
arch = test['architecture']
|
87 |
+
request = test['request']['request_evolution'][0]
|
88 |
+
response = ""
|
89 |
if len(test['request']['response_evolution']) == 0:
|
90 |
response_len = 0
|
91 |
else:
|
92 |
response_len = len(test['request']['response_evolution'][-1])
|
93 |
+
response = test['request']['response_evolution'][-1]
|
94 |
start = test['trace']['steps'][0]['start_ms']
|
95 |
end = test['trace']['steps'][-1]['end_ms']
|
96 |
elapsed = end - start
|
|
|
103 |
steps = []
|
104 |
for s in test['trace']['steps']:
|
105 |
steps.append(ArchitectureRequestRecord.ArchStep(s['name'], s['start_ms'], s['end_ms']))
|
106 |
+
return ArchitectureRequestRecord(arch, request, response, response_len, start, end, elapsed, tags, test_group, comment, steps)
|
107 |
|
108 |
@classmethod
|
109 |
def load_all(cls, reload=False) -> None:
|
|
|
247 |
|
248 |
for tg_id, tg_name in tg_id_names:
|
249 |
tg = TestGroup(tg_name)
|
250 |
+
sql = f"SELECT id, arch_name, request, response, response_len, start, end, comment FROM arch_requests WHERE test_group_id={tg_id}"
|
251 |
cur.execute(sql)
|
252 |
+
arch_requests = [(r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7]) for r in cur.fetchall()]
|
253 |
+
for ar_id, ar_arch_name, ar_req, ar_resp, ar_resp_len, ar_start, ar_end, ar_comment in arch_requests:
|
254 |
sql = f"SELECT name, start, end FROM arch_req_steps WHERE arch_req_id={ar_id}"
|
255 |
cur.execute(sql)
|
256 |
steps = [ArchitectureRequestRecord.ArchStep(r[0], r[1], r[2]) for r in cur.fetchall()]
|
257 |
+
arch_req_record = ArchitectureRequestRecord(ar_arch_name, ar_req, ar_resp, ar_resp_len, ar_start, ar_end, (ar_end - ar_start), [tg_name], tg_name, f"(DB persisted) {ar_comment}", steps)
|
258 |
tg.add_record(arch_req_record)
|
259 |
test_groups.append(tg)
|
260 |
return test_groups
|
|
|
315 |
sql = "CREATE TABLE test_groups (id INTEGER PRIMARY KEY AUTOINCREMENT, test_group TEXT NOT NULL, start INTEGER NOT NULL, end INTEGER NOT NULL);"
|
316 |
con.execute(sql)
|
317 |
|
318 |
+
sql = "CREATE TABLE arch_requests (id INTEGER PRIMARY KEY AUTOINCREMENT, arch_name TEXT NOT NULL, request TEXT NOT NULL, response TEXT NOT NULL, response_len INTEGER NOT NULL, start INTEGER NOT NULL, end INTEGER NOT NULL, comment TEXT NOT NULL, test_group_id INTEGER NOT NULL, FOREIGN KEY (test_group_id) REFERENCES test_groups (id))"
|
319 |
con.execute(sql)
|
320 |
|
321 |
sql = "CREATE TABLE arch_req_steps (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, start INTEGER NOT NULL, end INTEGER NOT NULL, arch_req_id INTEGER NOT NULL, FOREIGN KEY (arch_req_id) REFERENCES arch_requests(id))"
|
|
|
344 |
tg_id = con.execute(sql).lastrowid
|
345 |
|
346 |
for arr in test_group.arch_request_records:
|
347 |
+
|
348 |
+
sql = f'INSERT INTO arch_requests (arch_name, request, response, response_len, start, end, comment, test_group_id) VALUES ("{arr.arch}", ?, ?, {arr.response_len}, {arr.start}, {arr.end}, "{arr.comment}", {tg_id})'
|
349 |
+
arr_id = con.execute(sql, (arr.request, arr.response)).lastrowid
|
350 |
|
351 |
for s in arr.steps:
|
352 |
sql= f'INSERT INTO arch_req_steps (name, start, end, arch_req_id) VALUES ("{s.name}", {s.start}, {s.end}, {arr_id})'
|