Skip to content

Commit f6149e6

Browse files
authored
Improve tests (#393)
* Add test assertions * Restructure testing directories * Add more test assertions * Fix GitHub Actions and update README * Update Chrysalis tests * Add blocking test notes
1 parent d1a399a commit f6149e6

37 files changed

+779
-435
lines changed

.github/workflows/build_workflow.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ jobs:
8282
run: |
8383
python -m pip install .
8484
85+
# Run machine-independent tests
8586
- name: Run Tests
8687
run: |
87-
python -m unittest tests/test_*.py
88+
pytest tests/unit/test_*.py
89+
python -m unittest tests/integration/python_tests/group_by_command/test_*.py
90+
python -m unittest tests/integration/python_tests/group_by_workflow/test_*.py
8891
8992
# Build documentation on all PRs and pushes; only publish (commit to gh-pages) on pushes.
9093
build-docs:

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
build/
22
dist/
3-
tests/test_follow_symlinks/
4-
tests/test_follow_symlinks_non_archived/
3+
tests/utils/test_follow_symlinks
4+
tests/utils/test_follow_symlinks_non_archived
55
zstash.egg-info/
66
*.pyc
77
*~

conda/dev.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies:
88
- python >=3.11,<3.14
99
- sqlite
1010
- six >=1.16.0
11-
- globus-sdk >=3.15.0
11+
- globus-sdk >=3.15.0,<4.0
1212
# Developer Tools
1313
# =================
1414
# If versions are updated, also update 'rev' in `.pre-commit.config.yaml`
@@ -18,6 +18,10 @@ dependencies:
1818
- mypy ==1.18.2
1919
- pre-commit ==4.3.0
2020
- tbump >=6.9.0
21+
# Testing
22+
# =======================
23+
- pytest
24+
- pytest-cov
2125
# Documentation
2226
# =================
2327
# If versions are updated, also update in `.github/workflows/workflow.yml`

tests/README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# zstash Test Suite
2+
3+
## The test directory structure
4+
5+
```
6+
tests/
7+
integration/ # Tests that call zstash from the command line
8+
bash_tests/ # Test zstash commands via bash scripts
9+
run_from_chrysalis/ # Run these from Chrysalis (these use Globus and/or require the Chrysalis file system)
10+
run_from_perlmutter/ # Run these from Perlmutter (these use `hsi` directly and/or require the Perlmutter file system)
11+
python_tests/ # Test zstash commands via Python unittest wrappers
12+
group_by_command # Tests organized by command
13+
group_by_workflow # Tests organized by workflow
14+
unit/ # Tests of pure functions (uses pytest, not unittest)
15+
utils/ # Utilities for testing
16+
```
17+
18+
## Testing example for Perlmutter
19+
20+
```bash
21+
rm -rf build
22+
conda clean --all --y
23+
conda env create -f conda/dev.yml -n zstash_dev_20251017_test1
24+
conda activate zstash_dev_20251017_test1
25+
pre-commit run --all-files
26+
python -m pip install .
27+
pytest tests/unit/test_*.py
28+
# 1 passed in 0.19s
29+
python -m unittest tests/integration/python_tests/group_by_command/test_*.py
30+
# Ran 69 tests in 327.570s
31+
# OK
32+
python -m unittest tests/integration/python_tests/group_by_workflow/test_*.py
33+
# Ran 4 tests in 2.666s
34+
# OK
35+
cd tests/integration/bash_tests/run_from_perlmutter/
36+
time ./follow_symlinks.sh # NOTE: you will have to change out paths for your username
37+
# real 0m31.851s
38+
# No errors
39+
time ./test_update_non_empty_hpss.bash
40+
# real 0m10.062s
41+
# No errors
42+
43+
# Log into globus.org
44+
# Log into endpoints (NERSC Perlmutter, Globus Tutorial Collection 1) at globus.org: File Manager > Add the endpoints in the "Collection" fields
45+
time ./test_ls_globus.bash
46+
# real 0m26.930s
47+
# No errors
48+
```
49+
50+
## Testing example for Chrysalis
51+
52+
```bash
53+
rm -rf build
54+
conda clean --all --y
55+
conda env create -f conda/dev.yml -n zstash_dev_20251017_test1
56+
conda activate zstash_dev_20251017_test1
57+
pre-commit run --all-files
58+
python -m pip install .
59+
pytest tests/unit/test_*.py
60+
# 1 passed in 0.84s
61+
python -m unittest tests/integration/python_tests/group_by_command/test_*.py
62+
# Ran 69 tests in 110.139s
63+
# OK (skipped=32)
64+
# NOTE: Some tests are skipped because Chrysalis doesn't have direct `hsi`/HPSS access
65+
python -m unittest tests/integration/python_tests/group_by_workflow/test_*.py
66+
# Ran 4 tests in 6.889s
67+
# OK
68+
cd tests/integration/bash_tests/run_from_chrysalis/
69+
70+
# Log into globus.org
71+
# 1. Log into endpoints (LCRC Improv DTN, NERSC Perlmutter) at globus.org: File Manager > Add the endpoints in the "Collection" fields
72+
# 2. To start fresh, with no consents: https://auth.globus.org/v2/web/consents > Manage Your Consents > Globus Endpoint Performance Monitoring > rescind all"
73+
# Then, increment `try_num` below to avoid using an old directory.
74+
# Alternatively, start fresh by deleting the directory on Perlmutter:
75+
# `rm -rf /global/homes/f/forsyth/zstash/tests/test_globus_auth_try{try_num}`
76+
time ./globus_auth.bash try_num # NOTE: you will have to change out paths for your username
77+
# Paste the URL into your browser
78+
# Log into Argonne
79+
# Log into NERSC
80+
# Provide a label
81+
# Copy the auth code to the command line
82+
#
83+
# real 2m45.954s
84+
# No errors
85+
86+
# If not done above, do the following:
87+
# Log into globus.org
88+
# Log into endpoints (LCRC Improv DTN, NERSC Perlmutter) at globus.org: File Manager > Add the endpoints in the "Collection" fields
89+
90+
# In all cases, do:
91+
# Then, increment `try_num` below to avoid using an old directory.
92+
# Alternatively, start fresh by deleting the directory on Perlmutter:
93+
# `rm -rf /global/homes/f/forsyth/zstash/tests/test_database_corruption_try{try_num}`
94+
time ./database_corruption.bash try_num # NOTE: you will have to change out paths for your username
95+
# Success count: 25
96+
# Fail count: 0
97+
# real 6m43.994s
98+
99+
time ./symlinks.sh # NOTE: you will have to change out paths for your username
100+
# real 0m1.346s
101+
# No errors
102+
103+
cd blocking_test_scripts
104+
# Review README_TEST_BLOCKING
105+
# This uses "12 piControl ocean monthly files, 49 GB",
106+
# so processing may take a long time.
107+
# TODO (later PR): Confirm this test works
108+
```
109+
110+
## Testing with GitHub Actions
111+
112+
GitHub Actions runs the tests according to `.github/workflows/build_workflow.yml`:
113+
```
114+
# Run machine-independent tests
115+
- name: Run Tests
116+
run: |
117+
pytest tests/unit/test_*.py
118+
python -m unittest tests/integration/python_tests/group_by_command/test_*.py
119+
python -m unittest tests/integration/python_tests/group_by_workflow/test_*.py
120+
```

tests/integration/__init__.py

Whitespace-only changes.

tests3/README_TEST_BLOCKING renamed to tests/integration/bash_tests/run_from_chrysalis/blocking_test_scripts/README_TEST_BLOCKING

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,7 @@ II. Running the Test Script
6767

6868
The test script "test_zstash_blocking.sh" accepts two positional parameters:
6969

70-
test_zstash_blocking.sh (BLOCKING|NON_BLOCKING) [NEW_CREDS]
71-
72-
On an initial run, or whenever Globus complains of authentication failures,
73-
add "NEW_CREDS" as the second parameter. This will act to delete your
74-
cached Globus credentials and trigger prompts for you to paste login URLs
75-
to your browser (generally one per endpoint) which requires that you conduct
76-
a login sequence, and then paste a returned key-value at the bash command
77-
prompt. After both keys are accepted, you can re-run the test script
78-
without "NEW_CREDS", until the credentials expire (usually 24 hours.)
70+
test_zstash_blocking.sh (BLOCKING|NON_BLOCKING)
7971

8072
If "BLOCKING" is selected, zstash will run in default mode, waiting for
8173
each tar file to complete transfer before generating another tar file.
@@ -93,7 +85,7 @@ so that your command prompt returns and you can monitor progress with
9385
snapshot.sh
9486

9587
which will provide a view of both the tarfile cache and the destination
96-
directory for delivred tar files. It is also suggested that you name your
88+
directory for delivered tar files. It is also suggested that you name your
9789
logfile to reflect the date, and whether BLOCKING or not was specified.
9890

9991

0 commit comments

Comments
 (0)