Skip to content

Commit

Permalink
Unit testing CI (#36)
Browse files Browse the repository at this point in the history
**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.
  • Loading branch information
wangpatrick57 authored Jul 15, 2024
1 parent 3245aab commit e373554
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 33 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/sanity_test.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/unittest_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Unit Tests

on:
push: {}
pull_request:
branches: [main]

jobs:
build:
runs-on: self-hosted

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

# We could choose to set up dependencies manually in the GHA runner instead of installing them during the GHA.
#
# However, I think it's better to do them in the GHA itself so that we're testing our dependency installation step
# in addition to our actual code. It also removes the need to manually reinstall dependencies on the GHA runners
# every time we add a new dependency.
#
# Note that the GHA runners are stateful. Dependencies installed from previous runs will still be on the runner.
# This means this step will usually be pretty fast as most dependencies will already be cached. However, it also
# means that past runs might interfere with the current run, so you sometimes may need to restart the GHA runners.
- name: Install dependencies
run: |
./dependencies/install_dependencies.sh
. "$HOME/.cargo/env"
- name: Run unit tests
run: python scripts/run_unittests.py
6 changes: 3 additions & 3 deletions dependencies/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# You may want to create a conda environment before doing this
pip install -r dependency/requirements.txt
cat dependency/apt_requirements.txt | xargs sudo apt-get install -y
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
pip install -r dependencies/requirements.txt
cat dependencies/apt_requirements.txt | xargs sudo apt-get install -y
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
2 changes: 0 additions & 2 deletions dependencies/rust.sh

This file was deleted.

7 changes: 5 additions & 2 deletions scripts/run_unittests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import unittest
import sys

if __name__ == "__main__":
loader = unittest.TestLoader()
suite = loader.discover(".")
print(f"suite={suite}")
runner = unittest.TextTestRunner()
runner.run(suite)
result = runner.run(suite)
if not result.wasSuccessful():
# This is needed so that the GHA fails if the unit tests fail.
sys.exit(1)
5 changes: 2 additions & 3 deletions tune/protox/env/workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def __init__(
workload_timeout_penalty: float = 1.0,
logger: Optional[Logger] = None,
) -> None:

self.dbgym_cfg = dbgym_cfg
self.workload_path = workload_path
# Whether we should use benchbase or not.
Expand Down Expand Up @@ -257,7 +256,7 @@ def __init__(
sqls = [
(
line.split(",")[0],
Path(line.split(",")[1]),
self.workload_path / Path(line.split(",")[1]),
1.0,
)
for line in lines
Expand All @@ -271,7 +270,7 @@ def __init__(
sqls = [
(
split[0],
Path(split[1]),
self.workload_path / Path(split[1]),
float(split[2]),
)
for split in splits
Expand Down
4 changes: 2 additions & 2 deletions tune/protox/tests/test_index_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class IndexSpaceTests(unittest.TestCase):
@staticmethod
def load(
config_path=Path("tune/protox/tests/unittest_benchmark_configs/unittest_tpch.yaml"),
config_path=Path("tune/protox/tests/unittest_benchmark_configs/unittest_tpch.yaml").resolve(),
aux_type=True,
aux_include=True,
):
Expand All @@ -27,7 +27,7 @@ def load(
tables=benchmark_config["tables"],
attributes=benchmark_config["attributes"],
query_spec=benchmark_config["query_spec"],
workload_path=Path("tune/protox/tests/unittest_tpch_dir"),
workload_path=Path("tune/protox/tests/unittest_tpch_dir").resolve(),
pid=None,
workload_timeout=0,
workload_timeout_penalty=1.0,
Expand Down
2 changes: 1 addition & 1 deletion tune/protox/tests/test_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_ia(self):
IndexAction.index_counter = 0
self.assertEqual(
ia1.sql(add=True),
"CREATE INDEX index1 ON tbl USING btree (a,b,c) INCLUDE (d,e)",
"CREATE INDEX index0 ON tbl USING btree (a,b,c) INCLUDE (d,e)",
)

ia2 = IndexAction(
Expand Down
8 changes: 4 additions & 4 deletions tune/protox/tests/test_workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_tpch(self):
for k, v in ref.items()
}

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

def test_job(self):
Expand All @@ -68,7 +68,7 @@ def test_job(self):
for k, v in ref.items()
}

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

def test_dsb(self):
Expand All @@ -80,7 +80,7 @@ def test_dsb(self):
for k, v in ref.items()
}

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

def test_tpcc(self):
Expand All @@ -92,5 +92,5 @@ def test_tpcc(self):
for k, v in ref.items()
}

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

0 comments on commit e373554

Please sign in to comment.