Answer principles round 2: 0 🔴, 1 🟡 (0 misread); remove ci.sh's container when a patch cut stops it, show task-bench's count defaults where they apply, and take ci.sh's bound from the forge's wait
CI / tests (pull_request) Successful in 4m47s
CI / tests (pull_request) Successful in 4m47s
This commit is contained in:
@@ -734,6 +734,8 @@ class PatchCi(unittest.TestCase):
|
||||
self.addCleanup(subprocess.run, ["rm", "-rf", str(self.worktree)])
|
||||
self.log = self.worktree / "ci.log"
|
||||
self.said: list[str] = []
|
||||
self.removed: list[str] = []
|
||||
self.remove = lambda container: self.removed.append(container)
|
||||
|
||||
def test_passes_where_ci_sh_exits_zero(self):
|
||||
(self.worktree / "ci.sh").write_text("exit 0\n")
|
||||
@@ -759,7 +761,7 @@ class PatchCi(unittest.TestCase):
|
||||
|
||||
def test_the_runner_writes_ci_shs_output_to_the_log_as_it_runs_and_gives_its_exit_code(self):
|
||||
(self.worktree / "ci.sh").write_text("echo out\necho err >&2\nexit 3\n")
|
||||
ran = ci_script.ci_runner(self.log, 30, self.said.append)(self.worktree)
|
||||
ran = ci_script.ci_runner(self.log, 30, self.said.append, "ci-of-a-test", self.remove)(self.worktree)
|
||||
self.assertEqual(ran, patch.CiRan(3, "out\nerr\n"))
|
||||
self.assertEqual(self.log.read_text(), "out\nerr\n")
|
||||
self.assertEqual(self.said, [f"ci.sh's output goes to {self.log}; it is stopped where it still runs after 30 seconds"])
|
||||
@@ -767,7 +769,7 @@ class PatchCi(unittest.TestCase):
|
||||
def test_the_runner_stops_a_ci_sh_that_hangs_with_what_it_started_and_says_so(self):
|
||||
(self.worktree / "ci.sh").write_text("echo started\nsleep 60 &\necho $! >child.pid\nwait\n")
|
||||
began = time.monotonic()
|
||||
ran = ci_script.ci_runner(self.log, 0.5, self.said.append, grace=0.2)(self.worktree)
|
||||
ran = ci_script.ci_runner(self.log, 0.5, self.said.append, "ci-of-a-test", self.remove, grace=0.2)(self.worktree)
|
||||
self.assertLess(time.monotonic() - began, 20)
|
||||
self.assertEqual(ran, Failure(f"ci.sh still ran after 0.5 seconds and was stopped; {self.log} holds its output"))
|
||||
self.assertEqual(self.log.read_text(), "started\n")
|
||||
@@ -777,15 +779,49 @@ class PatchCi(unittest.TestCase):
|
||||
time.sleep(0.05)
|
||||
self.assertFalse(still_runs(child), "the process ci.sh started still runs")
|
||||
|
||||
def test_the_runner_names_ci_shs_container_and_removes_it_where_it_stops_ci_sh(self):
|
||||
(self.worktree / "ci.sh").write_text('echo "$CI_CONTAINER"\nsleep 60\n')
|
||||
ran = ci_script.ci_runner(self.log, 0.5, self.said.append, "ci-of-a-test", self.remove, grace=0.2)(self.worktree)
|
||||
self.assertEqual(ran, Failure(f"ci.sh still ran after 0.5 seconds and was stopped; {self.log} holds its output"))
|
||||
self.assertEqual(self.log.read_text(), "ci-of-a-test\n")
|
||||
self.assertEqual(self.removed, ["ci-of-a-test"])
|
||||
|
||||
def test_the_runner_says_where_the_container_of_a_stopped_ci_sh_may_still_run(self):
|
||||
(self.worktree / "ci.sh").write_text("sleep 60\n")
|
||||
ran = ci_script.ci_runner(self.log, 0.5, self.said.append, "ci-of-a-test", lambda container: Failure("docker rm --force ci-of-a-test failed: no daemon"), grace=0.2)(self.worktree)
|
||||
self.assertEqual(ran, Failure(f"ci.sh still ran after 0.5 seconds and was stopped, but its container ci-of-a-test may still run: docker rm --force ci-of-a-test failed: no daemon; {self.log} holds its output"))
|
||||
|
||||
def test_the_runner_removes_no_container_where_ci_sh_ends_in_time(self):
|
||||
(self.worktree / "ci.sh").write_text("exit 0\n")
|
||||
ci_script.ci_runner(self.log, 30, self.said.append, "ci-of-a-test", self.remove)(self.worktree)
|
||||
self.assertEqual(self.removed, [])
|
||||
|
||||
def test_removing_a_container_gives_a_failure_where_docker_fails_and_none_where_it_removes(self):
|
||||
asked: list[list[str]] = []
|
||||
def docker(code: int, stderr: str):
|
||||
return lambda argv, **options: asked.append(argv) or subprocess.CompletedProcess(argv, code, "", stderr)
|
||||
self.assertIsNone(ci_script.removed_container("ci-of-a-test", docker(0, "")))
|
||||
self.assertEqual(asked, [["docker", "rm", "--force", "ci-of-a-test"]])
|
||||
self.assertEqual(ci_script.removed_container("ci-of-a-test", docker(1, "Cannot connect to the Docker daemon\n")), Failure("docker rm --force ci-of-a-test failed: Cannot connect to the Docker daemon"))
|
||||
|
||||
def test_removing_a_container_gives_a_failure_where_docker_cannot_start(self):
|
||||
def no_docker(argv, **options):
|
||||
raise FileNotFoundError("docker")
|
||||
self.assertEqual(ci_script.removed_container("ci-of-a-test", no_docker), Failure("docker rm --force ci-of-a-test failed: docker"))
|
||||
|
||||
def test_ci_sh_names_its_container_only_where_it_is_given_a_name(self):
|
||||
script = (pathlib.Path(__file__).resolve().parents[2] / "ci.sh").read_text()
|
||||
self.assertIn('${CI_CONTAINER:+--name "$CI_CONTAINER"}', script)
|
||||
|
||||
def test_the_runner_gives_a_failure_where_ci_sh_cannot_start(self):
|
||||
ran = ci_script.ci_runner(self.log, 30, self.said.append)(self.worktree / "gone")
|
||||
ran = ci_script.ci_runner(self.log, 30, self.said.append, "ci-of-a-test", self.remove)(self.worktree / "gone")
|
||||
self.assertIsInstance(ran, Failure)
|
||||
self.assertIn("ci.sh could not run: ", ran.reason)
|
||||
self.assertIn(str(self.worktree / "gone"), ran.reason)
|
||||
|
||||
def test_the_runner_gives_a_failure_where_the_log_cannot_be_written(self):
|
||||
(self.worktree / "ci.sh").write_text("exit 0\n")
|
||||
ran = ci_script.ci_runner(self.worktree / "no-folder" / "ci.log", 30, self.said.append)(self.worktree)
|
||||
ran = ci_script.ci_runner(self.worktree / "no-folder" / "ci.log", 30, self.said.append, "ci-of-a-test", self.remove)(self.worktree)
|
||||
self.assertIsInstance(ran, Failure)
|
||||
self.assertIn(str(self.worktree / "no-folder" / "ci.log"), ran.reason)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user