sapling/tests/test-infinitepushbackup-logging.t
Jun Wu 9dc21f8d0b codemod: import from the edenscm package
Summary:
D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`.
That has nasty problems if both `import mercurial` and
`import edenscm.mercurial` are used, because Python would think `mercurial.foo`
and `edenscm.mercurial.foo` are different modules so code like
`try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)`
would fail to handle the `edenscm.mercurial` version. There are also some
module-level states (ex. `extensions._extensions`) that would cause trouble if
they have multiple versions in a single process.

Change imports to use the `edenscm` so ideally the `mercurial` is no longer
imported at all. Add checks in extensions.py to catch unexpected extensions
importing modules from the old (wrong) locations when running tests.

Reviewed By: phillco

Differential Revision: D13868981

fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
2019-01-29 17:25:32 -08:00

79 lines
3.9 KiB
Raku

$ . "$TESTDIR/library.sh"
$ . "$TESTDIR/infinitepush/library.sh"
$ setupcommon
$ hg init repo
$ cd repo
$ setupserver
$ cd ..
$ hg clone ssh://user@dummy/repo client -q
$ cat >> $TESTTMP/uilog.py <<EOF
> from edenscm.mercurial import extensions
> from edenscm.mercurial import ui as uimod
> def uisetup(ui):
> extensions.wrapfunction(uimod.ui, 'log', mylog)
> def mylog(orig, self, service, *msg, **opts):
> if service in ['infinitepush']:
> kwstr = ", ".join("%s=%s" % (k, v) for k, v in
> sorted(opts.iteritems()))
> msgstr = msg[0] % msg[1:]
> self.warn('%s: %s (%s)\n' % (service, msgstr, kwstr))
> return orig(self, service, *msg, **opts)
> EOF
$ cat >> repo/.hg/hgrc <<EOF
> [extensions]
> uilog=$TESTTMP/uilog.py
> EOF
$ cd client
$ mkcommit commit
$ hg push -r . --to scratch/scratchpush --create
pushing to ssh://user@dummy/repo
searching for changes
remote: infinitepush: b2x:infinitepush \(eventtype=start, hostname=.+, requestid=\d+, user=\w+\) (re)
remote: pushing 1 commit:
remote: 7e6a6fd9c7c8 commit
remote: infinitepush: bundlestore \(bundlesize=546, eventtype=start, hostname=.+, reponame=babar, requestid=\d+, user=\w+\) (re)
remote: infinitepush: bundlestore \(bundlesize=546, elapsedms=.+, eventtype=success, hostname=.+, reponame=babar, requestid=\d+, user=\w+\) (re)
remote: infinitepush: index \(eventtype=start, hostname=.+, newheadscount=1, reponame=babar, requestid=\d+, user=\w+\) (re)
remote: infinitepush: index \(elapsedms=.+, eventtype=success, hostname=.+, newheadscount=1, reponame=babar, requestid=\d+, user=\w+\) (re)
remote: infinitepush: b2x:infinitepush \(elapsedms=.+, eventtype=success, hostname=.+, reponame=babar, requestid=\d+, user=\w+\) (re)
$ cd ..
Check that logging works for b2x:infinitepushscratchbookmarks part
$ cd client
$ hg pushbackup
starting backup .* (re)
backing up stack rooted at 7e6a6fd9c7c8
remote: infinitepush: b2x:infinitepush \(eventtype=start, hostname=.+, reponame=babar, requestid=\d+, user=\w+\) (re)
remote: pushing 1 commit:
remote: 7e6a6fd9c7c8 commit
remote: infinitepush: index \(eventtype=start, hostname=.+, newheadscount=0, reponame=babar, requestid=\d+, user=\w+\) (re)
remote: infinitepush: index \(elapsedms=.+, eventtype=success, hostname=.+, newheadscount=0, reponame=babar, requestid=\d+, user=\w+\) (re)
remote: infinitepush: b2x:infinitepush \(elapsedms=.+, eventtype=success, hostname=.+, reponame=babar, requestid=\d+, user=\w+\) (re)
remote: infinitepush: b2x:infinitepushscratchbookmarks \(eventtype=start, hostname=.+, reponame=babar, requestid=\d+, user=\w+\) (re)
remote: infinitepush: b2x:infinitepushscratchbookmarks \(elapsedms=.+, eventtype=success, hostname=.+, reponame=babar, requestid=\d+, user=\w+\) (re)
finished in \d+\.(\d+)? seconds (re)
$ cd ..
Make upload to bundlestore fail
$ cat >> repo/.hg/hgrc <<EOF
> [scratchbranch]
> storepath=/dev/null
> EOF
$ cd client
$ mkcommit failpushcommit
$ hg push -r . --to scratch/scratchpush 2>err
pushing to ssh://user@dummy/repo
searching for changes
[255]
$ grep '^remote: ' err
remote: infinitepush: b2x:infinitepush \(eventtype=start, hostname=.+, requestid=\d+, user=\w+\) (re)
remote: pushing 2 commits:
remote: 7e6a6fd9c7c8 commit
remote: bba29d9d577a failpushcommit
remote: infinitepush: bundlestore \(bundlesize=1067, eventtype=start, hostname=.+, requestid=\d+, user=\w+\) (re)
remote: infinitepush: bundlestore \(bundlesize=1067, elapsedms=[-+0-9.e]+, errormsg=\[Errno 20\] \$ENOTDIR\$: '/dev/null/\d+', eventtype=failure, hostname=.+, reponame=babar, requestid=\d+, user=\w+\) (re)
remote: infinitepush: b2x:infinitepush \(elapsedms=[-+0-9.e]+, errormsg=\[Errno 20\] \$ENOTDIR\$: '/dev/null/\d+', eventtype=failure, hostname=.+, reponame=babar, requestid=\d+, user=\w+\) (re)
remote: abort: \$ENOTDIR\$: '/dev/null/\d+' (re)