Bug: Invoking a mock too many times leads to halting execution
See original GitHub issueExpected 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
- 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:
- Created 2 years ago
- Comments:11
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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)
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 animportant
label.