Skip to content

Commit

Permalink
Merge pull request #14 from crowdproj/8-unordered-processing-of-worke…
Browse files Browse the repository at this point in the history
…rs-in-subchain

8 unordered processing of workers in subchain
  • Loading branch information
svok authored Oct 5, 2022
2 parents 0be2c81 + 102f2e6 commit 0fa1969
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ on:
jobs:
# This workflow contains a single job called "build"
build:
# runs-on: ubuntu-latest
runs-on: macos-latest
runs-on: ubuntu-latest
# runs-on: macos-latest
steps:
- uses: actions/checkout@v3

Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
java-version: '11'
distribution: 'temurin'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
uses: gradle/wrapper-validation-action@v1
- name: Decode
run: |
mkdir -p ~/.gradle
Expand All @@ -48,11 +48,11 @@ jobs:
# NEXUS_USER: ${{ secrets.OSSRH_USER }}
# NEXUS_PASS: ${{ secrets.OSSRH_PASS }}
## GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Report unit tests
uses: dorny/test-reporter@v1
if: always()
with:
name: Gradle Tests
path: '**/build/test-results/*/TEST-*.xml'
reporter: java-junit
fail-on-error: true
# - name: Report unit tests
# uses: dorny/test-reporter@v1
# if: always()
# with:
# name: Gradle Tests
# path: '**/build/test-results/*/TEST-*.xml'
# reporter: java-junit
# fail-on-error: true
38 changes: 38 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ kotlin {

sourceSets {
val coroutinesVersion: String by project
val atomicfuVersion: String by project

all { languageSettings.optIn("kotlin.RequiresOptIn") }

Expand All @@ -74,6 +75,7 @@ kotlin {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion")
implementation("org.jetbrains.kotlinx:atomicfu:$atomicfuVersion")
}
}

Expand Down Expand Up @@ -195,6 +197,7 @@ tasks {
reports {
junitXml.required.set(true)
}
setupTestLogging()
}

publish {
Expand All @@ -208,3 +211,38 @@ tasks {
}

}

fun Test.setupTestLogging() {
testLogging {
events(
org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED,
org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED,
org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED,
org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_OUT,
)
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true

addTestListener(object : TestListener {
override fun beforeSuite(suite: TestDescriptor) {}
override fun beforeTest(testDescriptor: TestDescriptor) {}
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {}
override fun afterSuite(suite: TestDescriptor, result: TestResult) {
if (suite.parent != null) { // will match the outermost suite
val output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
val startItem = "| "
val endItem = " |"
val repeatLength = startItem.length + output.length + endItem.length
val messages = """
${(1..repeatLength).joinToString("") { "-" }}
$startItem$output$endItem
${(1..repeatLength).joinToString("") { "-" }}
""".trimIndent()
println(messages)
}
}
})
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
kotlinVersion=1.7.10

coroutinesVersion=1.6.3
atomicfuVersion=0.18.3
nexusStagingVersion=0.30.0

# -native-mt
4 changes: 4 additions & 0 deletions src/commonTest/kotlin/helper/TestContext.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.crowdproj.kotlin.cor.helper

import kotlinx.atomicfu.AtomicRef
import kotlinx.atomicfu.atomic

data class TestContext(
var status: CorStatuses = CorStatuses.NONE,
var some: Int = Int.MIN_VALUE,
var text: String = "",
val atomicText: AtomicRef<String> = atomic("")
) {

}
11 changes: 6 additions & 5 deletions src/commonTest/kotlin/subChain/SubChainSequentialTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.crowdproj.kotlin.cor.handlers.worker
import com.crowdproj.kotlin.cor.helper.TestContext
import com.crowdproj.kotlin.cor.helper.TestSubContext
import com.crowdproj.kotlin.cor.rootChain
import kotlinx.atomicfu.update
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -38,7 +39,7 @@ class SubChainSequentialTest {
chain.exec(ctx)
}
println("TIME: $t")
assertEquals("0;1;2;3;4;5;6;7;8;9;", ctx.text)
assertEquals("0;1;2;3;4;5;6;7;8;9;", ctx.atomicText.value)
}
}

Expand All @@ -50,7 +51,7 @@ class SubChainSequentialTest {
chain.exec(ctx)
}
println("TIME: $t")
assertEquals("9;8;7;6;5;4;3;2;1;0;", ctx.text)
assertEquals("9;8;7;6;5;4;3;2;1;0;", ctx.atomicText.value)
}
}

Expand Down Expand Up @@ -81,20 +82,20 @@ class SubChainSequentialTest {
}
worker("") { println("START: $str") }
worker("") { val del = 100 - str.toLong() * 10; println("$str $del"); delay(del); str += ";" }
worker("") { parent.text += str }
worker("") { parent.atomicText.update { it + str } }
worker("") { println("STOP: $str") }
}
subChain<TestContext, TestSubContext> {
title = "Check parallel execution of data"
buffer(10)
buffer(11)
on { some == 3 }
split {
val str = text
text = ""
str.map { TestSubContext(str = it.toString(), parent = this) }.asFlow()
}
worker("") { val del = 1000 - str.toLong() * 100; println("$str $del"); delay(del); str += ";" }
worker("") { parent.text += str }
worker("") { parent.atomicText.update { it + str } }
}
}.build()
}
Expand Down

0 comments on commit 0fa1969

Please sign in to comment.