testing: force hgwebdir to refresh on every request
authorGregory Szorc <gps@mozilla.com>
Sat, 24 Jan 2015 18:54:12 -0800
changeset 360254 f0b48c38689d655918eed57955b681d05258669b
parent 360253 f6dfc05658939c27cc83618d151b8b13a0a40e5b
child 360255 88e99df69400b7a6cbe4b1cb2f947c5dd239ba54
push id16998
push userrwood@mozilla.com
push dateMon, 02 May 2016 19:42:03 +0000
testing: force hgwebdir to refresh on every request hgwebdir only scans for new repositories every 20s. This interferes with our ability to run tests that create repositories against a running hgwebdir server. This patch introduces an extension that forces hgwebdir to refresh on request.
testing/refreshinghgwebdir.py
testing/vcttesting/mozreview.py
new file mode 100644
--- /dev/null
+++ b/testing/refreshinghgwebdir.py
@@ -0,0 +1,31 @@
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+"""Dummy extension to force hgwebdir to always refresh.
+
+By default, hgwebdir only refreshes every 20 seconds. This means that if
+we create a new repository, it doesn't appear on hgweb for 20 seconds.
+
+We have tests that use hgwebdir and we need hgweb to respond to new
+repositories without waiting 20 seconds or requiring a process restart.
+
+Installing this extension forces hgwebdir to refresh on every request.
+This does result in a slight performance loss. But this extension should
+only be used as part of tests, so it shouldn't matter.
+"""
+
+
+from mercurial.extensions import wrapfunction
+import mercurial.hgweb as hgweb
+
+def wrappedhgweb(orig, *args, **kwargs):
+    web = orig(*args, **kwargs)
+
+    if isinstance(web, hgweb.hgwebdir_mod.hgwebdir):
+        web.refreshinterval = -1
+
+    return web
+
+
+def extsetup(ui):
+    wrapfunction(hgweb, 'hgweb', wrappedhgweb)
--- a/testing/vcttesting/mozreview.py
+++ b/testing/vcttesting/mozreview.py
@@ -227,21 +227,27 @@ class MozReview(object):
                 'push_ssl = False',
                 'allow_push = *',
                 '',
                 '[paths]',
                 '/ = %s/**' % repos_path,
                 '',
             ]))
 
+        # hgwebdir doesn't pick up new repositories until 20s after they
+        # are created. We install an extension to always refresh.
+        refreshing_path = os.path.join(ROOT, 'testing',
+                                       'refreshinghgwebdir.py')
+
         env = os.environ.copy()
         env['HGRCPATH'] = global_hgrc
         env['HGENCODING'] = 'UTF-8'
         args = [
             self._hg,
+            '--config', 'extensions.refreshinghgwebdir=%s' % refreshing_path,
             'serve',
             '-d',
             '-p', str(port),
             '--pid-file', self._hg_pid_path,
             '--web-conf', web_conf,
             '--accesslog', os.path.join(self._path, 'hg.access.log'),
             '--errorlog', os.path.join(self._path, 'hg.error.log'),
         ]