Skip to content

Commit

Permalink
ci: Add tasks to run unit tests and GitHub workflow to run non-storag…
Browse files Browse the repository at this point in the history
…e unit tests. (#30)

Co-authored-by: kirkrodrigues <[email protected]>
  • Loading branch information
sitaowang1998 and kirkrodrigues authored Dec 6, 2024
1 parent d307a2a commit 1c8773a
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 24 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/code-linting-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ concurrency:

jobs:
lint:
strategy:
matrix:
os: ["ubuntu-latest"]
runs-on: "${{matrix.os}}"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
with:
Expand All @@ -34,10 +31,6 @@ jobs:
- name: "Install task"
run: "npm install -g @go-task/cli"

- if: "matrix.os == 'macos-latest'"
name: "Install coreutils (for md5sum)"
run: "brew install coreutils"

- name: "Log tool versions"
run: |-
md5sum --version
Expand All @@ -47,7 +40,6 @@ jobs:
- name: "Install project dependencies "
timeout-minutes: 10
continue-on-error: false
run: "task deps:lib_install"

- run: "task lint:check"
45 changes: 45 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "unit-tests"

on:
pull_request:
push:
schedule:
# Run daily at 00:15 UTC (the 15 is to avoid periods of high load)
- cron: "15 0 * * *"
workflow_dispatch:

permissions: {}

concurrency:
group: "${{github.workflow}}-${{github.ref}}"

# Cancel in-progress jobs for efficiency
cancel-in-progress: true

jobs:
non-storage-unit-tests:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
with:
submodules: "recursive"

- uses: "actions/setup-python@v5"
with:
python-version: "3.10"

- name: "Install task"
run: "npm install -g @go-task/cli"

- name: "Log tool versions"
run: |-
md5sum --version
python --version
tar --version
task --version
- name: "Install project dependencies "
timeout-minutes: 10
run: "task deps:lib_install"

- run: "task test:non-storage-unit-tests"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Follow the steps below to develop and contribute to the project.

## Requirements
* Python 3.10 or higher
* [Task] 3.38.0 or higher
* [Task] 3.40.0 or higher

## Set up
Initialize and update submodules:
Expand Down
21 changes: 21 additions & 0 deletions build-tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3"

tasks:
target:
internal: true
vars:
TARGETS:
ref: "default (list \"all\") .TARGETS"
deps: [":config-cmake-project"]
cmds:
- >-
cmake
--build "{{.G_BUILD_SPIDER_DIR}}"
--parallel {{numCPU}}
--target {{range .TARGETS}}{{.}} {{end}}
clean:
internal: true
deps: [":config-cmake-project"]
cmds:
- "cmake --build {{.G_BUILD_SPIDER_DIR}} --target clean --parallel {{numCPU}}"
28 changes: 17 additions & 11 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,26 @@ require this storage backend.
4. Set the `cStorageUrl` in `tests/storage/StorageTestHelper.hpp` to
`jdbc:mariadb://localhost:3306/<db_name>?user=<usr>&password=<pwd>`.

## Build and run unit tests
## Running tests

To build and run the unit tests, run the following commands in project root directory.
You can use the following tasks to run the set of unit tests that's appropriate.

```shell
cmake -S . -B build
cmake --build build --target unitTest --parallel
./build/tests/unitTest
```
| Task | Description |
|-------------------------------|-------------------------------------------------------------------|
| `test:all` | Runs all unit tests. |
| `test:non-storage-unit-tests` | Runs all unit tests which don't require a storage backend to run. |
| `test:storage-unit-tests` | Runs all unit tests which require a storage backend to run. |

If the tests show error messages for connection functions below,
revisit [Setup storage backend](#setup-storage-backend) section and double check if `cStorageUrl` is
set correctly.
If any tests show error messages for the connection function below, revisit the
[setup section](#set-up-mysql-as-storage-backend) and verify that `cStorageUrl` was set correctly.

```c++
REQUIRE( storage->connect(spider::test::cStorageUrl).success() )
```
```
## GitHub unit test workflow
The [unit_tests.yaml][gh-workflow-unit-tests] GitHub workflow runs the unit tests on push,
pull requests, and daily. Currently, it only runs unit tests that don't require a storage backend.
[gh-workflow-unit-tests]: ../.github/workflows/unit-tests.yaml
6 changes: 4 additions & 2 deletions lint-tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ tasks:
--strict \
.gersemirc \
.github/ \
lint-tasks.yaml \
build-tasks.yaml \
dep-tasks.yaml \
taskfile.yaml
lint-tasks.yaml \
taskfile.yaml \
test-tasks.yaml
clang-format:
internal: true
Expand Down
4 changes: 3 additions & 1 deletion taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: "3"

includes:
lint: "lint-tasks.yaml"
deps: "dep-tasks.yaml"
build: "build-tasks.yaml"
lint: "lint-tasks.yaml"
test: "test-tasks.yaml"
utils: "tools/yscope-dev-utils/taskfiles/utils.yml"

vars:
Expand Down
30 changes: 30 additions & 0 deletions test-tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3"

vars:
G_TEST_BINARY: "{{.G_BUILD_SPIDER_DIR}}/tests/unitTest"

tasks:
non-storage-unit-tests:
deps:
- "build-unit-test"
cmds:
- "{{.G_TEST_BINARY}} \"~[storage]\""

storage-unit-tests:
deps:
- "build-unit-test"
cmds:
- "{{.G_TEST_BINARY}} \"[storage]\""

all:
deps:
- "build-unit-test"
cmds:
- "{{.G_TEST_BINARY}}"

build-unit-test:
internal: true
deps:
- task: ":build:target"
vars:
TARGETS: ["spider_task_executor", "unitTest", "worker_test"]

0 comments on commit 1c8773a

Please sign in to comment.