Mercurial > hg
annotate mercurial/testing/ps_util.py @ 52216:fa58f4f97337 stable tip
ci: shard the test run on mac os X
This should comes with some benefit:
- spread the load across more runner,
- reduce the real-time CI run,
- reduce the "retry" run when we need them.
We start with the Mac jobs, but that would be tremendously useful for Windows
too.
For linux, we need to reduce the startup overhead for this to be worth it.
Building smaller image and speeding up clone should help with that.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 08 Nov 2024 17:08:11 +0100 |
parents | 625cf9621551 |
children |
rev | line source |
---|---|
51996
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
1 # This python code can be imported into tests in order to terminate a process |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
2 # with signal.SIGKILL on posix, or a roughly equivalent procedure on Windows. |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
3 import os |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
4 import signal |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
5 import subprocess |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
6 import sys |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
7 import tempfile |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
8 |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
9 from .. import ( |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
10 encoding, |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
11 pycompat, |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
12 ) |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
13 |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
14 from ..utils import procutil |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
15 |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
16 |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
17 def kill_nt(pid: int, exit_code: int): |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
18 fd, pidfile = tempfile.mkstemp( |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
19 prefix=b"sigkill-", dir=encoding.environ[b"HGTMP"], text=False |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
20 ) |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
21 try: |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
22 os.write(fd, b'%d\n' % pid) |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
23 finally: |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
24 os.close(fd) |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
25 |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
26 env = dict(encoding.environ) |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
27 env[b"DAEMON_EXITCODE"] = b"%d" % exit_code |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
28 |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
29 # Simulate the message written to stderr for this process on non-Windows |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
30 # platforms, for test consistency. |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
31 print("Killed!", file=sys.stderr) |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
32 |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
33 subprocess.run( |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
34 [ |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
35 encoding.environ[b"PYTHON"], |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
36 b"%s/killdaemons.py" |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
37 % encoding.environ[b'RUNTESTDIR_FORWARD_SLASH'], |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
38 pidfile, |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
39 ], |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
40 env=procutil.tonativeenv(env), |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
41 ) |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
42 |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
43 |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
44 def kill(pid: int): |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
45 """Kill the process with the given PID with SIGKILL or equivalent.""" |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
46 if pycompat.iswindows: |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
47 exit_code = 128 + 9 |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
48 kill_nt(pid, exit_code) |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
49 else: |
625cf9621551
tests: add a module that can perform the equivalent of `SIGKILL` on any OS
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff
changeset
|
50 os.kill(pid, signal.SIGKILL) |