Skip to content

mockk is not threadsafe!!!! #1062

@aozmen121

Description

@aozmen121

Prerequisites
Please answer the following questions for yourself before submitting an issue.

[ ✔️ ] I am running the latest version
[ ✔️ ] I checked the documentation and found no answer
[ ✔️ ] I checked to make sure that this issue has not already been filed

Expected Behavior
Whenever tests are ran in a multithreaded execution, threads executing mockkStatic with the same class should not cancel another threads mockkStatic. ie. mockkStatic should have thread local scope.

Current Behavior
Whenever tests are ran in a multithreaded execution, mockkStatic results in a race condition where multiple threads executing tests may cancel mockkStatic's set by other threads resulting in undefined behavior.

Failure Information (for bugs)
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

Steps to Reproduce
Please provide detailed steps for reproducing the issue.

Write two test cases which use mockkStatic on the same class.
Execute test cases in JUnit parallel execution mode.
Tests will result in undefined behavior due threads cancelling each others mockkStatic.

Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

MockK version: V1.13.4
OS: Windows 10
Kotlin version: 1.6.0
JDK version: Azul 11
Minimal reproducible code (the gist of this issue)
See the following github repo: https://github.com/willpxxr/mockkstatic

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions