Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concurrent invocations of InvocationRecorder #144

Merged
merged 2 commits into from
Dec 1, 2023

Conversation

carlonzo
Copy link
Collaborator

recorder and responses maps access where not threadsafe

}

val commonTest by getting {
dependencies {
implementation(libs.kotlin.test)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

kotlin test was a production library :(

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

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

keep also in mind that mockingbird is a testing library as well, clients should use mockingbird as a test library

@@ -18,14 +18,10 @@ package com.careem.mockingbird.test

import kotlinx.atomicfu.AtomicInt
import kotlinx.atomicfu.atomic
import kotlin.native.concurrent.SharedImmutable
import kotlin.test.assertEquals
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

:(



@SharedImmutable
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

SharedImmutable is ignored with the new memory model

* @param uuid the uuid of the mock
* @param invocation the Invocation object @see [Invocation]
*/
fun storeInvocation(uuid: String, invocation: Invocation) {
if (!recorder.containsKey(uuid)) {
recorder[uuid] = mutableListOf()
recorder.block { map ->
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

block will sync the call to the map

@@ -151,6 +147,16 @@ internal fun <T : Mock> T.rawVerify(
}
}

private fun assertEquals(
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't find usage of this function. Where can it be used if it is private?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

line 138. was using the function from kotlin.test

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure I would change this, why not keeping the kotlin test? Mockingbird is a test library it shouldn't be used in production code anyway

internal class InvocationRecorder {

private val recorder = mutableMapOf<String, MutableList<Invocation>>()
private val responses = mutableMapOf<String, LinkedHashMap<Invocation, (Invocation) -> Any?>>()
private val recorder = ConcurrentMutableMap<String, MutableList<Invocation>>()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks

@minaEweida minaEweida merged commit e2dde37 into master Dec 1, 2023
1 check passed
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.

3 participants