Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Conversation

@rsvinicius
Copy link
Contributor

🚧 Draft Pull Request – Partial Fix for Issue #1379

This PR builds upon the changes introduced in #821, aiming to improve test isolation while addressing the regression reported in #1379.

πŸ›  What's Being Done

  • Refactored internalConfirmVerified to reset only the specified mocks when parameters are passed.
  • Updated resetVerificationState to selectively clear verification state for specific mocks.
  • Ensured cleanup with try-finally, making the verification process more robust.
  • Added a test case confirmVerifiedSpecificMock to verify that confirmVerified(mock) behavior is correct.

⚠️ Current Status

This PR is still in progress. While the targeted clearing works in isolated tests, the test suite fails when running confirmVerifiedAll.

This issue appears similar to the cross-test interference previously addressed in issue #821, but now occurs when confirmVerified is used without parameters after using it with specific mocks in other tests.

πŸ‘‰ Notably, if we add a clearAllMocks() call before the confirmVerifiedAll test, it passes successfully β€” just like it did before PR #1367.

πŸ” Next Steps

Investigate and resolve the failure of confirmVerifiedAll in the full test suite

@Raibaz do you have any idea why this might be happening? It seems related to state retention when mixing confirmVerified(mock) and confirmVerified() in different tests.


MockKGateway.implementation().clearer.clearAll(options, currentThreadOnly = true)
if (mocks.isEmpty()) {
implementation.clearer.clearAll(options, false)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this changed from true to false?

Copy link
Contributor Author

@rsvinicius rsvinicius Apr 22, 2025

Choose a reason for hiding this comment

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

To be honest, I’m not entirely sure which value is more appropriate here. I noticed that clearAllMocks by default uses currentThreadOnly = false, so I followed that behavior for consistency. But if there's a specific reason it should be true, I’m happy to revisit this.

@Raibaz
Copy link
Collaborator

Raibaz commented Apr 22, 2025

Wild guess: could it be that verify with more than one call, such as the one in the confirmVerifiedAll test, don't add the right values to the list of verified calls?

Can you check the values of allCalls and verifiedCalls here, when your test fails?

@rsvinicius
Copy link
Contributor Author

Wild guess: could it be that verify with more than one call, such as the one in the confirmVerifiedAll test, don't add the right values to the list of verified calls?

I don’t think that’s the root cause, because when the confirmVerifiedAll test is run in isolation, it passes β€” so it seems that verify { ... } with multiple calls is working as expected in that context.

However, when the whole test suite is executed, the same test fails. That suggests some shared state leakage or interference between tests, similar to what we saw before the fix for #821.

Can you check the values of allCalls and verifiedCalls here, when your test fails?

Yes β€” I added debug prints and here’s what I found during a failing run (screenshot attached below). So it looks like the verifiedCalls list gets cleared unexpectedly across tests. Interestingly, if I add a clearAllMocks() at the beginning of the confirmVerifiedAll test, it passes β€” just like it used to before PR #1367.

image

@Raibaz
Copy link
Collaborator

Raibaz commented Apr 28, 2025

That's interesting - I'd do more investigation to understand who's clearing the verifiedCalls list, when and why :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants