diff --git a/scripts/tests/test_verify_remote.py b/scripts/tests/test_verify_remote.py index 9f2ecdd3..0b8e6799 100644 --- a/scripts/tests/test_verify_remote.py +++ b/scripts/tests/test_verify_remote.py @@ -10,7 +10,8 @@ RemoteLogTest의 ssh는 받은 명령을 이 머신에서 그대로 돌린다(HO repo의 clone에서 worktree를 만들고 잠금 아래에서 단계를 돌린다. 단계의 Gradle은 받은 인자를 찍는 가짜 `gradlew`다. 원격 로그의 첫 줄이 보낸 트리와 기준의 전체 해시를 적는지, 다른 프로세스가 잠금을 쥔 동안 지난 로그와 클래스 목록이 그대로인지, 기다리다 client가 끊겼거나 잠금을 얻지 못한 실행이 그것을 바꾸지 않는지, 단계와 합계가 배타 잠금 안에서 -도는지, 단계의 rc가 그대로 나가는지 본다. 잠금 대기는 Linux `/proc/locks`의 대기 줄(`->`)로 안다. +도는지, 단계의 rc가 그대로 나가는지, 단계가 stdin을 읽어도 합계·rc 줄과 그 rc로 끝나는지 본다. 잠금 대기는 Linux +`/proc/locks`의 대기 줄(`->`)로 안다. python3 -m unittest discover -s scripts/tests """ @@ -205,9 +206,10 @@ echo " 09:00:00 up 1 day, load average: 0.39, 0.40, 0.41" """ # Stands in for Gradle in the stage: prints what it was asked and whether the lock is held exclusively (only -# then does a shared try fail), and ends with the rc the test chose. +# then does a shared try fail), reads its stdin to the end if the test asks, and ends with the rc the test chose. FAKE_GRADLEW = """#!/bin/sh echo "gradle $*" +[ -z "${FAKE_STAGE_READS_STDIN:-}" ] || cat > /dev/null if flock -n -s "$FAKE_LOCK" true; then echo "stage: lock free"; else echo "stage: lock held"; fi exit "${FAKE_STAGE_RC:-0}" """ @@ -220,6 +222,13 @@ with open(sys.argv[sys.argv.index("--classes") + 1], "w", encoding="utf-8") as c classes.write("this run\\n") """ +# Stands in for run-compose-runtime-smoke.sh: reads its stdin to the end, as `docker compose exec -T` does, and +# ends with the rc the test chose. +FAKE_SMOKE = """#!/bin/sh +cat > /dev/null +exit "${FAKE_SMOKE_RC:-0}" +""" + LEAF = ":adapter:outbound:sample" RUN_LIMIT = 60 # seconds a run may take once nothing holds it back @@ -233,6 +242,8 @@ class RemoteLogTest(ThrowawayRepoTest): def setUp(self) -> None: super().setUp() self.write("scripts/junit-summary.py", FAKE_SUMMARY) + self.write("scripts/run-compose-runtime-smoke.sh", FAKE_SMOKE) + self.write("scripts/ci/verify-configuration-cache.sh", "exit 0\n") # round runs it before the smoke self.write("gradle/modules.json", f'{{"modules": [{{"gradle_path": "{LEAF}"}}]}}\n') self.write("gradlew", FAKE_GRADLEW) (self.repo / "gradlew").chmod(0o755) @@ -457,6 +468,31 @@ class RemoteLogTest(ThrowawayRepoTest): # then self.assertEqual((result.returncode, self.log().splitlines()[-1]), (3, "verify: rc=3"), result.stderr) + def assert_a_stdin_reading_stage_ends_with(self, rc: int, stage: str, **child: str) -> None: + """REV-BE-0050. The remote script is the stdin of `bash -s`: a stage that reads its stdin must not get + the lines after it (summary, rc line, exit).""" + # when + result = self.run_stage(stage, **child) + + # then + log = self.log(stage) + end = re.search(r"^summary: .*\nverify: rc=(\d+)\n\Z", log, re.MULTILINE) + self.assertEqual((result.returncode, end and end.group(1)), (rc, str(rc)), log + result.stderr) + + def test_a_smoke_that_reads_stdin_and_fails_ends_with_the_summary_and_its_rc(self) -> None: + for stage in ("nightly", "round"): # the two stages that run the smoke + with self.subTest(stage=stage): + self.assert_a_stdin_reading_stage_ends_with(3, stage, FAKE_SMOKE_RC="3") + + def test_a_smoke_that_reads_stdin_and_passes_ends_with_the_summary_and_its_rc(self) -> None: + for stage in ("nightly", "round"): + with self.subTest(stage=stage): + self.assert_a_stdin_reading_stage_ends_with(0, stage, FAKE_SMOKE_RC="0") + + def test_a_gradle_that_reads_stdin_and_fails_ends_with_the_summary_and_its_rc(self) -> None: + # pr has no smoke: an empty stdin given to the smoke alone does not pass this + self.assert_a_stdin_reading_stage_ends_with(3, "pr", FAKE_STAGE_READS_STDIN="1", FAKE_STAGE_RC="3") + if __name__ == "__main__": unittest.main() diff --git a/scripts/verify.sh b/scripts/verify.sh index 32533ab9..83fc77d3 100755 --- a/scripts/verify.sh +++ b/scripts/verify.sh @@ -183,11 +183,13 @@ fi echo "verify: 잠금을 얻었다" >&2 || exit 4 rm -f ~/$log-logs/$stage-classes.tsv # 단계가 합계 전에 끊겨도 지난 실행의 목록이 새 로그 옆에 남지 않는다 # 첫 줄은 이 로그가 어느 트리·기준의 실행인지, 둘째 줄은 단계 직전 부하다. +# 이 스크립트가 bash -s의 stdin이다. 단계 안 프로세스(docker compose exec -T 등)가 읽으면 아래 합계·rc·exit 줄을 먹고 +# bash가 tee의 rc 0으로 끝나므로 단계에는 빈 stdin을 준다(REV-BE-0050). { echo "verify: tree $tree base $base $stage${target:+ $target} \$(date '+%Y-%m-%dT%H:%M:%S%z')" echo "verify: \$(uptime)" VERIFY_LOCKED=1 ./scripts/verify.sh $stage $target --on here ${NO_CACHE[*]} -} 2>&1 | tee ~/$log-logs/$stage.log +} &1 | tee ~/$log-logs/$stage.log rc=\${PIPESTATUS[0]} # 새 worktree라 여기 있는 JUnit XML은 모두 이번 실행의 것이다. worktree를 지우면 XML도 사라지므로 그 전에 합계를 # 로그에 쓰고, lane(태스크)별로 돈 클래스 목록을 로그 폴더에 남긴다(docs/work/reference/gates.md 4절).