Skip to content

Commit e0872fe

Browse files
authored
Standardize test function names for clarity and consistency (#7709)
1 parent 13b3b09 commit e0872fe

5 files changed

Lines changed: 67 additions & 12 deletions

File tree

tests/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# End-to-End Tests
2+
3+
## Test hierarchy
4+
5+
```
6+
CTest entry ctest -R e2e_logging
7+
└── Entry-point tests/e2e_logging.py
8+
└── Runner cr.add("cpp", run_cpp, ...)
9+
└── Group run_cpp(args) — creates and owns a network
10+
└── Case test_historical_query(network, args) — single test
11+
```
12+
13+
## Naming conventions
14+
15+
### CTest entries
16+
17+
Registered in CMakeLists.txt via `add_e2e_test(NAME ...)`. Names should be
18+
unique and not be substrings of each other, so that `ctest -R <name>` matches
19+
exactly one test. For example, `recovery_test` and `recovery_test_suite` are
20+
problematic because `-R recovery_test` matches both.
21+
22+
### Entry-points
23+
24+
Python scripts (e.g. `schema.py`, `e2e_logging.py`) that use `ConcurrentRunner`
25+
to run one or more groups in parallel. A single entry-point may bin-pack
26+
unrelated groups for efficient CI run-time.
27+
28+
### Runners (ConcurrentRunner threads)
29+
30+
The first argument to `cr.add("name", ...)`. This name appears in every log
31+
line from that thread, so it should be short and descriptive (e.g. `"cpp"`,
32+
`"operations"`, `"recovery"`).
33+
34+
### Groups — `run_` prefix
35+
36+
Top-level functions that create and own a network, then call test cases on it.
37+
38+
- Should take `(args)` or `(const_args)`.
39+
- Should create their own network via `with infra.network.network(...)`.
40+
- Should not return `network`.
41+
- `const_args` signals the function will `copy.deepcopy` before mutating.
42+
43+
### Test cases — `test_` prefix
44+
45+
Individual test functions that operate on an existing network.
46+
47+
- Should take `(network, args)` and return `network` (enables chaining).
48+
- Should have a `@reqs.description("...")` decorator.
49+
- Should not create their own network.
50+
51+
### Other helpers
52+
53+
Functions that don't fit either pattern (e.g. shared test groups that operate
54+
on an existing network but aren't individual tests) should avoid the `test_`
55+
and `run_` prefixes.

tests/e2e_logging.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ def additional_interfaces(local_node_id):
22002200
) as network:
22012201
network.start_and_open(args)
22022202

2203-
run_main_tests(network, args)
2203+
do_main_tests(network, args)
22042204

22052205

22062206
def run_app_space_js(args):
@@ -2256,7 +2256,7 @@ def run_app_space_js(args):
22562256
)
22572257
assert r.status_code == http.HTTPStatus.OK.value, r.status_code
22582258

2259-
run_main_tests(network, args)
2259+
do_main_tests(network, args)
22602260

22612261

22622262
def test_cose_config(network, args):
@@ -2276,7 +2276,7 @@ def test_cose_config(network, args):
22762276
return network
22772277

22782278

2279-
def run_main_tests(network, args):
2279+
def do_main_tests(network, args):
22802280
test_basic_constraints(network, args)
22812281
test(network, args)
22822282
test_remove(network, args)

tests/e2e_operations.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,7 +2582,7 @@ def run_read_ledger_on_testdata(args):
25822582
)
25832583

25842584

2585-
def test_merkle_verification_level(args):
2585+
def run_merkle_verification_level(args):
25862586
"""Test MERKLE verification level on isolated chunks and full ledgers"""
25872587
LOG.info("Testing MERKLE verification level")
25882588

@@ -2746,7 +2746,7 @@ def test_merkle_verification_level(args):
27462746
temp_dir.cleanup()
27472747

27482748

2749-
def test_error_message_on_failure_to_read_aci_sec_context(args):
2749+
def run_error_message_on_failure_to_read_aci_sec_context(args):
27502750
with infra.network.network(
27512751
args.nodes,
27522752
args.binary_dir,
@@ -2796,7 +2796,7 @@ def test_error_message_on_failure_to_read_aci_sec_context(args):
27962796
), f"Did not find expected log messages: {expected_log_messages}"
27972797

27982798

2799-
def test_error_message_on_failure_to_fetch_snapshot(const_args):
2799+
def run_error_message_on_failure_to_fetch_snapshot(const_args):
28002800
args = copy.deepcopy(const_args)
28012801
args.nodes = infra.e2e_args.min_nodes(args, 0)
28022802
with infra.network.network(
@@ -2909,7 +2909,7 @@ def run_snp_tests(args):
29092909
)
29102910
run_recovery_local_unsealing(args, recovery_f=1, suffix="_unsealing_with_f_equal_1")
29112911
run_recovery_unsealing_validate_audit(args)
2912-
test_error_message_on_failure_to_read_aci_sec_context(args)
2912+
run_error_message_on_failure_to_read_aci_sec_context(args)
29132913
run_recovery_decision_protocol(args)
29142914
run_recovery_decision_protocol_timeout_path(args)
29152915
run_recovery_decision_protocol_multiple_timeout(args)
@@ -2930,5 +2930,5 @@ def run(args):
29302930
run_late_mounted_ledger_check(args)
29312931
run_empty_ledger_dir_check(args)
29322932
run_read_ledger_on_testdata(args)
2933-
test_merkle_verification_level(args)
2933+
run_merkle_verification_level(args)
29342934
run_propose_request_vote(args)

tests/npm_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def generate_and_verify_jwk(client):
154154
assert body["pem"] == pub_pem
155155

156156

157-
def test_apply_writes(c):
157+
def check_apply_writes(c):
158158
### Default behaviour
159159
# Writes are applied for 2xx response codes
160160
r = c.post("/app/rpc/apply_writes", {"val": "aaa", "statusCode": 200})
@@ -695,7 +695,7 @@ def test_npm_app(network, args):
695695
v3 = r.body.json()["version"]
696696
assert v3 == v1
697697

698-
test_apply_writes(c)
698+
check_apply_writes(c)
699699

700700
priv_key_pem, _ = infra.crypto.generate_rsa_keypair(2048)
701701
pem = infra.crypto.generate_cert(priv_key_pem)

tests/recovery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def test_trusted_keys_vs_endorsements(network, args):
591591

592592

593593
@reqs.description("Recover a service from local files")
594-
def test_recover_service_from_files(
594+
def run_recover_service_from_files(
595595
args,
596596
directory,
597597
expected_recovery_count,
@@ -1202,7 +1202,7 @@ def run(args):
12021202

12031203

12041204
def run_recovery_from_files(args):
1205-
test_recover_service_from_files(
1205+
run_recover_service_from_files(
12061206
args,
12071207
directory=args.directory,
12081208
expected_recovery_count=args.expected_recovery_count,

0 commit comments

Comments
 (0)