@@ -16,7 +16,7 @@ import kotlinx.coroutines.flow.flowOf
16
16
import kotlinx.coroutines.flow.toList
17
17
import kotlin.time.Duration
18
18
import kotlin.time.Duration.Companion.milliseconds
19
- import kotlin.time.Duration.Companion.seconds
19
+ import kotlin.time.Duration.Companion.minutes
20
20
import kotlin.time.measureTime
21
21
import kotlin.time.measureTimedValue
22
22
@@ -45,7 +45,9 @@ class FlowAsyncExtKtTest : FunSpec({
45
45
it * 2
46
46
}
47
47
48
- retry(5, 20.seconds) {
48
+ // The high max retries is due to macOS incredibly slow build on GH Actions
49
+ // It causes the test to slow down, so time-related tests get quite unpredictable
50
+ retry(20, 1.minutes) {
49
51
val counter = AtomicReference (0)
50
52
51
53
sourceFlow
@@ -61,18 +63,19 @@ class FlowAsyncExtKtTest : FunSpec({
61
63
62
64
// Measure the time taken to receive two items
63
65
measureTime {
64
- // First item should be received in >= 500 ms & <= 520 ms
66
+ // First item should be received in >= 500 ms & <= 600 ms
65
67
assertSoftly(ensureNext()) { duration ->
66
68
duration shouldBeGreaterThan 480 .milliseconds
67
- duration shouldBeLessThanOrEqualTo 520 .milliseconds
69
+ // Once again, this is due to macOS slow builds on GH Actions
70
+ duration shouldBeLessThanOrEqualTo 600 .milliseconds
68
71
}
69
72
70
73
repeat(9) {
71
74
// The other 9 items should be almost immediate
72
- ensureNext() shouldNotBeGreaterThan 6 .milliseconds
75
+ ensureNext() shouldNotBeGreaterThan 10 .milliseconds
73
76
}
74
77
75
- } shouldBeLessThanOrEqualTo 550 .milliseconds
78
+ } shouldBeLessThanOrEqualTo 650 .milliseconds
76
79
}
77
80
78
81
awaitComplete()
@@ -81,7 +84,7 @@ class FlowAsyncExtKtTest : FunSpec({
81
84
}
82
85
83
86
test("unorderedMapAsync should correctly transform each element") {
84
- val sourceFlow = flowOf(100, 50, 10 )
87
+ val sourceFlow = flowOf(500, 100, 5 )
85
88
86
89
val result =
87
90
sourceFlow
@@ -92,22 +95,22 @@ class FlowAsyncExtKtTest : FunSpec({
92
95
.toList()
93
96
94
97
/* *
95
- * The assertion shouldContainInOrder expects the elements in the specific order [100, 20, 200 ].
98
+ * The assertion shouldContainInOrder expects the elements in the specific order [200, 10, 1000 ].
96
99
*
97
100
* Despite the function being unordered, in this specific case, the output will be ordered due to the
98
101
* interplay of processing times and concurrency limit.
99
102
*
100
103
* Lemme explain how it works exactly:
101
104
*
102
- * - The first element (100 ) will start processing and take 100 milliseconds.
103
- * - Meanwhile, the second element (50 ) starts and finishes in 50 milliseconds.
104
- * - The third element (10 ) starts processing after the second but finishes quickly in 10 milliseconds.
105
- * - By the time the first element (100 ) finishes, the other two are already done.
105
+ * - The first element (500 ) will start processing and take 500 milliseconds.
106
+ * - Meanwhile, the second element (100 ) starts and finishes in 100 milliseconds.
107
+ * - The third element (5 ) starts processing after the second but finishes quickly in 5 milliseconds.
108
+ * - By the time the first element (500 ) finishes, the other two are already done.
106
109
*
107
- * So, the order of completion is 50 (20 after transformation), 10 (20 after transformation),
108
- * and finally 100 (200 after transformation).
110
+ * So, the order of completion is 100 (200 after transformation), 5 (10 after transformation),
111
+ * and finally 500 (1000 after transformation).
109
112
*/
110
- result shouldContainInOrder listOf(100, 20, 200 )
113
+ result shouldContainInOrder listOf(200, 10, 1000 )
111
114
}
112
115
113
116
test("flatMapIterableAsync should correctly transform and flatten each element") {
@@ -126,7 +129,7 @@ class FlowAsyncExtKtTest : FunSpec({
126
129
}
127
130
128
131
test("unorderedFlatMapIterableAsync should correctly transform and flatten each element with specific processing times") {
129
- val sourceFlow = flowOf(100, 50, 10 )
132
+ val sourceFlow = flowOf(500, 100, 5 )
130
133
131
134
val result =
132
135
sourceFlow
@@ -137,21 +140,21 @@ class FlowAsyncExtKtTest : FunSpec({
137
140
.toList()
138
141
139
142
/* *
140
- * The assertion shouldContainInOrder expects the elements in the specific order [100, 20, 200 ].
143
+ * The assertion shouldContainInOrder expects the elements in the specific order [100, 200, 5, 10, 500, 1000 ].
141
144
*
142
145
* Despite the function being unordered, in this specific case, the output will be ordered due to the
143
146
* interplay of processing times and concurrency limit.
144
147
*
145
148
* Lemme explain how it works exactly:
146
149
*
147
- * - The first element (100 ) will start processing and take 100 milliseconds.
148
- * - Meanwhile, the second element (50 ) starts and finishes in 50 milliseconds.
149
- * - The third element (10 ) starts processing after the second but finishes quickly in 10 milliseconds.
150
- * - By the time the first element (100 ) finishes, the other two are already done.
150
+ * - The first element (500 ) will start processing and take 500 milliseconds.
151
+ * - Meanwhile, the second element (100 ) starts and finishes in 100 milliseconds.
152
+ * - The third element (5 ) starts processing after the second but finishes quickly in 5 milliseconds.
153
+ * - By the time the first element (500 ) finishes, the other two are already done.
151
154
*
152
- * So, the order of completion is 50 (100 after transformation), 10 (20 after transformation),
153
- * and finally 100 (200 after transformation).
155
+ * So, the order of completion is 100 (200 after transformation), 5 (10 after transformation),
156
+ * and finally 500 (1000 after transformation).
154
157
*/
155
- result shouldContainInOrder listOf(50, 100, 10, 20, 100, 200 )
158
+ result shouldContainInOrder listOf(100, 200, 5, 10, 500, 1000 )
156
159
}
157
160
})
0 commit comments