Skip to content

Commit a65a833

Browse files
nomisRevserras
andauthored
Update Arrow-Atomic (#3225)
Co-authored-by: Alejandro Serrano <[email protected]>
1 parent 89205f6 commit a65a833

File tree

12 files changed

+171
-143
lines changed

12 files changed

+171
-143
lines changed

arrow-libs/core/arrow-annotations/build.gradle.kts

+2-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ spotless {
1313
}
1414
}
1515

16+
apply(from = property("ANIMALSNIFFER_MPP"))
17+
1618
kotlin {
1719
sourceSets {
1820
commonMain {
@@ -25,11 +27,6 @@ kotlin {
2527
implementation(libs.kotlin.stdlib)
2628
}
2729
}
28-
jvmTest {
29-
dependencies {
30-
runtimeOnly(libs.kotest.runnerJUnit5)
31-
}
32-
}
3330
jsMain {
3431
dependencies {
3532
implementation(libs.kotlin.stdlibJS)
@@ -45,5 +42,3 @@ kotlin {
4542
}
4643
}
4744
}
48-
49-
apply(from = property("ANIMALSNIFFER_MPP"))

arrow-libs/core/arrow-atomic/build.gradle.kts

+2-25
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
44

5-
65
plugins {
76
id(libs.plugins.kotlin.multiplatform.get().pluginId)
87
alias(libs.plugins.arrowGradleConfig.kotlin)
98
alias(libs.plugins.arrowGradleConfig.publish)
10-
11-
alias(libs.plugins.kotest.multiplatform)
129
alias(libs.plugins.kotlinx.kover)
1310
alias(libs.plugins.spotless)
1411
}
@@ -32,15 +29,10 @@ kotlin {
3229
commonTest {
3330
dependencies {
3431
implementation(projects.arrowFxCoroutines)
35-
implementation(libs.kotest.frameworkEngine)
32+
implementation(libs.kotlin.test)
3633
implementation(libs.kotest.assertionsCore)
3734
implementation(libs.kotest.property)
38-
}
39-
}
40-
41-
jvmTest {
42-
dependencies {
43-
runtimeOnly(libs.kotest.runnerJUnit5)
35+
implementation(libs.coroutines.test)
4436
}
4537
}
4638

@@ -55,21 +47,6 @@ kotlin {
5547
implementation(libs.kotlin.stdlibJS)
5648
}
5749
}
58-
59-
commonTest {
60-
dependencies {
61-
implementation(projects.arrowFxCoroutines)
62-
implementation(libs.kotest.frameworkEngine)
63-
implementation(libs.kotest.assertionsCore)
64-
implementation(libs.kotest.property)
65-
}
66-
}
67-
68-
jvmTest {
69-
dependencies {
70-
runtimeOnly(libs.kotest.runnerJUnit5)
71-
}
72-
}
7350
}
7451

7552
jvm {
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,52 @@
11
package arrow.atomic
22

3-
import arrow.fx.coroutines.parMap
4-
import io.kotest.core.spec.style.StringSpec
3+
import kotlin.test.Test
4+
import kotlinx.coroutines.test.runTest
55
import io.kotest.matchers.shouldBe
66
import io.kotest.property.Arb
77
import io.kotest.property.arbitrary.boolean
8-
import io.kotest.property.arbitrary.int
9-
import io.kotest.property.arbitrary.long
10-
import io.kotest.property.arbitrary.string
118
import io.kotest.property.checkAll
12-
import kotlin.coroutines.Continuation
13-
import kotlin.coroutines.EmptyCoroutineContext
14-
import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn
159

16-
class AtomicBooleanTest : StringSpec({
10+
class AtomicBooleanTest {
1711

18-
"set get - successful" {
12+
@Test
13+
fun setGetSuccessful() = runTest {
1914
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
2015
val r = AtomicBoolean(x)
2116
r.value = y
2217
r.value shouldBe y
2318
}
2419
}
2520

26-
"update get - successful" {
21+
@Test
22+
fun updateGetSuccessful() = runTest {
2723
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
2824
val r = AtomicBoolean(x)
2925
r.update { y }
3026
r.value shouldBe y
3127
}
3228
}
3329

34-
"getAndSet - successful" {
30+
@Test
31+
fun getAndSetSuccessful() = runTest {
3532
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
3633
val ref = AtomicBoolean(x)
3734
ref.getAndSet(y) shouldBe x
3835
ref.value shouldBe y
3936
}
4037
}
4138

42-
"getAndUpdate - successful" {
39+
@Test
40+
fun getAndUpdateSuccessful() = runTest {
4341
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
4442
val ref = AtomicBoolean(x)
4543
ref.getAndUpdate { y } shouldBe x
4644
ref.value shouldBe y
4745
}
4846
}
4947

50-
"updateAndGet - successful" {
48+
@Test
49+
fun updateAndGetSuccessful() = runTest {
5150
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
5251
val ref = AtomicBoolean(x)
5352
ref.updateAndGet {
@@ -57,15 +56,17 @@ class AtomicBooleanTest : StringSpec({
5756
}
5857
}
5958

60-
"tryUpdate - modification occurs successfully" {
59+
@Test
60+
fun tryUpdateModificationOccursSuccessfully() = runTest {
6161
checkAll(Arb.boolean()) { x ->
6262
val ref = AtomicBoolean(x)
6363
ref.tryUpdate { !it }
6464
ref.value shouldBe !x
6565
}
6666
}
6767

68-
"tryUpdate - should fail to update if modification has occurred" {
68+
@Test
69+
fun tryUpdateShouldFailToUpdateIfModificationHasOccurred() = runTest {
6970
checkAll(Arb.boolean()) { x ->
7071
val ref = AtomicBoolean(x)
7172
ref.tryUpdate {
@@ -75,7 +76,8 @@ class AtomicBooleanTest : StringSpec({
7576
}
7677
}
7778

78-
"consistent set update on strings" {
79+
@Test
80+
fun consistentSetUpdateOnStrings() = runTest {
7981
checkAll(Arb.boolean(), Arb.boolean()) { x, y ->
8082
val set = {
8183
val r = AtomicBoolean(x)
@@ -92,4 +94,4 @@ class AtomicBooleanTest : StringSpec({
9294
set() shouldBe update()
9395
}
9496
}
95-
})
97+
}

arrow-libs/core/arrow-atomic/src/commonTest/kotlin/arrow/atomic/AtomicIntTest.kt

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
11
package arrow.atomic
22

33
import arrow.fx.coroutines.parMap
4-
import io.kotest.core.spec.style.StringSpec
4+
import kotlin.test.Test
5+
import kotlinx.coroutines.test.runTest
56
import io.kotest.matchers.shouldBe
67
import io.kotest.property.Arb
78
import io.kotest.property.arbitrary.int
8-
import io.kotest.property.arbitrary.string
99
import io.kotest.property.checkAll
10-
import kotlin.coroutines.Continuation
11-
import kotlin.coroutines.EmptyCoroutineContext
12-
import kotlin.coroutines.intrinsics.startCoroutineUninterceptedOrReturn
1310

14-
class AtomicIntTest : StringSpec({
11+
class AtomicIntTest {
1512

16-
"set get - successful" {
13+
@Test
14+
fun setGetSuccessful() = runTest {
1715
checkAll(Arb.int(), Arb.int()) { x, y ->
1816
val r = AtomicInt(x)
1917
r.value = y
2018
r.value shouldBe y
2119
}
2220
}
2321

24-
"update get - successful" {
22+
@Test
23+
fun updateGetSuccessful() = runTest {
2524
checkAll(Arb.int(), Arb.int()) { x, y ->
2625
val r = AtomicInt(x)
2726
r.update { y }
2827
r.value shouldBe y
2928
}
3029
}
3130

32-
"getAndSet - successful" {
31+
@Test
32+
fun getAndSetSuccessful() = runTest {
3333
checkAll(Arb.int(), Arb.int()) { x, y ->
3434
val ref = AtomicInt(x)
3535
ref.getAndSet(y) shouldBe x
3636
ref.value shouldBe y
3737
}
3838
}
3939

40-
"getAndUpdate - successful" {
40+
@Test
41+
fun getAndUpdateSuccessful() = runTest {
4142
checkAll(Arb.int(), Arb.int()) { x, y ->
4243
val ref = AtomicInt(x)
4344
ref.getAndUpdate { y } shouldBe x
4445
ref.value shouldBe y
4546
}
4647
}
4748

48-
"updateAndGet - successful" {
49+
@Test
50+
fun updateAndGetSuccessful() = runTest {
4951
checkAll(Arb.int(), Arb.int()) { x, y ->
5052
val ref = AtomicInt(x)
5153
ref.updateAndGet {
@@ -55,15 +57,17 @@ class AtomicIntTest : StringSpec({
5557
}
5658
}
5759

58-
"tryUpdate - modification occurs successfully" {
60+
@Test
61+
fun tryUpdateModificationOccursSuccessfully() = runTest {
5962
checkAll(Arb.int()) { x ->
6063
val ref = AtomicInt(x)
6164
ref.tryUpdate { it + 1 }
6265
ref.value shouldBe x + 1
6366
}
6467
}
6568

66-
"tryUpdate - should fail to update if modification has occurred" {
69+
@Test
70+
fun tryUpdateShouldFailToUpdateIfModificationHasOccurred() = runTest {
6771
checkAll(Arb.int()) { x ->
6872
val ref = AtomicInt(x)
6973
ref.tryUpdate {
@@ -73,7 +77,8 @@ class AtomicIntTest : StringSpec({
7377
}
7478
}
7579

76-
"consistent set update on strings" {
80+
@Test
81+
fun consistentSetUpdateOnStrings() = runTest {
7782
checkAll(Arb.int(), Arb.int()) { x, y ->
7883
val set = {
7984
val r = AtomicInt(x)
@@ -91,11 +96,11 @@ class AtomicIntTest : StringSpec({
9196
}
9297
}
9398

94-
"concurrent modifications" {
95-
val finalValue = 50_000
99+
@Test
100+
fun concurrentModifications() = runTestWithDelay {
101+
val finalValue = stackSafeIteration()
96102
val r = AtomicInt(0)
97103
(0 until finalValue).parMap { r.update { it + 1 } }
98104
r.value shouldBe finalValue
99105
}
100106
}
101-
)

0 commit comments

Comments
 (0)