https://kotlinlang.org logo
#kotest
Title
# kotest
k

Kweku

04/08/2021, 11:56 PM
Having a weird issue with Arbs and IOS. Basically Using arbs in iOS tests is resulting in an InvalidMutabilityEcception on XorWowRandom. Something like
Arb.long
is fine but using it in
checkAll
for example or doing something like
arb.long.take(1)
results in the exception I'm using property testing but not the framework.
s

sam

04/09/2021, 12:04 AM
Probably the random is not thread safe
k

Kweku

04/09/2021, 2:07 PM
Yeah using take where you pass in a RandomSource works so it is possibly to do with the random, but the issue happens on a normal test with no coroutines etc involved
s

sam

04/09/2021, 2:40 PM
are you running any tests in parallel ?
k

Kweku

04/09/2021, 3:33 PM
I don't think so, just running the iOS test via the gutter icon
Heres the stacktrace
kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.random.XorWowRandom@2c52d248
kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.random.XorWowRandom@2c52d248
at kotlin.Throwable#<init>(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/Throwable.kt:23)
at kotlin.Exception#<init>(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/Exceptions.kt:23)
at kotlin.RuntimeException#<init>(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/Exceptions.kt:34)
at kotlin.native.concurrent.InvalidMutabilityException#<init>(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:22)
at <global>.ThrowInvalidMutabilityException(/Users/teamcity1/teamcity_work/11ac87a349af04d5/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:93)
at <global>.MutationCheck(Unknown Source)
at kotlin.random.XorWowRandom.<set-x>#internal(/Users/teamcity1/teamcity_work/11ac87a349af04d5/backend.native/build/stdlib/kotlin/random/XorWowRandom.kt:20)
at kotlin.random.XorWowRandom#nextInt(/Users/teamcity1/teamcity_work/11ac87a349af04d5/backend.native/build/stdlib/kotlin/random/XorWowRandom.kt:43)
at kotlin.random.Random#nextLong(/Users/teamcity1/teamcity_work/11ac87a349af04d5/backend.native/build/stdlib/kotlin/random/Random.kt:95)
at kotlin.random#nextLong@kotlin.random.Random(/Users/teamcity1/teamcity_work/11ac87a349af04d5/backend.native/build/stdlib/kotlin/random/Random.kt:358)
at io.kotest.property.arbitrary.long$lambda-0#internal(/Users/runner/work/kotest/kotest/kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/longs.kt:22)
at io.kotest.property.arbitrary.$long$lambda-0$FUNCTION_REFERENCE$107.invoke#internal(/Users/runner/work/kotest/kotest/kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/longs.kt:22)
at io.kotest.property.arbitrary.$long$lambda-0$FUNCTION_REFERENCE$107.$<bridge-BNNN>invoke(/Users/runner/work/kotest/kotest/kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/longs.kt:22)
at io.kotest.property.arbitrary.object-8.values$lambda-0#internal(/Users/runner/work/kotest/kotest/kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/builders.kt:30)
at io.kotest.property.arbitrary.object-8.$values$lambda-0$FUNCTION_REFERENCE$42.invoke#internal(/Users/runner/work/kotest/kotest/kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/builders.kt:30)
at kotlin.sequences.GeneratorSequence.object-1.calcNext#internal(/Users/teamcity1/teamcity_work/11ac87a349af04d5/backend.native/build/stdlib/kotlin/collections/Sequences.kt:591)
at kotlin.sequences.GeneratorSequence.object-1.hasNext#internal(/Users/teamcity1/teamcity_work/11ac87a349af04d5/backend.native/build/stdlib/kotlin/collections/Sequences.kt:609)
at io.kotest.property.Arb#samples(/Users/runner/work/kotest/kotest/kotest-property/src/commonMain/kotlin/io/kotest/property/Gen.kt:85)
at io.kotest.property.arbitrary#take@io.kotest.property.Arb<0:0>(/Users/runner/work/kotest/kotest/kotest-property/src/commonMain/kotlin/io/kotest/property/arbitrary/arbs.kt:10)
at io.kotest.property.arbitrary#take$default@io.kotest.property.Arb<0:0>
s

sam

04/09/2021, 3:42 PM
Are you passing in your own random
k

Kweku

04/09/2021, 3:59 PM
Passing in a my own Random source and Random works e.g
Copy code
Arb.long().take(1, RandomSource(Random(1),1))
both in a normal test and a runblocking test but
Arb.long().take()
causes an exception My original usage was just using arbs in checkAll which causes exceptions on IOS. I started calling take to try and work out where the issue was
s

sam

04/09/2021, 4:11 PM
interesting
what about if you create that random source first
and then try to use it multiple times, in say a loop
I don't a mac so I can't test ios, I'm just thinking out loud to help narrow it down
k

Kweku

04/09/2021, 4:14 PM
CheckAll also works if I pass in
PropTestConfig
with a seed specified
s

sam

04/09/2021, 4:20 PM
Can you create an issue ?
I think I know how to fix
I'm hoping that fixes it
8 Views