[Bug 6941] New: hg serve option to invoke command with address in environment and terminate when it exits
mercurial-bugs at mercurial-scm.org
mercurial-bugs at mercurial-scm.org
Tue Dec 3 21:03:11 UTC 2024
https://bz.mercurial-scm.org/show_bug.cgi?id=6941
Bug ID: 6941
Summary: hg serve option to invoke command with address in
environment and terminate when it exits
Product: Mercurial
Version: 6.8.1
Hardware: PC
OS: NetBSD
Status: UNCONFIRMED
Severity: feature
Priority: wish
Component: Mercurial
Assignee: bugzilla at mercurial-scm.org
Reporter: mercurial-bugzilla at campbell.mumble.net
CC: mercurial-devel at mercurial-scm.org
Python Version: ---
It would be nice, especially while writing automatic tests, if you could do
something like this:
$ hg serve -- sh -c 'curl http://$HGSERVER/?cmd=capabilities'
And what hg would do is:
1. Start a server on an arbitrary local socket address, with a port number not
in use reliably chosen by the OS, say 127.0.0.1:57421.
2. Run the command
sh -c 'curl http://$HGSERVER/?cmd=capabilities'
as a subprocess with the environment variable HGSERVER set to the socket
address `127.0.0.1:57421' (or, if IPv6, `[::1]:57421'), or maybe a URL instead
of socket address.
3. Terminate when the subprocess exits.
Alternatives I considered:
- I could run `hg serve -p 0 --daemon' in the background and handle a pidfile,
but if, e.g., the hg process crashes, the pid may be recycled, so I might end
up killing an unrelated process.
- I could use another process supervisor to run `hg serve -p 0 --print-url' and
capture the output, but I don't know of a convenient process supervisor that
(a) can be used in cram-type tests for this purpose, (b) provides a handy way
to capture the output for subsequent shell commands. (I could write one, or
find a way to incorporate it into cram, but that's a lot of additional work.)
- I could use a fixed port number like 8000 to obviate the need for capturing
the output of `--print-url', but this interferes with running multiple tests in
parallel.
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the Mercurial-devel
mailing list