| 1 |
import os |
| 2 |
from mercurial.hgweb import hgwebdir_mod |
| 3 |
|
| 4 |
hgwebdir = hgwebdir_mod.hgwebdir |
| 5 |
|
| 6 |
os.mkdir(b'webdir') |
| 7 |
os.chdir(b'webdir') |
| 8 |
|
| 9 |
webdir = os.path.realpath(b'.') |
| 10 |
|
| 11 |
|
| 12 |
def trivial_response(req, res): |
| 13 |
return [] |
| 14 |
|
| 15 |
|
| 16 |
def make_hgwebdir(gc_rate=None): |
| 17 |
config = os.path.join(webdir, b'hgwebdir.conf') |
| 18 |
with open(config, 'wb') as configfile: |
| 19 |
configfile.write(b'[experimental]\n') |
| 20 |
if gc_rate is not None: |
| 21 |
configfile.write(b'web.full-garbage-collection-rate=%d\n' % gc_rate) |
| 22 |
hg_wd = hgwebdir(config) |
| 23 |
hg_wd._runwsgi = trivial_response |
| 24 |
return hg_wd |
| 25 |
|
| 26 |
|
| 27 |
def process_requests(webdir_instance, number): |
| 28 |
# we don't care for now about passing realistic arguments |
| 29 |
for _ in range(number): |
| 30 |
for chunk in webdir_instance.run_wsgi(None, None): |
| 31 |
pass |
| 32 |
|
| 33 |
|
| 34 |
without_gc = make_hgwebdir(gc_rate=0) |
| 35 |
process_requests(without_gc, 5) |
| 36 |
assert without_gc.requests_count == 5 |
| 37 |
assert without_gc.gc_full_collections_done == 0 |
| 38 |
|
| 39 |
with_gc = make_hgwebdir(gc_rate=2) |
| 40 |
process_requests(with_gc, 5) |
| 41 |
assert with_gc.requests_count == 5 |
| 42 |
assert with_gc.gc_full_collections_done == 2 |
| 43 |
|
| 44 |
with_systematic_gc = make_hgwebdir() # default value of the setting |
| 45 |
process_requests(with_systematic_gc, 3) |
| 46 |
assert with_systematic_gc.requests_count == 3 |
| 47 |
assert with_systematic_gc.gc_full_collections_done == 3 |