Skip to content

Conversation

@shashankhs11
Copy link
Contributor

@shashankhs11 shashankhs11 commented Nov 15, 2025

Rewrote more tests in TaskManagerTest.java

Reviewers: Lucas Brutschy [email protected]

@github-actions github-actions bot added triage PRs from the community streams tests Test fixes (including flaky tests) labels Nov 15, 2025
@shashankhs11
Copy link
Contributor Author

@lucasbru, tagging for review :)

@lucasbru lucasbru requested a review from Copilot November 17, 2025 16:52
@lucasbru lucasbru self-assigned this Nov 17, 2025
@lucasbru lucasbru self-requested a review November 17, 2025 16:53
Copilot finished reviewing on behalf of lucasbru November 17, 2025 16:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request continues a series of test refactorings in TaskManagerTest.java, replacing tests that use StateMachineTask with tests that use mocked StreamTask instances created via the statefulTask builder pattern. This modernizes the testing approach to use better test utilities and mocking frameworks.

Key Changes:

  • Consolidated two separate tests (shouldComputeOffsetSumFromCheckpointFileForUninitializedTask and shouldComputeOffsetSumFromCheckpointFileForClosedTask) into a single parameterized test
  • Replaced multiple tests that used StateMachineTask with mocked StreamTask instances configured via builder pattern
  • Removed unused assertNull import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

when(task01.process(anyLong()))
.thenThrow(timeoutException.get()) // throws TimeoutException
.thenReturn(true)
.thenReturn(true)
.thenReturn(false);
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock behavior is evaluated at setup time, so timeoutException.get() will always return the TimeoutException. Setting timeoutException.set(null) on line 4218 won't change the mock's behavior. The second call to taskManager.process(1, time) will still throw the TimeoutException instead of processing records.

Consider using thenThrow(...).thenReturn(true).thenReturn(true).thenReturn(false) without the AtomicReference, or reconfigure the mock after clearing the timeout.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I don't think the atomic reference makes sense now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 931852e

Comment on lines 4218 to 4219
timeoutException.set(null);
assertThat(taskManager.process(1, time), is(3));
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting timeoutException.set(null) doesn't update the mock's behavior. The mock's thenThrow() at line 4198 was configured at setup time with the exception object and will continue to throw it. The test expects the retry on line 4219 to succeed, but it will still encounter the TimeoutException.

The test needs to either reconfigure the mock after line 4218 or avoid using the AtomicReference approach entirely.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - this is not working as you intended it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 931852e

@github-actions github-actions bot removed the triage PRs from the community label Nov 18, 2025
Copy link
Member

@lucasbru lucasbru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Minor comments only

when(task01.process(anyLong()))
.thenThrow(timeoutException.get()) // throws TimeoutException
.thenReturn(true)
.thenReturn(true)
.thenReturn(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I don't think the atomic reference makes sense now

Comment on lines 4218 to 4219
timeoutException.set(null);
assertThat(taskManager.process(1, time), is(3));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - this is not working as you intended it

mkEntry(new TopicPartition("changelog", 1), 10L)
);
final Map<TaskId, Long> expectedOffsetSums = mkMap(mkEntry(taskId00, 15L));
when(tasks.allTasksPerId()).thenReturn(mkMap(mkEntry(taskId00, task)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit weird that you add tasks to the stateUpdater first, and then mock it. I would reverse the order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! my bad, addressed in 931852e

@lucasbru lucasbru merged commit b2a9112 into apache:trunk Nov 20, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-approved streams tests Test fixes (including flaky tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants