Repository navigation
[Server] Fix a double setUp in tests, and fail CI on etc/conf writes #2167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
18b5136
fa94fe3
ec2fbec
cfd9aa0
da3f27f
8f423ce
6933dbc
f9133a9
4a2287c
30de299
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/usr/bin/env bash | ||
| # Fails if any etc/conf directory differs from the checkout: a new file (ignored or not), or an | ||
| # edited or deleted tracked one. Run in CI after the tests: a server built without its own | ||
| # configurationFolder writes its signing keys and token.txt into etc/conf. | ||
| set -euo pipefail | ||
|
|
||
| changed=$(git status --porcelain --ignored --untracked-files=all -- ':(glob)**/etc/conf/**') | ||
| if [ -n "$changed" ]; then | ||
|
Comment on lines
+7
to
+8
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think missing tests - but its not necessary if we dont need |
||
| echo "::error::Tests changed etc/conf; give each test server its own configurationFolder:" | ||
| echo "$changed" | ||
| exit 1 | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env python3 | ||
| """Check project/scripts/check_etc_conf.sh against a throwaway git repository.""" | ||
|
|
||
| import os | ||
| import subprocess | ||
| import tempfile | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| UC_ROOT = Path(__file__).resolve().parents[2] | ||
| SCRIPT = UC_ROOT / "project" / "scripts" / "check_etc_conf.sh" | ||
| # Ignore the developer's global and system git configuration (excludes, signing, hooks), so only | ||
| # the throwaway repository's own rules apply. | ||
| GIT_ENV = {**os.environ, "GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_NOSYSTEM": "1"} | ||
|
|
||
|
|
||
| def git(repo: Path, *args: str) -> None: | ||
| subprocess.run(["git", "-c", "user.name=test", "-c", "[email protected]", *args], | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this temp repo still picks up the developer's global git config, so global ignore rules, commit signing, or hooks can make the test fail even when the script is fine. could we isolate git with +GIT_ENV = {
+ **os.environ,
+ "GIT_CONFIG_GLOBAL": os.devnull,
+ "GIT_CONFIG_NOSYSTEM": "1",
+} |
||
| cwd=repo, env=GIT_ENV, check=True, capture_output=True) | ||
|
|
||
|
|
||
| def check(repo: Path) -> subprocess.CompletedProcess: | ||
| return subprocess.run(["bash", str(SCRIPT)], cwd=repo, env=GIT_ENV, capture_output=True, | ||
| text=True) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| with tempfile.TemporaryDirectory() as tmp: | ||
| repo = Path(tmp) | ||
| git(repo, "init", "-q") | ||
| (repo / "etc" / "conf").mkdir(parents=True) | ||
| (repo / "etc" / "conf" / "server.properties").write_text("server.env=dev\n") | ||
| # Like the real .gitignore: the generated files are ignored in etc/conf. | ||
| (repo / ".gitignore").write_text("etc/conf/*.txt\nother/*.txt\n") | ||
| git(repo, "add", ".") | ||
| git(repo, "commit", "-q", "-m", "init") | ||
| # Untracked and ignored files outside etc/conf are none of the script's business, so they | ||
| # stay for the whole test: every passing check below also pins that. | ||
| (repo / "other").mkdir() | ||
| (repo / "other" / "new.json").write_text("x") | ||
| (repo / "other" / "x.txt").write_text("x") | ||
|
|
||
| result = check(repo) | ||
| assert result.returncode == 0, f"a clean tree must pass:\n{result.stdout}{result.stderr}" | ||
|
|
||
| # Each case must fail and name the file: ignored, unignored in a module, hidden, edited. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit (not a blocker): Dropping the etc/conf pathspec would not fail any test Every dirty path in the test sits under an For example: An untracked Before the first clean-tree check, create an untracked file and a gitignored file outside EvidenceHow it was checkedChecked by 2 independent checks: CONFIRMED How about adding that passing case so the pathspec scope is pinned? |
||
| cases = { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit (not a blocker): Deleted tracked file case is not covered The header of check_etc_conf.sh says it fails on an edited or deleted tracked file, but the cases dict covers ignored, untracked, hidden and edited files only. The script fails on any non-empty porcelain output, so a deletion is caught today. A later change to the status filtering that dropped ' D' lines would still pass this test. For example: Deleting etc/conf/server.properties and running the script should exit 1 and list ' D etc/conf/server.properties'. No case checks that. Would you like to add the deletion case so the header's promise is tested?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit (not a blocker): Test misses files nested below etc/conf All cases in For example: Write EvidenceHow it was checkedChecked by 2 independent checks: CONFIRMED Could we add this row to |
||
| "etc/conf/token.txt": "!! etc/conf/token.txt", | ||
| "etc/conf/keys/private_key.der": "?? etc/conf/keys/private_key.der", | ||
| "examples/cli/etc/conf/certs.json": "?? examples/cli/etc/conf/certs.json", | ||
| "etc/conf/.hidden": "?? etc/conf/.hidden", | ||
| "etc/conf/server.properties": " M etc/conf/server.properties", | ||
| } | ||
| for path, expected in cases.items(): | ||
| file = repo / path | ||
| original = file.read_text() if file.exists() else None | ||
| file.parent.mkdir(parents=True, exist_ok=True) | ||
| file.write_text("written by a test\n") | ||
| result = check(repo) | ||
| assert result.returncode == 1 and expected in result.stdout, ( | ||
| f"{path}: expected a failure listing {expected!r}, got exit {result.returncode}:\n" | ||
| f"{result.stdout}{result.stderr}") | ||
| if original is None: | ||
| file.unlink() | ||
| if file.parent != repo / "etc" / "conf" and not any(file.parent.iterdir()): | ||
| file.parent.rmdir() | ||
| else: | ||
| file.write_text(original) | ||
|
|
||
| tracked = repo / "etc" / "conf" / "server.properties" | ||
| tracked.unlink() | ||
| result = check(repo) | ||
| assert result.returncode == 1 and " D etc/conf/server.properties" in result.stdout, ( | ||
| f"a deleted tracked file must fail:\n{result.stdout}{result.stderr}") | ||
| git(repo, "checkout", "--", "etc/conf/server.properties") | ||
|
|
||
| result = check(repo) | ||
| assert result.returncode == 0, f"the restored tree must pass:\n{result.stdout}" | ||
| print("PASS: check_etc_conf.sh fails on new, ignored, hidden, edited and deleted files in any " | ||
| "etc/conf") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,29 @@ def check_cgroup_memory(run_tests) -> None: | |
| assert left == 6 * gib, f"expected 6 GiB left under the parent's limit, got {left}" | ||
|
|
||
|
|
||
| def check_conf_stamps(run_tests) -> None: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit (not a blocker): Depth limit of conf_stamps() is not pinned by a test
For example: Put Add EvidenceHow it was checkedChecked by 2 independent checks: CONFIRMED Would you like to add the depth fixture, and is the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [AI Assisted] Added the depth fixture in 30de299:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, and the depth part is settled. I ran I also checked your second point. The added/deleted/edited comparison is still inline in |
||
| # etc/conf at the root and in modules one and two levels deep, with a hidden file and a file | ||
| # in a subdirectory. | ||
| files = ["etc/conf/a.properties", "etc/conf/keys/private_key.der", "server/etc/conf/.hidden", | ||
| "connectors/spark/etc/conf/b.json"] | ||
| saved = run_tests.ROOT | ||
| with tempfile.TemporaryDirectory() as root: | ||
| # Three levels deep is past the limit, so this one must not be watched. | ||
| for name in files + ["a/b/c/etc/conf/deep.json"]: | ||
| (Path(root) / name).parent.mkdir(parents=True, exist_ok=True) | ||
| (Path(root) / name).write_text("x") | ||
| run_tests.ROOT = root | ||
| try: | ||
| before = run_tests.conf_stamps() | ||
| # An edited file must change its stamp, or the warning would never fire for it. | ||
| os.utime(Path(root) / files[2], (1, 1)) | ||
| after = run_tests.conf_stamps() | ||
| finally: | ||
| run_tests.ROOT = saved | ||
| assert sorted(before) == sorted(files), f"conf_stamps() watched {sorted(before)}" | ||
| assert before[files[2]] != after[files[2]], f"editing {files[2]} did not change its stamp" | ||
|
|
||
|
|
||
| def check_concurrency_limit() -> None: | ||
| command = [str(UC_ROOT / "build" / "sbt"), "-no-colors", "-batch", | ||
| "show Global / concurrentRestrictions"] | ||
|
|
@@ -163,6 +186,7 @@ def main() -> None: | |
| check_sbt_errors_shown(run_tests) | ||
| check_durations_file(run_tests) | ||
| check_cgroup_memory(run_tests) | ||
| check_conf_stamps(run_tests) | ||
| check_concurrency_limit() | ||
| check_parallel_run() | ||
| print("PASS: dev/run-tests.py validates its arguments and runs client/test in 2 test JVMs") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| package io.unitycatalog.server.base; | ||
|
|
||
| import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; | ||
|
|
||
| import com.linecorp.armeria.server.ServerPortBindException; | ||
| import io.unitycatalog.server.UnityCatalogServer; | ||
| import io.unitycatalog.server.persist.utils.FileOperations; | ||
|
|
@@ -114,6 +112,11 @@ protected FileOperations decorateFileOperations(FileOperations fileOperations) { | |
| @SneakyThrows | ||
| @BeforeEach | ||
| public void setUp() { | ||
| if (unityCatalogServer != null) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the new setup guard lacks a rejection test |
||
| throw new IllegalStateException( | ||
| "setUp() ran twice in one test, starting a second server: override setUp() instead of " | ||
| + "calling it from another @BeforeEach method"); | ||
| } | ||
| if (serverConfig == null) { | ||
| throw new IllegalArgumentException("Server config is required"); | ||
| } | ||
|
|
@@ -150,11 +153,9 @@ private static synchronized void copySigningKeys(Path target) throws IOException | |
| } | ||
| signingKeysFolder = folder; | ||
| } | ||
| // Replace: setUp() runs twice in one test when a subclass declares another @BeforeEach method | ||
| // that calls super.setUp(), instead of overriding setUp(). | ||
| try (Stream<Path> keys = Files.list(signingKeysFolder)) { | ||
| for (Path key : keys.toList()) { | ||
| Files.copy(key, target.resolve(key.getFileName()), REPLACE_EXISTING); | ||
| Files.copy(key, target.resolve(key.getFileName())); | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit (not a blocker): conf_stamps() depth and hidden-file handling has no test
conf_stamps() now globs etc/conf at depth 0, 1 and 2, keys results by relative path, uses listdir so hidden files count, and skips non-files. Nothing under project/tests exercises it; the new test only covers check_etc_conf.sh. This is a coverage gap, not a behavior bug: the current code handles all three depths.
For example: Changing range(3) to range(2) would stop watching connectors/spark/etc/conf, and the warning in main() would never fire for it, yet every CI check would still pass.
Add a case to the existing project/tests/test_run_tests.py that builds a temporary tree with an etc/conf at depth 0, 1 and 2 (one holding a hidden file) and asserts that conf_stamps() returns the relative path of each file. That keeps it in the current test file instead of adding a new one.
How about adding a small tree-based case to test_run_tests.py so a depth regression gets caught?