Mercurial > p > roundup > code
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 7871:30fcdf60da44 | 7872:163d2c60fdf3 |
|---|---|
| 1 from __future__ import print_function | 1 from __future__ import print_function |
| 2 import sys, os, time | 2 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) | |
| 4 | 14 |
| 5 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ | 15 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ |
| 6 Interval, DatabaseError, Boolean, Number | 16 Interval, DatabaseError, Boolean, Number |
| 7 from roundup import date, password | 17 from roundup import date, password |
| 8 | 18 |
| 9 from test.db_test_base import config | 19 from test.db_test_base import config |
| 20 | |
| 21 int_sig_default_handler = None | |
| 10 | 22 |
| 11 def setupSchema(db, module): | 23 def setupSchema(db, module): |
| 12 status = module.Class(db, "status", name=String()) | 24 status = module.Class(db, "status", name=String()) |
| 13 status.setkey("name") | 25 status.setkey("name") |
| 14 user = module.Class(db, "user", username=String(), password=Password(), | 26 user = module.Class(db, "user", username=String(), password=Password(), |
| 22 session = module.Class(db, 'session', title=String()) | 34 session = module.Class(db, 'session', title=String()) |
| 23 session.disableJournalling() | 35 session.disableJournalling() |
| 24 db.post_init() | 36 db.post_init() |
| 25 db.commit() | 37 db.commit() |
| 26 | 38 |
| 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 | |
| 27 def main(backendname, time=time.time, numissues=10): | 46 def main(backendname, time=time.time, numissues=10): |
| 47 global int_sig_default_handler | |
| 28 try: | 48 try: |
| 29 backend = importlib.import_module("roundup.backends.back_%s" % | 49 backend = importlib.import_module("roundup.backends.back_%s" % |
| 30 backendname) | 50 backendname) |
| 31 except ImportError: | 51 except ImportError: |
| 32 return | 52 return |
| 34 times = [] | 54 times = [] |
| 35 | 55 |
| 36 config.DATABASE = os.path.join('_benchmark', '%s-%s'%(backendname, | 56 config.DATABASE = os.path.join('_benchmark', '%s-%s'%(backendname, |
| 37 numissues)) | 57 numissues)) |
| 38 if not os.path.exists(config.DATABASE): | 58 if not os.path.exists(config.DATABASE): |
| 59 int_sig_default_handler = signal.signal(signal.SIGINT, rm_db_on_signal) | |
| 39 db = backend.Database(config, 'admin') | 60 db = backend.Database(config, 'admin') |
| 40 setupSchema(db, backend) | 61 setupSchema(db, backend) |
| 41 # create a whole bunch of stuff | 62 # create a whole bunch of stuff |
| 42 db.user.create(**{'username': 'admin', 'roles': 'Admin'}) | 63 db.user.create(**{'username': 'admin', 'roles': 'Admin'}) |
| 43 db.status.create(name="unread") | 64 db.status.create(name="unread") |
| 53 db.issue.create(**{'title': 'issue %s'%i}) | 74 db.issue.create(**{'title': 'issue %s'%i}) |
| 54 for j in range(10): | 75 for j in range(10): |
| 55 db.issue.set(str(i+1), status='2', assignedto='2', nosy=[]) | 76 db.issue.set(str(i+1), status='2', assignedto='2', nosy=[]) |
| 56 db.issue.set(str(i+1), status='1', assignedto='1', | 77 db.issue.set(str(i+1), status='1', assignedto='1', |
| 57 nosy=['1','2']) | 78 nosy=['1','2']) |
| 58 if (i*100//numissues) != pc: | 79 if (i*100//numissues) != pc and 'INCI' not in os.environ: |
| 59 pc = (i*100//numissues) | 80 pc = (i*100//numissues) |
| 60 sys.stdout.write("%d%%\r"%pc) | 81 sys.stdout.write("%d%%\r"%pc) |
| 61 sys.stdout.flush() | 82 sys.stdout.flush() |
| 62 db.commit() | 83 db.commit() |
| 84 signal.signal(signal.SIGINT, int_sig_default_handler) | |
| 63 else: | 85 else: |
| 64 db = backend.Database(config, 'admin') | 86 db = backend.Database(config, 'admin') |
| 65 setupSchema(db, backend) | 87 setupSchema(db, backend) |
| 66 | 88 |
| 67 sys.stdout.write('%7s: %-6d'%(backendname, numissues)) | 89 sys.stdout.write('%7s: %-6d'%(backendname, numissues)) |
