forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
streaming_workunit_handler_integration_test.py
67 lines (51 loc) · 2.08 KB
/
streaming_workunit_handler_integration_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import annotations
import os
import signal
from typing import List, Mapping, Tuple
from workunit_logger.register import FINISHED_SUCCESSFULLY
from pants.testutil.pants_integration_test import (
PantsResult,
run_pants,
setup_tmpdir,
temporary_workdir,
)
from pants.util.dirutil import maybe_read_file
from pants_test.pantsd.pantsd_integration_test_base import attempts, launch_waiter
def workunit_logger_config(log_dest: str) -> Mapping:
return {
"GLOBAL": {
"backend_packages.add": ["workunit_logger", "pants.backend.python"],
},
"workunit-logger": {"dest": log_dest},
}
def run(args: List[str], success: bool = True) -> Tuple[PantsResult, str | None]:
with setup_tmpdir({}) as tmpdir:
dest = os.path.join(tmpdir, "dest.log")
pants_run = run_pants(args, config=workunit_logger_config(dest))
log_content = maybe_read_file(dest)
if success:
pants_run.assert_success()
assert log_content
assert FINISHED_SUCCESSFULLY in log_content
else:
pants_run.assert_failure()
return pants_run, log_content
def test_list() -> None:
run(["list", "3rdparty::"])
def test_help() -> None:
run(["help"])
run(["--version"])
def test_ctrl_c() -> None:
with temporary_workdir() as workdir:
dest = os.path.join(workdir, "dest.log")
# Start a pantsd run that will wait forever, then kill the pantsd client.
client_handle, _, _ = launch_waiter(workdir=workdir, config=workunit_logger_config(dest))
client_pid = client_handle.process.pid
os.kill(client_pid, signal.SIGINT)
# Confirm that finish is still called (even though it may be backgrounded in the server).
for _ in attempts("The log should eventually show that the SWH shut down."):
content = maybe_read_file(dest)
if content and FINISHED_SUCCESSFULLY in content:
break