Skip to content

Commit e0cde22

Browse files
committed
added and passed test_postgres_build
1 parent c430a90 commit e0cde22

File tree

9 files changed

+100
-62
lines changed

9 files changed

+100
-62
lines changed

benchmark/tests/integtest_benchmark.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
)
2121

2222

23-
class TestBenchmark(unittest.TestCase):
23+
class BenchmarkTests(unittest.TestCase):
2424
DBGYM_CONFIG_PATH = Path("benchmark/tests/benchmark_integtest_dbgym_config.yaml")
2525

2626
def setUp(self) -> None:
27-
workspace_path = get_workspace_path_from_config(TestBenchmark.DBGYM_CONFIG_PATH)
27+
workspace_path = get_workspace_path_from_config(
28+
BenchmarkTests.DBGYM_CONFIG_PATH
29+
)
2830
# Get a clean start each time.
2931
if workspace_path.exists():
3032
shutil.rmtree(workspace_path)
File renamed without changes.

dbms/postgres/cli.py

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"""
44

55
import logging
6-
import os
76
import shutil
87
import subprocess
98
from pathlib import Path
109
from typing import Optional
1110

1211
import click
1312
import sqlalchemy
13+
from gymlib.symlinks_paths import get_pgbin_symlink_path, get_repo_symlink_path
1414

1515
from benchmark.constants import DEFAULT_SCALE_FACTOR
1616
from benchmark.job.load_info import JobLoadInfo
@@ -35,7 +35,6 @@
3535
fully_resolve_path,
3636
get_dbdata_tgz_filename,
3737
get_default_dbdata_parent_dpath,
38-
get_default_pgbin_path,
3938
is_fully_resolved,
4039
is_ssd,
4140
link_result,
@@ -61,7 +60,38 @@ def postgres_group(dbgym_workspace: DBGymWorkspace) -> None:
6160
help="Include this flag to rebuild Postgres even if it already exists.",
6261
)
6362
def postgres_build(dbgym_workspace: DBGymWorkspace, rebuild: bool) -> None:
64-
_build_repo(dbgym_workspace, rebuild)
63+
_postgres_build(dbgym_workspace, rebuild)
64+
65+
66+
def _postgres_build(dbgym_workspace: DBGymWorkspace, rebuild: bool) -> None:
67+
"""
68+
This function exists as a hook for integration tests.
69+
"""
70+
expected_repo_symlink_dpath = get_repo_symlink_path(
71+
dbgym_workspace.dbgym_workspace_path
72+
)
73+
if not rebuild and expected_repo_symlink_dpath.exists():
74+
logging.getLogger(DBGYM_LOGGER_NAME).info(
75+
f"Skipping _postgres_build: {expected_repo_symlink_dpath}"
76+
)
77+
return
78+
79+
logging.getLogger(DBGYM_LOGGER_NAME).info(
80+
f"Setting up repo in {expected_repo_symlink_dpath}"
81+
)
82+
repo_real_dpath = dbgym_workspace.dbgym_this_run_path / "repo"
83+
repo_real_dpath.mkdir(parents=False, exist_ok=False)
84+
subprocess_run(
85+
f"./_build_repo.sh {repo_real_dpath}",
86+
cwd=dbgym_workspace.base_dbgym_repo_dpath / "dbms" / "postgres",
87+
)
88+
89+
# only link at the end so that the link only ever points to a complete repo
90+
repo_symlink_dpath = dbgym_workspace.link_result(repo_real_dpath)
91+
assert expected_repo_symlink_dpath.samefile(repo_symlink_dpath)
92+
logging.getLogger(DBGYM_LOGGER_NAME).info(
93+
f"Set up repo in {expected_repo_symlink_dpath}"
94+
)
6595

6696

6797
@postgres_group.command(
@@ -75,7 +105,7 @@ def postgres_build(dbgym_workspace: DBGymWorkspace, rebuild: bool) -> None:
75105
"--pgbin-path",
76106
type=Path,
77107
default=None,
78-
help=f"The path to the bin containing Postgres executables. The default is {get_default_pgbin_path(WORKSPACE_PATH_PLACEHOLDER)}.",
108+
help=f"The path to the bin containing Postgres executables. The default is {get_pgbin_symlink_path(WORKSPACE_PATH_PLACEHOLDER)}.",
79109
)
80110
@click.option(
81111
"--intended-dbdata-hardware",
@@ -99,7 +129,7 @@ def postgres_dbdata(
99129
) -> None:
100130
# Set args to defaults programmatically (do this before doing anything else in the function)
101131
if pgbin_path is None:
102-
pgbin_path = get_default_pgbin_path(dbgym_workspace.dbgym_workspace_path)
132+
pgbin_path = get_pgbin_symlink_path(dbgym_workspace.dbgym_workspace_path)
103133
if dbdata_parent_dpath is None:
104134
dbdata_parent_dpath = get_default_dbdata_parent_dpath(
105135
dbgym_workspace.dbgym_workspace_path
@@ -127,40 +157,6 @@ def postgres_dbdata(
127157
)
128158

129159

130-
def _get_pgbin_symlink_path(dbgym_workspace: DBGymWorkspace) -> Path:
131-
return dbgym_workspace.cur_symlinks_build_path(
132-
"repo.link", "boot", "build", "postgres", "bin"
133-
)
134-
135-
136-
def _get_repo_symlink_path(dbgym_workspace: DBGymWorkspace) -> Path:
137-
return dbgym_workspace.cur_symlinks_build_path("repo.link")
138-
139-
140-
def _build_repo(dbgym_workspace: DBGymWorkspace, rebuild: bool) -> None:
141-
expected_repo_symlink_dpath = _get_repo_symlink_path(dbgym_workspace)
142-
if not rebuild and expected_repo_symlink_dpath.exists():
143-
logging.getLogger(DBGYM_LOGGER_NAME).info(
144-
f"Skipping _build_repo: {expected_repo_symlink_dpath}"
145-
)
146-
return
147-
148-
logging.getLogger(DBGYM_LOGGER_NAME).info(
149-
f"Setting up repo in {expected_repo_symlink_dpath}"
150-
)
151-
repo_real_dpath = dbgym_workspace.cur_task_runs_build_path("repo", mkdir=True)
152-
subprocess_run(
153-
f"./build_repo.sh {repo_real_dpath}", cwd=dbgym_workspace.cur_source_path()
154-
)
155-
156-
# only link at the end so that the link only ever points to a complete repo
157-
repo_symlink_dpath = link_result(dbgym_workspace, repo_real_dpath)
158-
assert expected_repo_symlink_dpath.samefile(repo_symlink_dpath)
159-
logging.getLogger(DBGYM_LOGGER_NAME).info(
160-
f"Set up repo in {expected_repo_symlink_dpath}"
161-
)
162-
163-
164160
def _create_dbdata(
165161
dbgym_workspace: DBGymWorkspace,
166162
benchmark_name: str,
@@ -216,7 +212,9 @@ def _create_dbdata(
216212

217213
def _generic_dbdata_setup(dbgym_workspace: DBGymWorkspace) -> None:
218214
# get necessary vars
219-
pgbin_real_dpath = _get_pgbin_symlink_path(dbgym_workspace).resolve()
215+
pgbin_real_dpath = get_pgbin_symlink_path(
216+
dbgym_workspace.dbgym_workspace_path
217+
).resolve()
220218
assert pgbin_real_dpath.exists()
221219
dbgym_pguser = DBGYM_POSTGRES_USER
222220
dbgym_pgpass = DBGYM_POSTGRES_PASS

dbms/tests/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dbgym_workspace_path: ../dbgym_dbms_integtest_workspace/

dbms/tests/integtest_dbms.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import shutil
2+
import unittest
3+
from pathlib import Path
4+
5+
from gymlib.symlinks_paths import get_repo_symlink_path
6+
7+
from dbms.postgres.cli import _postgres_build
8+
from util.workspace import (
9+
DBGymWorkspace,
10+
fully_resolve_path,
11+
get_workspace_path_from_config,
12+
)
13+
14+
15+
class DBMSTests(unittest.TestCase):
16+
DBGYM_CONFIG_PATH = Path("dbms/tests/dbms_integtest_dbgym_config.yaml")
17+
18+
def setUp(self) -> None:
19+
workspace_path = get_workspace_path_from_config(DBMSTests.DBGYM_CONFIG_PATH)
20+
# Get a clean start each time.
21+
if workspace_path.exists():
22+
shutil.rmtree(workspace_path)
23+
24+
# Reset this to avoid the error of it being created twice.
25+
# In real usage, the second run would be a different Python process so DBGymWorkspace.num_times_created_this_run would be 0.
26+
DBGymWorkspace.num_times_created_this_run = 0
27+
self.workspace = DBGymWorkspace(workspace_path)
28+
29+
def tearDown(self) -> None:
30+
if self.workspace.dbgym_workspace_path.exists():
31+
shutil.rmtree(self.workspace.dbgym_workspace_path)
32+
33+
def test_postgres_build(self) -> None:
34+
repo_path = get_repo_symlink_path(self.workspace.dbgym_workspace_path)
35+
self.assertFalse(repo_path.exists())
36+
_postgres_build(self.workspace, False)
37+
self.assertTrue(repo_path.exists())
38+
self.assertTrue(fully_resolve_path(repo_path).exists())
39+
40+
41+
if __name__ == "__main__":
42+
unittest.main()

env/tests/gymlib_integtest_util.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
from typing import Optional
55

66
# TODO: remove symlinks_paths from the import
7-
from gymlib.symlinks_paths import get_workload_suffix, get_workload_symlink_path
7+
from gymlib.symlinks_paths import (
8+
get_pgbin_symlink_path,
9+
get_workload_suffix,
10+
get_workload_symlink_path,
11+
)
812

913
from benchmark.tpch.constants import DEFAULT_TPCH_SEED
1014
from env.tuning_artifacts import TuningMetadata
1115
from util.workspace import (
1216
DBGymWorkspace,
1317
fully_resolve_path,
1418
get_default_dbdata_parent_dpath,
15-
get_default_pgbin_path,
1619
get_default_pristine_dbdata_snapshot_path,
1720
get_workspace_path_from_config,
1821
)
@@ -91,7 +94,7 @@ def get_default_metadata() -> TuningMetadata:
9194
dbgym_workspace.dbgym_workspace_path,
9295
GymlibIntegtestManager.BENCHMARK,
9396
GymlibIntegtestManager.SCALE_FACTOR,
94-
suffix
97+
suffix,
9598
),
9699
),
97100
pristine_dbdata_snapshot_path=fully_resolve_path(
@@ -105,6 +108,6 @@ def get_default_metadata() -> TuningMetadata:
105108
get_default_dbdata_parent_dpath(dbgym_workspace.dbgym_workspace_path),
106109
),
107110
pgbin_path=fully_resolve_path(
108-
get_default_pgbin_path(dbgym_workspace.dbgym_workspace_path),
111+
get_pgbin_symlink_path(dbgym_workspace.dbgym_workspace_path),
109112
),
110113
)

gymlib_package/gymlib/symlinks_paths.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,11 @@ def get_workload_symlink_path(
5959
/ DBGYM_APP_NAME
6060
/ (get_workload_dirname(benchmark, scale_factor, suffix) + ".link")
6161
)
62+
63+
64+
def get_repo_symlink_path(workspace_path: Path) -> Path:
65+
return workspace_path / SYMLINKS_DNAME / DBGYM_APP_NAME / "repo.link"
66+
67+
68+
def get_pgbin_symlink_path(workspace_path: Path) -> Path:
69+
return get_repo_symlink_path(workspace_path) / "boot" / "build" / "postgres" / "bin"

util/workspace.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ def get_latest_run_path_from_workspace_path(workspace_path: Path) -> Path:
4545
return get_runs_path_from_workspace_path(workspace_path) / "latest_run.link"
4646

4747

48-
# Other parameters
49-
50-
5148
# Paths of config files in the codebase. These are always relative paths.
5249
# The reason these can be relative paths instead of functions taking in codebase_path as input is because relative paths are relative to the codebase root
5350
DEFAULT_BOOT_CONFIG_FPATH = POSTGRES_PATH / "default_boot_config.yaml"
@@ -109,19 +106,6 @@ def get_default_dbdata_parent_dpath(workspace_path: Path) -> Path:
109106
return get_tmp_path_from_workspace_path(workspace_path)
110107

111108

112-
def get_default_repo_path(workspace_path: Path) -> Path:
113-
return (
114-
get_symlinks_path_from_workspace_path(workspace_path)
115-
/ "dbgym_dbms_postgres"
116-
/ "build"
117-
/ "repo.link"
118-
)
119-
120-
121-
def get_default_pgbin_path(workspace_path: Path) -> Path:
122-
return get_default_repo_path(workspace_path) / "boot" / "build" / "postgres" / "bin"
123-
124-
125109
class DBGymWorkspace:
126110
"""
127111
Global configurations that apply to all parts of DB-Gym

0 commit comments

Comments
 (0)