Skip to content

Commit e373554

Browse files
Unit testing CI (#36)
**Summary**: Made GitHub Action which installs dependencies and runs all unit tests in the repository. **Demo**: A successful run. You can view it [here](https://github.com/cmu-db/dbgym/actions/runs/9831741840/job/27139551785). ![Screenshot 2024-07-07 at 17 56 58](https://github.com/cmu-db/dbgym/assets/20631215/c2613191-49eb-4d86-b0c2-a59a66e899c5) **Details**: * Also fixed some benign errors in the unit tests. Some paths were previously relative and had to be changed to be absolute. I also started counting index names from 0 instead of 1, which led to another test failure.
1 parent 3245aab commit e373554

File tree

9 files changed

+52
-33
lines changed

9 files changed

+52
-33
lines changed

.github/workflows/sanity_test.yml

-16
This file was deleted.

.github/workflows/unittest_ci.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Unit Tests
2+
3+
on:
4+
push: {}
5+
pull_request:
6+
branches: [main]
7+
8+
jobs:
9+
build:
10+
runs-on: self-hosted
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.10'
19+
20+
# We could choose to set up dependencies manually in the GHA runner instead of installing them during the GHA.
21+
#
22+
# However, I think it's better to do them in the GHA itself so that we're testing our dependency installation step
23+
# in addition to our actual code. It also removes the need to manually reinstall dependencies on the GHA runners
24+
# every time we add a new dependency.
25+
#
26+
# Note that the GHA runners are stateful. Dependencies installed from previous runs will still be on the runner.
27+
# This means this step will usually be pretty fast as most dependencies will already be cached. However, it also
28+
# means that past runs might interfere with the current run, so you sometimes may need to restart the GHA runners.
29+
- name: Install dependencies
30+
run: |
31+
./dependencies/install_dependencies.sh
32+
. "$HOME/.cargo/env"
33+
34+
- name: Run unit tests
35+
run: python scripts/run_unittests.py

dependencies/install_dependencies.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22
# You may want to create a conda environment before doing this
3-
pip install -r dependency/requirements.txt
4-
cat dependency/apt_requirements.txt | xargs sudo apt-get install -y
5-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
3+
pip install -r dependencies/requirements.txt
4+
cat dependencies/apt_requirements.txt | xargs sudo apt-get install -y
5+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

dependencies/rust.sh

-2
This file was deleted.

scripts/run_unittests.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import unittest
2+
import sys
23

34
if __name__ == "__main__":
45
loader = unittest.TestLoader()
56
suite = loader.discover(".")
6-
print(f"suite={suite}")
77
runner = unittest.TextTestRunner()
8-
runner.run(suite)
8+
result = runner.run(suite)
9+
if not result.wasSuccessful():
10+
# This is needed so that the GHA fails if the unit tests fail.
11+
sys.exit(1)

tune/protox/env/workload.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ def __init__(
223223
workload_timeout_penalty: float = 1.0,
224224
logger: Optional[Logger] = None,
225225
) -> None:
226-
227226
self.dbgym_cfg = dbgym_cfg
228227
self.workload_path = workload_path
229228
# Whether we should use benchbase or not.
@@ -257,7 +256,7 @@ def __init__(
257256
sqls = [
258257
(
259258
line.split(",")[0],
260-
Path(line.split(",")[1]),
259+
self.workload_path / Path(line.split(",")[1]),
261260
1.0,
262261
)
263262
for line in lines
@@ -271,7 +270,7 @@ def __init__(
271270
sqls = [
272271
(
273272
split[0],
274-
Path(split[1]),
273+
self.workload_path / Path(split[1]),
275274
float(split[2]),
276275
)
277276
for split in splits

tune/protox/tests/test_index_space.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class IndexSpaceTests(unittest.TestCase):
1212
@staticmethod
1313
def load(
14-
config_path=Path("tune/protox/tests/unittest_benchmark_configs/unittest_tpch.yaml"),
14+
config_path=Path("tune/protox/tests/unittest_benchmark_configs/unittest_tpch.yaml").resolve(),
1515
aux_type=True,
1616
aux_include=True,
1717
):
@@ -27,7 +27,7 @@ def load(
2727
tables=benchmark_config["tables"],
2828
attributes=benchmark_config["attributes"],
2929
query_spec=benchmark_config["query_spec"],
30-
workload_path=Path("tune/protox/tests/unittest_tpch_dir"),
30+
workload_path=Path("tune/protox/tests/unittest_tpch_dir").resolve(),
3131
pid=None,
3232
workload_timeout=0,
3333
workload_timeout_penalty=1.0,

tune/protox/tests/test_primitive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_ia(self):
9898
IndexAction.index_counter = 0
9999
self.assertEqual(
100100
ia1.sql(add=True),
101-
"CREATE INDEX index1 ON tbl USING btree (a,b,c) INCLUDE (d,e)",
101+
"CREATE INDEX index0 ON tbl USING btree (a,b,c) INCLUDE (d,e)",
102102
)
103103

104104
ia2 = IndexAction(

tune/protox/tests/test_workload.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_tpch(self):
5656
for k, v in ref.items()
5757
}
5858

59-
w, i = WorkloadTests.load("tune/protox/tests/unittest_benchmark_configs/unittest_tpch.yaml", Path("tune/protox/tests/unittest_tpch_dir"))
59+
w, i = WorkloadTests.load("tune/protox/tests/unittest_benchmark_configs/unittest_tpch.yaml", Path("tune/protox/tests/unittest_tpch_dir").resolve())
6060
self.assertEqual(i.class_mapping, ref)
6161

6262
def test_job(self):
@@ -68,7 +68,7 @@ def test_job(self):
6868
for k, v in ref.items()
6969
}
7070

71-
w, i = WorkloadTests.load("tune/protox/tests/unittest_benchmark_configs/unittest_job_full.yaml", Path("tune/protox/tests/unittest_job_full_dir"))
71+
w, i = WorkloadTests.load("tune/protox/tests/unittest_benchmark_configs/unittest_job_full.yaml", Path("tune/protox/tests/unittest_job_full_dir").resolve())
7272
self.assertEqual(i.class_mapping, ref)
7373

7474
def test_dsb(self):
@@ -80,7 +80,7 @@ def test_dsb(self):
8080
for k, v in ref.items()
8181
}
8282

83-
w, i = WorkloadTests.load("tune/protox/tests/unittest_benchmark_configs/unittest_dsb.yaml", Path("tune/protox/tests/unittest_dsb_dir"))
83+
w, i = WorkloadTests.load("tune/protox/tests/unittest_benchmark_configs/unittest_dsb.yaml", Path("tune/protox/tests/unittest_dsb_dir").resolve())
8484
self.diff_classmapping(ref, i.class_mapping)
8585

8686
def test_tpcc(self):
@@ -92,5 +92,5 @@ def test_tpcc(self):
9292
for k, v in ref.items()
9393
}
9494

95-
w, i = WorkloadTests.load("tune/protox/tests/unittest_benchmark_configs/unittest_tpcc.yaml", Path("tune/protox/tests/unittest_tpcc_dir"))
95+
w, i = WorkloadTests.load("tune/protox/tests/unittest_benchmark_configs/unittest_tpcc.yaml", Path("tune/protox/tests/unittest_tpcc_dir").resolve())
9696
self.assertEqual(i.class_mapping, ref)

0 commit comments

Comments
 (0)