Mercurial > p > roundup > code
diff test/benchmark.py @ 7872:163d2c60fdf3
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.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 10 Apr 2024 12:54:18 -0400 |
| parents | 30fcdf60da44 |
| children | 867418c24339 |
line wrap: on
line diff
--- a/test/benchmark.py Wed Apr 10 00:14:58 2024 -0400 +++ b/test/benchmark.py Wed Apr 10 12:54:18 2024 -0400 @@ -1,6 +1,16 @@ from __future__ import print_function import sys, os, time -import importlib +import importlib, signal, shutil + +# --- patch sys.path to make sure 'import roundup' finds correct version +import os.path as osp +import pdb; pdb.set_trace() +thisdir = osp.dirname(osp.abspath(__file__)) +rootdir = osp.dirname(thisdir) +if (osp.exists(thisdir + '/benchmark.py') and + osp.exists(rootdir + '/roundup/__init__.py')): + # the script is located inside roundup source code + sys.path.insert(0, rootdir) from roundup.hyperdb import String, Password, Link, Multilink, Date, \ Interval, DatabaseError, Boolean, Number @@ -8,6 +18,8 @@ from test.db_test_base import config +int_sig_default_handler = None + def setupSchema(db, module): status = module.Class(db, "status", name=String()) status.setkey("name") @@ -24,7 +36,15 @@ db.post_init() db.commit() +def rm_db_on_signal(sig, frame): + print("removing incomplete database %s due to interruption." % + config.DATABASE) + shutil.rmtree(config.DATABASE) + signal.signal(signal.SIGINT, int_sig_default_handler) + signal.raise_signal(signal.SIGTERM) + def main(backendname, time=time.time, numissues=10): + global int_sig_default_handler try: backend = importlib.import_module("roundup.backends.back_%s" % backendname) @@ -36,6 +56,7 @@ config.DATABASE = os.path.join('_benchmark', '%s-%s'%(backendname, numissues)) if not os.path.exists(config.DATABASE): + int_sig_default_handler = signal.signal(signal.SIGINT, rm_db_on_signal) db = backend.Database(config, 'admin') setupSchema(db, backend) # create a whole bunch of stuff @@ -55,11 +76,12 @@ db.issue.set(str(i+1), status='2', assignedto='2', nosy=[]) db.issue.set(str(i+1), status='1', assignedto='1', nosy=['1','2']) - if (i*100//numissues) != pc: + if (i*100//numissues) != pc and 'INCI' not in os.environ: pc = (i*100//numissues) sys.stdout.write("%d%%\r"%pc) sys.stdout.flush() db.commit() + signal.signal(signal.SIGINT, int_sig_default_handler) else: db = backend.Database(config, 'admin') setupSchema(db, backend)
