Skip to content

Commit edd278f

Browse files
PSMDB-1769 - Adding Github action for Ruff (#401)
* Adding Ruff linter github actions to run against any python file that has changes * Test fixes * Change so tests do not run against a Draft PR
1 parent 566cd91 commit edd278f

File tree

6 files changed

+104
-22
lines changed

6 files changed

+104
-22
lines changed

.github/workflows/LINT.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: LINT
2+
3+
on:
4+
workflow_dispatch:
5+
6+
pull_request:
7+
branches:
8+
- main
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 5
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Install dependencies
20+
run: pip install ruff uv
21+
22+
- name: Get changed Python files
23+
id: changed-files
24+
if: github.event_name == 'pull_request'
25+
run: |
26+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
27+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
28+
FILES="$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- '*.py' | tr '\n' ' ' || true)"
29+
echo "files=$FILES" >> "$GITHUB_OUTPUT"
30+
31+
- name: Run ruff only on changed files
32+
run: |
33+
FILES="${{ steps.changed-files.outputs.files }}"
34+
if [ -z "$FILES" ]; then
35+
echo "No changed Python files."
36+
exit 0
37+
fi
38+
echo "Linting changed files:"
39+
echo "$FILES"
40+
uv run ruff check $FILES

.github/workflows/PBM-FULL.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ on:
1111
required: false
1212

1313
pull_request:
14+
types: [opened, reopened, synchronize, ready_for_review]
1415
branches:
1516
- main
1617
paths:
1718
- 'pbm-functional/pytest/**'
1819

1920
jobs:
2021
test:
22+
if: github.event.pull_request.draft == false
2123
runs-on: ubuntu-latest
2224
timeout-minutes: 180
2325
strategy:

.github/workflows/PLM-FULL.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: PLM-FULL
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
plm_branch:
7+
description: "plm branch"
8+
required: false
9+
go_ver:
10+
description: "golang version"
11+
required: false
12+
13+
pull_request:
14+
types: [opened, reopened, synchronize, ready_for_review]
15+
branches:
16+
- main
17+
paths:
18+
- 'plm-pytest/**'
19+
20+
jobs:
21+
test:
22+
# Will not run if item is a draft
23+
if: github.event.pull_request.draft == false
24+
runs-on: ubuntu-latest
25+
timeout-minutes: 180
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
psmdb: ["6.0", "7.0", "8.0"]
30+
env:
31+
PLM_BRANCH: ${{ github.event.inputs.plm_branch || 'main' }}
32+
GO_VER: ${{ github.event.inputs.go_ver || 'bullseye' }}
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Setup environment with PSMDB ${{ matrix.psmdb }} and PLM branch ${{ env.PLM_BRANCH }}
36+
run: |
37+
PSMDB=perconalab/percona-server-mongodb:${{ matrix.psmdb }} docker compose build easyrsa
38+
PSMDB=perconalab/percona-server-mongodb:${{ matrix.psmdb }} docker compose build
39+
docker compose up -d
40+
working-directory: ./plm-pytest
41+
- name: Test ${{ matrix.test }} backup/restore on PSMDB ${{ matrix.psmdb }} and PBM branch ${{ env.PLM_BRANCH }}
42+
run: |
43+
docker compose run --rm test pytest -s --junitxml=junit.xml
44+
working-directory: ./plm-pytest
45+
- name: Print PLM logs
46+
if: failure()
47+
run: |
48+
docker logs plink
49+
- name: Publish Test Report
50+
uses: mikepenz/action-junit-report@v4
51+
if: success() || failure()
52+
with:
53+
report_paths: '**/junit.xml'

plm-pytest/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest_plugins = [
2+
"metrics_collector"
3+
]

plm-pytest/test_basic_sync_rs.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ def test_rs_plink_PML_T2(reset_state, srcRS, dstRS, plink, metrics_collector):
134134
def test_rs_plink_PML_T3(reset_state, srcRS, dstRS, plink):
135135
"""
136136
Test to validate handling of index creation failures during clone and replication phase due to
137-
IndexOptionsConflict error (index with the same key spec already exists with a different name).
138-
Since PLM temporarily creates unique indexes as non-unique, creation of index with the same options
139-
but different name should fail. It's expected behavior, but all other indexes should be created successfully.
137+
IndexOptionsConflict error (index with the same key spec already exists with a different name). The failed index will be created during the finalization stage.
140138
"""
141139
try:
142140
src = pymongo.MongoClient(srcRS.connection)
@@ -197,8 +195,6 @@ def test_rs_plink_PML_T3(reset_state, srcRS, dstRS, plink):
197195
name="compound_test_sparse_index", sparse=True
198196
)
199197

200-
time.sleep(5)
201-
202198
except Exception:
203199
raise
204200
finally:
@@ -219,28 +215,16 @@ def test_rs_plink_PML_T3(reset_state, srcRS, dstRS, plink):
219215
result = plink.finalize()
220216
assert result is True, "Failed to finalize plink service"
221217

222-
expected_mismatches = [
223-
("init_test_db.invalid_index_collection", "compound_test_unique_index"),
224-
("clone_test_db.invalid_index_collection", "compound_test_unique_index"),
225-
("repl_test_db.invalid_index_collection", "compound_test_unique_index")
226-
]
227-
228218
result, summary = compare_data_rs(srcRS, dstRS)
229-
assert result is False, "Data mismatch after synchronization"
230-
231-
missing_mismatches = [index for index in expected_mismatches if index not in summary]
232-
unexpected_mismatches = [mismatch for mismatch in summary if mismatch not in expected_mismatches]
233-
234-
assert not missing_mismatches, f"Expected mismatches missing: {missing_mismatches}"
235-
if unexpected_mismatches:
236-
pytest.fail("Unexpected mismatches:\n" + "\n".join(unexpected_mismatches))
219+
assert result is True, "Data mismatch after synchronization"
237220

238221
plink_error, error_logs = plink.check_plink_errors()
239222
expected_error = "ERR One or more indexes failed to create"
240223
if not plink_error:
241224
unexpected = [line for line in error_logs if expected_error not in line]
242225
if unexpected:
243226
pytest.fail("Unexpected error(s) in logs:\n" + "\n".join(unexpected))
227+
assert len(error_logs) == 3
244228

245229
@pytest.mark.timeout(300,func_only=True)
246230
@pytest.mark.usefixtures("start_cluster")
@@ -674,7 +658,7 @@ def test_rs_plink_PML_T30(reset_state, srcRS, dstRS, plink):
674658
Test to validate handling of concurrent data clone and index build failure
675659
"""
676660
src = pymongo.MongoClient(srcRS.connection)
677-
dst = pymongo.MongoClient(dstRS.connection)
661+
pymongo.MongoClient(dstRS.connection)
678662
normal_docs = [{"a": {"b": 1}, "words": "omnibus"} for _ in range(20000)]
679663
src["init_test_db"].invalid_text_collection1.insert_many(normal_docs)
680664
src["init_test_db"].invalid_text_collection1.insert_one({"a": {"b": []}, "words": "omnibus"})
@@ -699,7 +683,7 @@ def invalid_index_creation():
699683
t2.start()
700684
t1.join()
701685
t2.join()
702-
assert plink.wait_for_repl_stage(timeout=30) is True, "Failed to start replication stage"
686+
assert plink.wait_for_repl_stage(timeout=60) is True, "Failed to start replication stage"
703687
assert plink.wait_for_zero_lag() is True, "Failed to catch up on replication"
704688
assert plink.finalize() is True, "Failed to finalize plink service"
705689
result, _ = compare_data_rs(srcRS, dstRS)

plm-pytest/test_edge_case_id_rs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def test_rs_plink_PML_T34(reset_state, srcRS, dstRS, plink, id_type):
174174

175175
def add_data(target_suffix):
176176
batch_size = 5000
177-
num_batches = 80
177+
num_batches = 20
178178

179179
for meta in collections_meta:
180180
if not meta["name"].endswith(target_suffix):

0 commit comments

Comments
 (0)