question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Invoking a mock too many times leads to halting execution

See original GitHub issue

Expected Behavior

Invoking a mockk should never cause a test to hang. If too many invocations lead to performance issues, it would be better to either:

  • throw an exception once a reasonable cap is reached
  • rotate away old data

Current Behavior

After invoking a mock around 130 000 times (on my machine, running JDK 15 on Windows) further invocations will hit a wall and take forever (minutes) to finish.

Steps to Reproduce

I made a small reproduction repo here: https://github.com/Kantis/mockk-repro

  1. Run ./gradlew test -i and you’ll see some output as the mock is invoked over and over until it causes problems.

Context

  • MockK version: 1.11.0
  • OS: Windows
  • Kotlin version: 1.5.10 (Also applies to 1.4.32)
  • JDK version: 15
  • ~JUnit version~ Kotest: 4.6.0
  • Type of test: Unit test

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11

github_iconTop GitHub Comments

2reactions
Raibazcommented, Jun 3, 2021

This shouldn’t be too hard to fix, it should be just a matter of setting a cap to the size of recorded calls and throwing a clear enough exception when the size exceeds a threshold.

(It should be a very rare case though)

0reactions
stale[bot]commented, Aug 28, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as stale just ask to put an important label.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simulate first call fails, second call succeeds - Stack Overflow
This is useful if you need to mock the same thing several times, or mock in some pattern. Eg (albeit a farfetched one):...
Read more >
unittest.mock — mock object library — Python 3.11.1 ...
This is a list of all the calls made to the mock object in sequence (so the length of the list is the...
Read more >
What Is Google C++ Mocking Framework?
A mock object implements the same interface as a real object (so it can be used as one), but lets you specify at...
Read more >
Python Mocking 101: Fake It Before You Make It - Fugue
In Python, mocking is accomplished through the unittest.mock module. ... so I'll be calling update multiple times, and making multiple calls ...
Read more >
The only 3 steps you need to mock an API call in Jest
Use this newfound power to give your functions exactly what they should expect from the API calls. Stop worrying about what the network...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found