Commit Graph

40 Commits

Author SHA1 Message Date
Pulkit Goyal
b4347ea80f py3: make sure commands name are bytes in tests 2017-06-25 08:20:05 +05:30
Boris Feld
59e3c73ea0 test: remove aliases forcing date, use default-date
Now that we have the default-date by default and all code have been updated,
remove the old commands alias that forced the date as they are not longer
useful.

Writing tests now should be easier for everyone now that all dates should be
stable.
2017-05-22 19:29:21 +02:00
Pierre-Yves David
bb04bb0f0e devel: activate default-date in tests
It will make writing future tests more easier for everyone as we won't need to
glob dates anymore in tests.
2017-05-22 16:59:57 +02:00
Yuya Nishihara
3e663dde68 registrar: move cmdutil.command to registrar module (API)
cmdutil.command wasn't a member of the registrar framework only for a
historical reason. Let's make that happen. This patch keeps cmdutil.command
as an alias for extension compatibility.
2016-01-09 23:07:20 +09:00
Jun Wu
d25b765433 runtests: always set web.ipv6
Previously, we only set web.ipv6 if IPv6 is used, but not on the IPv4 case.

Since we already have set web.address, it makes sense to move "web.ipv6" out
from "extra config options".
2017-02-16 08:43:59 -08:00
Jun Wu
ff1c9b7606 runtests: set web.address to localhost
Previously, "hg serve" will listen on "", which is not clear which interface
it will actually listen on - it could listen on all interfaces (ex. 0.0.0.0
on IPv4).

The run-tests.py script only checks "localhost" for available ports. So
let's make it the same for "hg serve" by explicitly setting "web.address" to
"localhost".

This resolves some IPv6 EADDRINUSE errors.
2017-02-16 00:13:29 -08:00
Jun Wu
1719b329c6 runtests: set web.ipv6 if we use IPv6
As explained by the previous patch, we need to set "web.ipv6=True" if we
decide to use IPv6. Otherwise "hg serve" will still try to listen on IPv4.

This patch makes it so by appending web.ipv6 to "extra configs".

This patch was tested in a Linux system with IPv6, by the following steps:

  1. Change hgweb/server.py temporarily to write a file if
     IPv6HTTPServer.__init__ is called.
  2. run-tests.py -l --keep-tmpdir test-serve.t
  3. Check the generated .hgrc, make sure it sets web.ipv6=1.
  4. Check the log file to make sure IPv6HTTPServer.__init__ is called.
2017-02-15 16:43:27 -08:00
Yuya Nishihara
5d86e43147 ui: check EOF of getpass() response read from command-server channel
readline() returns '' only when EOF is encountered, in which case, Python's
getpass() raises EOFError. We should do the same to abort the session as
"response expected."

This bug was reported to
https://bitbucket.org/tortoisehg/thg/issues/4659/
2017-01-14 20:31:35 +09:00
Yuya Nishihara
cf2dbd1027 hook: do not redirect stdout/err/in to ui while running in-process hooks (BC)
It was introduced by e0df29fe80bf to address command-server issues. After
that, I've made a complete fix by b096b3ac9391, so we don't need to replace
sys.stdio objects to protect the IPC channels.

This change means we no longer see data written to sys.stdout/err by an
in-process hook on command server. I think that's okay because the canonical
way is to use ui functions and in-process hooks should respect the Mercurial
API.

This will help Python 3 porting, where sys.stdout is TextIO but ui.fout is
BytesIO.
2016-10-20 22:39:59 +09:00
Mads Kiilerich
38cb771268 spelling: fixes of non-dictionary words 2016-10-17 23:16:55 +02:00
Yuya Nishihara
db11160c56 histedit: use ui.fin to read commands from stdin
stdin is wrapped by channeledinput in command-server session.
2016-03-18 17:15:06 -07:00
timeless
5fd9e9e1b5 help: use single quotes in use warning 2016-09-20 23:47:46 +00:00
Pulkit Goyal
aef2bdd39a py3: make files use absolute_import and print_function
This patch includes addition of absolute_import and print_function to the
 files where they are missing. The modern importing conventions are also followed.
2016-07-03 22:28:24 +05:30
timeless
cc4a444d91 tests: tolerate http2
You can run tests like this:
run-tests.py -l --extra-config-opt ui.usehttp2=true

And ideally, no tests should fail...
2016-04-21 04:30:18 +00:00
timeless
edef054d1b test-commandserver: handle cStringIO.StringIO/io.StringIO divergence 2016-04-06 20:34:34 +00:00
Yuya Nishihara
025ddf17ef cmdserver: write early exception to 'e' channel in 'unix' mode
In 'unix' mode, the server is typically detached from the console. Therefore
a client couldn't see the exception that occurred while instantiating the
server object.

This patch tries to catch the early error and send it to 'e' channel even if
the server isn't instantiated yet. This means the error may be sent before the
initial hello message. So it's up to the client implementation whether to
handle the early error message or error out as protocol violation.

The error handling code is also copied to chgserver.py. I'll factor out them
later if we manage to get chg passes the test suite.
2016-03-12 22:03:30 +09:00
FUJIWARA Katsunori
4bd619a29e repoview: discard filtered changelog if index isn't shared with unfiltered
Before this patch, revisions rollbacked at failure of previous
transaction might be visible at subsequent operations unintentionally,
if repoview object is reused even after failure of transaction:
e.g. command server and HTTP server are typical cases.

'repoview' uses the tuple of values below of unfiltered changelog as
"the key" to examine validity of filtered changelog cache.

     - length
     - tip node
     - filtered revisions (as hashed value)
     - '_delayed' field

'repoview' compares between "the key" of unfiltered changelog at
previous caching and now, and reuses filtered changelog cache if no
change is detected.

But this comparison indicates only that there is no change between
unfiltered 'repo.changelog' at last caching and now, but not that
filtered changelog cache is valid for current unfiltered one.

'repoview' uses "shallow copy" of unfiltered changelog to create
filtered changelog cache. In this case, 'index' buffer of unfiltered
changelog is also referred by filtered changelog.

At failure of transaction, unfiltered changelog itself is invalidated
(= un-referred) on the 'repo' side (see b7829fc79508 also). But
'index' of it still contains revisions to be rollbacked at this
failure, and is referred by filtered changelog.

Therefore, even if there is no change between unfiltered
'repo.changelog' at last caching and now, steps below makes rollbacked
revisions visible via filtered changelog unintentionally.

  1. instantiate unfiltered changelog as 'repo.changelog'
     (call it CL1)

  2. make filtered (= shallow copy of) CL1
     (call it FCL1)

  3. cache FCL1 with "the key" of CL1

  4. revisions are appended to 'index', which is shared by CL1 and FCL1

  5. invalidate 'repo.changelog' (= CL1) at failure of transaction

  6. instantiate 'repo.changelog' again at next operation
     (call it CL2)

     CL2 doesn't have revisions added at (4), because it is
     instantiated from '00changelog.i', which isn't changed while
     failed transaction.

  7. compare between "the key" of CL1 and CL2

  8. FCL1 cached at (3) is reused, because comparison at (7) doesn't
     detect change between CL1 at (1) and CL2

  9. revisions rollbacked at (5) are visible via FCL1 unintentionally,
     because FCL1 still refers 'index' changed at (4)

The root cause of this issue is that there is no examination about
validity of filtered changelog cache against current unfiltered one.

This patch discards filtered changelog cache, if its 'index' object
isn't shared with unfiltered one.

BTW, at the time of this patch, redundant truncation of
'00changelog.i' at failure of transaction (see b7829fc79508 for
detail) often prevents "hg serve" from making already rollbacked
revisions visible, because updating timestamps of '00changelog.i' by
truncation makes "hg serve" discard old repoview object with invalid
filtered changelog cache.

This is reason why this issue is overlooked before this patch, even
though test-bundle2-exchange.t has tests in similar situation: failure
of "hg push" via HTTP by pretxnclose hook on server side doesn't
prevent subsequent commands from looking up outgoing revisions
correctly.

But timestamp on the filesystem doesn't have enough resolution for
recent computation power, and it can't be assumed that this avoidance
always works as expected.

Therefore, without this patch, this issue might appear occasionally.
2016-02-24 06:10:46 +09:00
Matt Harbison
0ad55d4a9e test-commandserver: generate files with a fixed EOL for test stability
The hashes were different on Windows.
2015-10-01 21:49:50 -04:00
Yuya Nishihara
902720a104 localrepo: recreate phasecache if changelog was modified (issue4855)
Because _phaserevs and _phasesets cache revision numbers, they must be
invalidated if there are new commits or stripped revisions. We could do
that by calling _phasecache.invalidate(), but it wasn't simple to be
integrated with the filecache mechanism.

So for now, phasecache will be recreated after repo.invalidate() if
00changelog.i was modified before.
2015-09-29 21:57:08 +09:00
Jordi Gutiérrez Hermoso
cce05f8f6d phases: return zero for no-op operations (issue4751) (BC)
It is rather unhelpful to return 1 if there were no changes because
the request matches the current state of phases. So we just undo that.
2015-09-14 19:25:34 -04:00
Yuya Nishihara
a3529f51c1 localrepo: refresh filecache stats only if transaction finished successfully
If commit is aborted by pretxncommit hook, in-memory changelog and manifest
have entries that would be added. So they must be discarded on invalidate().

But the mechanism introduced by 071f71da2fe2 doesn't handle this case well.
It tries to mitigate the penalty of invalidate() by marking in-memory cache
as "clean" on unlock assuming that they are identical to the stored data.
But this assumption is wrong if stored data are rolled back by tr.abort().

This patch moves the hook to post-close action so that it will never be
triggered on abort.

This bug was originally reported to thg, which is only reproducible in
command-server process on unix, evolve disabled.

https://bitbucket.org/tortoisehg/thg/issues/4285/
2015-09-15 00:32:39 +09:00
Yuya Nishihara
69537fb219 dispatch: error out on invalid -R path even if optionalrepo (issue4805) (BC)
Before this patch, repo could be set to None for wrong -R. It's okay for
commands that can reject repo=None, but the command server have a problem
because:

 - it accepts repo=None for "unbound" mode
 - and it reenters dispatch() where repo object is created for cwd by default

Test outputs are changed because the error is detected earlier. I think new
message is better than ".hg not found".
2015-08-31 23:29:15 +09:00
Pierre-Yves David
b1a2babd78 devel: rename 'all' to 'all-warnings' (BC)
We have started to isolate extra usecases for developer-only output
that is not a warning. As the section has the fairly generic name
'devel' it makes sense to tuck them there. As a result, 'all' becomes
a bit misleading so we rename it to 'all-warnings'. This will break
some developer setups but the tests are still fine and developers will
likely spot this change.
2015-05-26 14:14:36 -07:00
Pierre-Yves David
93e144e4f3 run-test: enable the devel warning during tests
This should help us to catch new locking order issues as soon as possible.

There are two harmless test updates (from the config change). Moreover, some
bundle2 tests are displaying warning for a legitimate reason. The use of pushkey
during the unbundle process may requires the 'wlock' after 'lock' (around the
whole unbundle process was taken). This is non-trivial to fix, so I better have
the check on, with the warning in the test than the check off. See issue4596 for
details.
2015-04-12 09:46:03 -04:00
Matt Mackall
4abfc94f18 merge with stable 2014-11-27 12:25:01 -06:00
anatoly techtonik
6abd5e7bc0 merge: be precise about what merged into what in short desc 2014-11-26 17:22:09 +03:00
Matt Harbison
889536b207 run-tests: set a default largefiles usercache in the default hgrc file
This fixes a test failure introduced in 131ac757f996 on Windows and OS X, where
the cached largefile wasn't being deleted because the named .cache directory
didn't exist.  It only existed on Linux because the test suite sets $HOME to the
directory of the test being run, and Linux uses $HOME/.cache by default.

Most of the other largefiles tests explicitly set this value at the top of their
scripts, but test-largefiles-update.t didn't pick that up when it was created.
Those scripts that do set a value will override this.

We could just set the parameter in the test-largefiles-update.t script, but
there are a few other non obvious tests that exercise largefiles too.  These
largefiles end up being cached in the user's real cache, so proper hygiene
dictates that this not be left to each individual test script.
2014-11-19 23:41:40 -05:00
Yuya Nishihara
1c7ce2bd17 cmdserver: protect pipe server streams against corruption caused by direct io
Because pipe-mode server uses stdio as IPC channel, other modules should not
touch stdio directly and use ui instead.  However, this strategy is brittle
because several Python functions read and write stdio implicitly.

    print 'hello'  # should use ui.write()
    # => ch = 'h', size = 1701604463 'ello', data = '\n'

This patch adds protection for such mistakes.  Both stdio files and low-level
file descriptors are redirected to /dev/null while command server uses them.
2014-11-15 13:50:43 +09:00
Yuya Nishihara
0c88d9a994 cmdserver: use given streams as pipe channels like other commands
Because commandserver itself is an hg subcommand, it shouldn't use stdio
directly in principle.
2014-11-15 12:43:35 +09:00
Matt Mackall
ff003a7261 tests: don't try to test unix sockets on vfat 2014-10-27 16:39:57 -05:00
Yuya Nishihara
df336dc3c8 ui: separate option to show prompt echo, enabled only in tests (issue4417)
The problem in commandserver was addressed by 766cfbe766dc, but it is tricky
to reuse ui.nontty option to disable echo back.  Instead, this patch introduces
new option to enable echoing of prompt response.

Prompt echoing is changed to be off by default, which should avoid possible
breakage of output parsing in user scripts.

For now, this option is undocumented because it exists for internal use.
2014-10-21 23:16:46 +09:00
Yuya Nishihara
a9b00f4522 cmdserver: include pid of server handling requests in hello message
Because unix-mode server forks child process per connection, client does not
know the pid of the server that will handle requests.  The pid is necessary
to interrupt hung process:

 1. client connects to socket server
 2. server accepts the connection, forks, and tells pid
 3. client requests "runcommand pull"
    .. hung ..
 4. client sends SIGINT to the (forked) server
 5. server returns from I/O wait

Note that getsockopt(SO_PEERCRED) of Linux cannot be used because the server
fork()s after accept().
2014-10-18 12:24:50 +09:00
Yuya Nishihara
0baf7a676d cmdserver: add service that listens on unix domain socket and forks process
Typical use case of 'unix' mode is a background hg daemon.

    $ hg serve --cmdserver unix --cwd / -a /tmp/hg-`id -u`.sock

Unlike 'pipe' mode in which parent process keeps stdio channel, 'unix' server
can be detached.  So clients can freely connect and disconnect from server,
saving Python start-up time.

It might be better to write "--cmdserver socket -a unix:/sockpath" instead
of "--cmdserver unix -a /sockpath" in case hgweb gets the ability to listen
on unix domain socket.
2014-10-04 16:46:50 +09:00
Durham Goode
312ed291dd obsolete: update tests to use obsolete options
The obsolete._enabled flag has become a config option. This updates all but one
of the tests to use the minimal number of flags necessary for them to pass.  For
most tests this is just 'createmarkers', for a couple tests it's
'allowunstable', and for even fewer it's 'exchange'.
2014-10-14 13:34:25 -07:00
Yuya Nishihara
2f53d7a8aa ui: disable echo back of prompt input if ui is set to non-tty purposely
d735f8a82023 is nice for test output, but it also affects command-server
channel.  Command-server client shouldn't receive echo-back message, which
makes it harder to parse the output.
2014-10-08 20:51:01 +09:00
Yuya Nishihara
03d7086901 test-commandserver: make runcommand message bolder
It seems ' runcommand' is difficult to distinguish from command output.
'*** runcommand' is slightly better.
2014-09-28 17:21:38 +09:00
Yuya Nishihara
a55d222f7b test-commandserver: rewrite manual substitution of output by (glob) match 2014-09-28 14:46:57 +09:00
Yuya Nishihara
095547c625 test-commandserver: remove redundant banner output
Since test output was inlined, "testing <func>" message should no longer
be necessary.
2014-09-28 16:59:30 +09:00
Yuya Nishihara
60e5066f88 test-commandserver: port test functions from .py to .t
Though we have to duplicate import statements, .t test is still more handy
than .py test which has cryptic .out file.

This change allows to skip a part of test by #if conditional, which my next
patch series depends on.
2014-09-28 16:05:37 +09:00
Yuya Nishihara
bd1f3e4e18 test-commandserver: add stub for .t test by copying .out with 2-space indent
Currently test-commandserver.t only contains output, so it is skipped by
#require false.
2014-09-28 14:27:40 +09:00