Skip to content

Commit baffba0

Browse files
committed
test: benchmark no progress when INCI defined; set path; signal handling
The progress reports on issue creation in the db breaks up the table in CI as each is reported on a new line. If the environment variable INCI is set to any value, don't generate progress output. Change GitHub action to define INCI Insert roundup root directory in sys.path so import from test directory will be found. Also set up signal handler to delete the database if ^C is pressed during creation. The interrupted db is incomplete (required data missing), but it is used as is for a subsequent run. This causes the benchmark to crash.
1 parent f6f29af commit baffba0

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

.github/workflows/ci-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ jobs:
315315

316316
- name: run benchmarks
317317
if: "contains(github.event.head_commit.message, 'benchmark')"
318-
run: PYTHONPATH=. python test/benchmark.py
318+
run: INCI=1 python test/benchmark.py
319319

320320
# in parallel build coveralls requires a finish step
321321
finish:

test/benchmark.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
from __future__ import print_function
22
import sys, os, time
3-
import importlib
3+
import importlib, signal, shutil
4+
5+
# --- patch sys.path to make sure 'import roundup' finds correct version
6+
import os.path as osp
7+
import pdb; pdb.set_trace()
8+
thisdir = osp.dirname(osp.abspath(__file__))
9+
rootdir = osp.dirname(thisdir)
10+
if (osp.exists(thisdir + '/benchmark.py') and
11+
osp.exists(rootdir + '/roundup/__init__.py')):
12+
# the script is located inside roundup source code
13+
sys.path.insert(0, rootdir)
414

515
from roundup.hyperdb import String, Password, Link, Multilink, Date, \
616
Interval, DatabaseError, Boolean, Number
717
from roundup import date, password
818

919
from test.db_test_base import config
1020

21+
int_sig_default_handler = None
22+
1123
def setupSchema(db, module):
1224
status = module.Class(db, "status", name=String())
1325
status.setkey("name")
@@ -24,7 +36,15 @@ def setupSchema(db, module):
2436
db.post_init()
2537
db.commit()
2638

39+
def rm_db_on_signal(sig, frame):
40+
print("removing incomplete database %s due to interruption." %
41+
config.DATABASE)
42+
shutil.rmtree(config.DATABASE)
43+
signal.signal(signal.SIGINT, int_sig_default_handler)
44+
signal.raise_signal(signal.SIGTERM)
45+
2746
def main(backendname, time=time.time, numissues=10):
47+
global int_sig_default_handler
2848
try:
2949
backend = importlib.import_module("roundup.backends.back_%s" %
3050
backendname)
@@ -36,6 +56,7 @@ def main(backendname, time=time.time, numissues=10):
3656
config.DATABASE = os.path.join('_benchmark', '%s-%s'%(backendname,
3757
numissues))
3858
if not os.path.exists(config.DATABASE):
59+
int_sig_default_handler = signal.signal(signal.SIGINT, rm_db_on_signal)
3960
db = backend.Database(config, 'admin')
4061
setupSchema(db, backend)
4162
# create a whole bunch of stuff
@@ -55,11 +76,12 @@ def main(backendname, time=time.time, numissues=10):
5576
db.issue.set(str(i+1), status='2', assignedto='2', nosy=[])
5677
db.issue.set(str(i+1), status='1', assignedto='1',
5778
nosy=['1','2'])
58-
if (i*100//numissues) != pc:
79+
if (i*100//numissues) != pc and 'INCI' not in os.environ:
5980
pc = (i*100//numissues)
6081
sys.stdout.write("%d%%\r"%pc)
6182
sys.stdout.flush()
6283
db.commit()
84+
signal.signal(signal.SIGINT, int_sig_default_handler)
6385
else:
6486
db = backend.Database(config, 'admin')
6587
setupSchema(db, backend)

0 commit comments

Comments
 (0)