Skip to content

Commit

Permalink
Increasing timeouts to make GH actions happy
Browse files Browse the repository at this point in the history
  • Loading branch information
gabfssilva committed Feb 27, 2024
1 parent b1b78f0 commit 5c318e4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ jobs:
path: :connector:connector-aws
containers: localstack
runner: macos-latest
task: test
gradle-command: >
:connector:connector-aws:connector-aws-lambda:test
:connector:connector-aws:connector-aws-s3:test
:connector:connector-aws:connector-aws-sqs:test
:connector:connector-aws:connector-aws-sns:test
:connector:connector-aws:connector-aws-ses:test
- module: Azure Queue Storage
path: :connector:connector-azure:connector-azure-queue-storage
containers: azurite
Expand Down Expand Up @@ -95,7 +100,10 @@ jobs:
with:
java-version: '17'
distribution: 'temurin'
- name: Set up Gradle
uses: gradle/gradle-setup-action@v3
- name: Run tests for ${{ matrix.module }}
uses: gradle/gradle-build-action@v3
with:
arguments: ${{ matrix.path }}:${{ matrix.task || 'allTests' }}
env:
task: ${{ matrix.path }}:${{ matrix.task || 'allTests' }}
run: |
./gradlew ${{ matrix.gradle-command || env.task }}
51 changes: 27 additions & 24 deletions core/src/commonTest/kotlin/com/river/core/FlowAsyncExtKtTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.toList
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.measureTime
import kotlin.time.measureTimedValue

Expand Down Expand Up @@ -45,7 +45,9 @@ class FlowAsyncExtKtTest : FunSpec({
it * 2
}

retry(5, 20.seconds) {
// The high max retries is due to macOS incredibly slow build on GH Actions
// It causes the test to slow down, so time-related tests get quite unpredictable
retry(20, 1.minutes) {
val counter = AtomicReference(0)

sourceFlow
Expand All @@ -61,18 +63,19 @@ class FlowAsyncExtKtTest : FunSpec({

// Measure the time taken to receive two items
measureTime {
// First item should be received in >= 500 ms & <= 520 ms
// First item should be received in >= 500 ms & <= 600 ms
assertSoftly(ensureNext()) { duration ->
duration shouldBeGreaterThan 480.milliseconds
duration shouldBeLessThanOrEqualTo 520.milliseconds
// Once again, this is due to macOS slow builds on GH Actions
duration shouldBeLessThanOrEqualTo 600.milliseconds
}

repeat(9) {
// The other 9 items should be almost immediate
ensureNext() shouldNotBeGreaterThan 6.milliseconds
ensureNext() shouldNotBeGreaterThan 10.milliseconds
}

} shouldBeLessThanOrEqualTo 550.milliseconds
} shouldBeLessThanOrEqualTo 650.milliseconds
}

awaitComplete()
Expand All @@ -81,7 +84,7 @@ class FlowAsyncExtKtTest : FunSpec({
}

test("unorderedMapAsync should correctly transform each element") {
val sourceFlow = flowOf(100, 50, 10)
val sourceFlow = flowOf(500, 100, 5)

val result =
sourceFlow
Expand All @@ -92,22 +95,22 @@ class FlowAsyncExtKtTest : FunSpec({
.toList()

/**
* The assertion shouldContainInOrder expects the elements in the specific order [100, 20, 200].
* The assertion shouldContainInOrder expects the elements in the specific order [200, 10, 1000].
*
* Despite the function being unordered, in this specific case, the output will be ordered due to the
* interplay of processing times and concurrency limit.
*
* Lemme explain how it works exactly:
*
* - The first element (100) will start processing and take 100 milliseconds.
* - Meanwhile, the second element (50) starts and finishes in 50 milliseconds.
* - The third element (10) starts processing after the second but finishes quickly in 10 milliseconds.
* - By the time the first element (100) finishes, the other two are already done.
* - The first element (500) will start processing and take 500 milliseconds.
* - Meanwhile, the second element (100) starts and finishes in 100 milliseconds.
* - The third element (5) starts processing after the second but finishes quickly in 5 milliseconds.
* - By the time the first element (500) finishes, the other two are already done.
*
* So, the order of completion is 50 (20 after transformation), 10 (20 after transformation),
* and finally 100 (200 after transformation).
* So, the order of completion is 100 (200 after transformation), 5 (10 after transformation),
* and finally 500 (1000 after transformation).
*/
result shouldContainInOrder listOf(100, 20, 200)
result shouldContainInOrder listOf(200, 10, 1000)
}

test("flatMapIterableAsync should correctly transform and flatten each element") {
Expand All @@ -126,7 +129,7 @@ class FlowAsyncExtKtTest : FunSpec({
}

test("unorderedFlatMapIterableAsync should correctly transform and flatten each element with specific processing times") {
val sourceFlow = flowOf(100, 50, 10)
val sourceFlow = flowOf(500, 100, 5)

val result =
sourceFlow
Expand All @@ -137,21 +140,21 @@ class FlowAsyncExtKtTest : FunSpec({
.toList()

/**
* The assertion shouldContainInOrder expects the elements in the specific order [100, 20, 200].
* The assertion shouldContainInOrder expects the elements in the specific order [100, 200, 5, 10, 500, 1000].
*
* Despite the function being unordered, in this specific case, the output will be ordered due to the
* interplay of processing times and concurrency limit.
*
* Lemme explain how it works exactly:
*
* - The first element (100) will start processing and take 100 milliseconds.
* - Meanwhile, the second element (50) starts and finishes in 50 milliseconds.
* - The third element (10) starts processing after the second but finishes quickly in 10 milliseconds.
* - By the time the first element (100) finishes, the other two are already done.
* - The first element (500) will start processing and take 500 milliseconds.
* - Meanwhile, the second element (100) starts and finishes in 100 milliseconds.
* - The third element (5) starts processing after the second but finishes quickly in 5 milliseconds.
* - By the time the first element (500) finishes, the other two are already done.
*
* So, the order of completion is 50 (100 after transformation), 10 (20 after transformation),
* and finally 100 (200 after transformation).
* So, the order of completion is 100 (200 after transformation), 5 (10 after transformation),
* and finally 500 (1000 after transformation).
*/
result shouldContainInOrder listOf(50, 100, 10, 20, 100, 200)
result shouldContainInOrder listOf(100, 200, 5, 10, 500, 1000)
}
})
4 changes: 2 additions & 2 deletions core/src/commonTest/kotlin/com/river/core/FlowExtKtTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class FlowExtKtTest : FunSpec({

test("should transform the flow into a list based on the time window") {
flowOf(2, 4, 6, 8, 10, 12, 14, 16)
.onEach { delay(190) }
.toList(10, 600.milliseconds) shouldBe listOf(2, 4, 6)
.onEach { delay(300) }
.toList(10, 1150.milliseconds) shouldBe listOf(2, 4, 6)
}

test("should chunk the items based on the count") {
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
org.gradle.jvmargs=-Xmx4096M
kotlin.mpp.androidSourceSetLayoutVersion=2
org.gradle.caching=true
org.gradle.configureondemand=true

0 comments on commit 5c318e4

Please sign in to comment.