Skip to content

Commit b737f71

Browse files
committed
fix: update test assertions to match simplified Workload fixture
The Workload.java fixture was trimmed to only repeatString but test files still asserted computeSum, filterEvens, and instanceMethod.
1 parent 0cb67c1 commit b737f71

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

tests/test_languages/test_java/test_java_tracer_e2e.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,11 @@ def test_agent_captures_invocations(self, compiled_workload: Path, trace_db: Pat
8181
conn = sqlite3.connect(str(trace_db))
8282
try:
8383
rows = conn.execute("SELECT function, classname, descriptor, length(args) FROM function_calls").fetchall()
84-
assert len(rows) >= 5, f"Expected at least 5 captured invocations, got {len(rows)}"
84+
assert len(rows) >= 2, f"Expected at least 2 captured invocations, got {len(rows)}"
8585

8686
# Check that specific methods were captured
8787
functions = {row[0] for row in rows}
88-
assert "computeSum" in functions
8988
assert "repeatString" in functions
90-
assert "filterEvens" in functions
91-
assert "instanceMethod" in functions
9289

9390
# Verify all rows have non-empty args blobs
9491
for row in rows:
@@ -97,7 +94,7 @@ def test_agent_captures_invocations(self, compiled_workload: Path, trace_db: Pat
9794
# Verify metadata
9895
metadata = dict(conn.execute("SELECT key, value FROM metadata").fetchall())
9996
assert "totalCaptures" in metadata
100-
assert int(metadata["totalCaptures"]) >= 5
97+
assert int(metadata["totalCaptures"]) >= 2
10198
finally:
10299
conn.close()
103100

@@ -136,11 +133,11 @@ def test_max_function_count_limit(self, compiled_workload: Path, trace_db: Path)
136133

137134
conn = sqlite3.connect(str(trace_db))
138135
try:
139-
# computeSum is called 4 times (2 direct + 2 from instanceMethod)
140-
compute_count = conn.execute(
141-
"SELECT COUNT(*) FROM function_calls WHERE function = 'computeSum'"
136+
# repeatString is called 1000+ times; with maxFunctionCount=2, at most 2 should be captured
137+
repeat_count = conn.execute(
138+
"SELECT COUNT(*) FROM function_calls WHERE function = 'repeatString'"
142139
).fetchone()[0]
143-
assert compute_count <= 2, f"Expected at most 2 computeSum captures, got {compute_count}"
140+
assert repeat_count <= 2, f"Expected at most 2 repeatString captures, got {repeat_count}"
144141
finally:
145142
conn.close()
146143

@@ -198,7 +195,6 @@ def test_generates_test_files(self, compiled_workload: Path, trace_db: Path, tmp
198195
assert "package codeflash.replay;" in content
199196
assert "import org.junit.jupiter.api.Test;" in content
200197
assert "ReplayHelper" in content
201-
assert "replay_computeSum_0" in content
202198
assert "replay_repeatString_0" in content
203199

204200
def test_metadata_parsing(self, compiled_workload: Path, trace_db: Path, tmp_path: Path) -> None:
@@ -243,7 +239,7 @@ def test_metadata_parsing(self, compiled_workload: Path, trace_db: Path, tmp_pat
243239
assert "functions" in metadata
244240
assert "trace_file" in metadata
245241
assert "classname" in metadata
246-
assert "computeSum" in metadata["functions"]
242+
assert "repeatString" in metadata["functions"]
247243
assert metadata["classname"] == "com.example.Workload"
248244
assert metadata["trace_file"] == trace_db.as_posix()
249245

@@ -267,7 +263,7 @@ def test_two_stage_trace(self, compiled_workload: Path, tmp_path: Path) -> None:
267263
conn = sqlite3.connect(str(trace_db))
268264
try:
269265
count = conn.execute("SELECT COUNT(*) FROM function_calls").fetchone()[0]
270-
assert count >= 5, f"Expected at least 5 captured invocations, got {count}"
266+
assert count >= 2, f"Expected at least 2 captured invocations, got {count}"
271267
finally:
272268
conn.close()
273269

@@ -295,8 +291,7 @@ def test_full_trace_and_replay_generation(self, compiled_workload: Path, tmp_pat
295291
workload_files = [f for f in test_files if "Workload" in f.name and "ConstructorAccess" not in f.name]
296292
assert len(workload_files) == 1
297293
content = workload_files[0].read_text(encoding="utf-8")
298-
assert "replay_computeSum" in content
299-
assert "replay_instanceMethod" in content
294+
assert "replay_repeatString" in content
300295

301296
def test_package_detection(self) -> None:
302297
"""Test that package detection finds Java packages from source files."""

tests/test_languages/test_java/test_java_tracer_integration.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def test_discover_functions_from_replay_tests(self, traced_workload: tuple) -> N
8787
assert func.language == "java", f"Expected language='java', got '{func.language}'"
8888
assert func.file_path == file_path
8989

90-
assert "computeSum" in all_func_names
9190
assert "repeatString" in all_func_names
9291

9392
def test_discover_tests_for_replay_tests(self, traced_workload: tuple) -> None:
@@ -111,7 +110,6 @@ def test_discover_tests_for_replay_tests(self, traced_workload: tuple) -> None:
111110
func_name = qualified_name.split(".")[-1] if "." in qualified_name else qualified_name
112111
matched_func_names.add(func_name)
113112

114-
assert "computeSum" in matched_func_names, f"computeSum not found in: {result.keys()}"
115113
assert "repeatString" in matched_func_names, f"repeatString not found in: {result.keys()}"
116114

117115
# Each function should have at least one test
@@ -222,8 +220,8 @@ def test_full_pipeline(self, compiled_workload: Path, tmp_path: Path) -> None:
222220
assert len(function_to_tests) > 0, "No function-to-test mappings"
223221

224222
# Verify function_to_tests has entries for our traced functions
225-
has_compute_sum = any("computeSum" in key for key in function_to_tests)
226-
assert has_compute_sum, f"computeSum not in function_to_tests keys: {list(function_to_tests.keys())}"
223+
has_repeat_string = any("repeatString" in key for key in function_to_tests)
224+
assert has_repeat_string, f"repeatString not in function_to_tests keys: {list(function_to_tests.keys())}"
227225

228226
# Step 4: Rank functions (like optimizer.rank_all_functions_globally)
229227
if jfr_file.exists():
@@ -280,7 +278,7 @@ def test_instrument_and_compile_replay_tests(self, compiled_workload: Path, tmp_
280278
source_code = WORKLOAD_SOURCE.read_text(encoding="utf-8")
281279
source_functions = discover_functions_from_source(source_code, file_path=WORKLOAD_SOURCE)
282280
# Pick the first function with a return type for instrumentation
283-
target_func = next(f for f in source_functions if f.function_name == "computeSum")
281+
target_func = next(f for f in source_functions if f.function_name == "repeatString")
284282

285283
replay_test_file = replay_test_paths[0]
286284
test_source = replay_test_file.read_text(encoding="utf-8")

0 commit comments

Comments
 (0)