Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a test-helper class TestCoroutineContext. #1

Open
wants to merge 66 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
55a66ac
Improve ReceiveChannel operators implementations to guarantee closing
elizarov Mar 12, 2018
fe8ba6b
`onCompletion` added to `launch`, `async`, and `actor`
elizarov Mar 13, 2018
a4b5693
`onCompletion` added to `promise` and `future` (JDK8 and Guava)
elizarov Mar 13, 2018
ab66afc
Kotlin 1.2.30
elizarov Feb 20, 2018
9fe5f46
Deprecated CoroutineScope.coroutineContext which is replaced with
elizarov Feb 21, 2018
61cafea
Warning about future fail-fast in consumeEach is added to the guide
elizarov Mar 13, 2018
c7d10a4
Fix references to `coroutineContext` is the docs of all the builders
elizarov Mar 13, 2018
45bcb0b
Improve ChannelsConsumeTest to avoid spurious failures due to concurr…
elizarov Mar 14, 2018
d7d9e2f
IO: eliminate kotlin.Pair allocations
Mar 15, 2018
7831716
IO: introduce non-flushing joinTo
Mar 21, 2018
740c485
Fail with proper message if JDK_16 is not set
venkatperi Mar 21, 2018
26f4b9e
Add extension to ExecutorService to return closeable CoroutineDispatcher
deva666 Mar 20, 2018
8e38418
Explicitly mention that jcenter must be in a list of repos
elizarov Apr 3, 2018
6c2ed55
Merge remote-tracking branch 'origin/master' into develop
elizarov Apr 3, 2018
905a512
typo fixed
elizarov Apr 4, 2018
e1a5652
Extracted compilation configs into separate build files
elizarov Apr 4, 2018
3145290
Restructure build logic, prepare for native
elizarov Apr 11, 2018
aa461cf
Minimize cut-and-pasted code between JS and JVM
elizarov Apr 11, 2018
31550f1
Gradle 4.6
elizarov Apr 11, 2018
a735f9e
updated dependencies for android sample apps
Dmitry-Borodin Apr 9, 2018
379f210
Remove unavailable builder from js/kotlinx-coroutines-core-js/README.md
vkhikhlov Apr 10, 2018
4b94843
Merge remote-tracking branch 'origin/master' into develop
elizarov Apr 11, 2018
0bb18fc
Better way to set CoroutineContext#DEBUG value
dmytrodanylyk Apr 10, 2018
590c888
Documentation for debug property values
elizarov Apr 11, 2018
4cb5d19
Allow negative timeouts in delay, withTimeout and onTimeout on JVM
qwwdfsad Apr 11, 2018
4dcdc4a
Remove duplicate test file after rebase
qwwdfsad Apr 12, 2018
d521478
Separate Job (interface) and JobSupport (implementation). No other ch…
qwwdfsad Apr 13, 2018
931587a
Improve test coverage of CancellableCoroutine, add benchmark
qwwdfsad Apr 16, 2018
f3a5013
Decouple AbstractContinuation and CancellableContinuation from Job in…
qwwdfsad Apr 16, 2018
4aa18aa
Introduce cancelling state for AbstractContinuation, improve exceptio…
qwwdfsad Apr 17, 2018
80a2947
Make deprecated API hidden, replace deprecated API with new one
qwwdfsad Apr 17, 2018
f6430f4
Cleanup:
qwwdfsad Apr 17, 2018
b1a07ee
Setup dependency resolution strategy to force kotlin_version
ilya-g Apr 16, 2018
480d8e9
Fix complaints of the latest compiler: actuals without expect
ilya-g Apr 16, 2018
f0cd180
Suppress errors about default parameters in actual functions
ilya-g Apr 17, 2018
81f79c3
Do not use deprecated coroutineContext
ilya-g Apr 17, 2018
cc08426
Do not put kotlin dependency in package.json used for tests
ilya-g Apr 18, 2018
58fa752
Do not print npmPublish args at configuration phase
ilya-g Apr 18, 2018
f4eb05a
Kotlin 1.2.40
qwwdfsad Apr 25, 2018
4b9a559
CompletedExceptionally now always has cause and exception became an a…
qwwdfsad Apr 11, 2018
4f0d48b
Introducing awaitAll and joinAll extensions on JVM
qwwdfsad Apr 11, 2018
9c69279
Update readme, take the shortest link in Knit when resolving API refe…
qwwdfsad Apr 11, 2018
f0ef14e
Start jobs during awaitAll call to properly handle lazily started cor…
qwwdfsad Apr 11, 2018
203abb0
awaitAll review and todos
elizarov Apr 12, 2018
f5e63ca
Replacing isCancelledWithoutCause with proper contract on exception, …
qwwdfsad Apr 12, 2018
05d3823
awaitAll improvements: create defensive copy of jobs to consistently …
qwwdfsad Apr 12, 2018
c1092d5
Remove CompletedExceptionally#exception
qwwdfsad Apr 12, 2018
e89cd68
More comments about CancellationException and its consistent use;
elizarov Apr 25, 2018
189e995
awaitAll should be defined only for Deferred types and return results…
elizarov Apr 26, 2018
9619134
Migrate channels and related operators to common, so channels can be …
qwwdfsad Apr 20, 2018
2cdbfd7
Properly implement select clause for JS channels
qwwdfsad Apr 22, 2018
8a07168
Update readme for JS channels
qwwdfsad Apr 22, 2018
11d6b5b
Hide declarations in internal package
elizarov Apr 26, 2018
f2bdf60
Merged develop (js-channels work) into await-all
elizarov Apr 26, 2018
769d7dc
Moved awaitAll/joinAll to common module
elizarov Apr 26, 2018
0406a9b
Remove prev/next from common LockFreeLinkedList API
elizarov Apr 26, 2018
cd00643
Delay bug fixes:
qwwdfsad Apr 26, 2018
b4c7b40
Use disposeOnCompletion to remove cancelled delays
elizarov Apr 27, 2018
76146bb
Merge branch 'await-all' into develop
elizarov Apr 27, 2018
6d9f40f
Merge develop into decouple-job
elizarov Apr 28, 2018
dbd9e1c
Consistent naming of handler base classes and their concrete impls
elizarov Apr 28, 2018
3e9f244
Review and optimize usage of CancellableContinuation.invokeOnCancella…
elizarov Apr 28, 2018
e0b6db0
Leaking handles in awaitAll are fixed
elizarov Apr 28, 2018
87f2faa
Fix compiler warnings
qwwdfsad Apr 30, 2018
20dbd9f
Fast-path for isDone in ListenableFuture#await, stop using deprecated…
qwwdfsad May 7, 2018
afb3dea
Adding a test-helper class TestCoroutineContext.
Mar 20, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ buildscript {
}
```

Make sure that you have either `jcenter()` or `mavenCentral()` in the list of repositories:

```
repository {
jcenter()
}
```

### Kotlin/JS

Use `org.jetbrains.kotlinx:kotlinx-coroutines-core-js:<version>` artifact in your Gradle/Maven dependencies
Expand All @@ -109,11 +117,22 @@ To avoid field overloading by type during obfuscation, add this to your config:
}
```

## Building

This library is built with Gradle. To build it, use `./gradlew build`.
You can import this project into IDEA, but you have to delegate build actions
to Gradle (in Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Runner)

### Requirements

* JDK >= 1.8 referred to by the `JAVA_HOME` environment variable.
* JDK 1.6 referred to by the `JDK_16` environment variable.

## Contributions and releases

All development (both new features and bug fixes) is performed in `develop` branch.
This way `master` sources always contain sources of the most recently released version.
Please send PRs with bug fixes to `develop` branch
Please send PRs with bug fixes to `develop` branch.
Fixes to documentation in markdown files are an exception to this rule. They are updated directly in `master`.

The `develop` branch is pushed to `master` during release.
Expand Down
1 change: 1 addition & 0 deletions benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ repositories {

dependencies {
jmh 'com.typesafe.akka:akka-actor:2.0.2'
jmh project(':kotlinx-coroutines-core-common')
jmh project(':kotlinx-coroutines-core')
jmh project(':kotlinx-coroutines-core').sourceSets.test.output
jmh project(':kotlinx-coroutines-io')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package benchmarks

import kotlinx.coroutines.experimental.*
import org.openjdk.jmh.annotations.*
import java.util.concurrent.*
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*

@Warmup(iterations = 5)
@Measurement(iterations = 10)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@State(Scope.Benchmark)
@Fork(2)
open class CancellableContinuationBenchmark {

@Benchmark
fun awaitWithSuspension(): Int {
val deferred = CompletableDeferred<Int>()
return run(allowSuspend = true) { deferred.await() }
}

@Benchmark
fun awaitNoSuspension(): Int {
val deferred = CompletableDeferred(1)
return run { deferred.await() }
}

private fun run(allowSuspend: Boolean = false, block: suspend () -> Int): Int {
val value = block.startCoroutineUninterceptedOrReturn(EmptyContinuation)
if (value === COROUTINE_SUSPENDED) {
if (!allowSuspend) {
throw IllegalStateException("Unexpected suspend")
} else {
return -1
}
}

return value as Int
}

object EmptyContinuation : Continuation<Int> {
override val context: CoroutineContext
get() = EmptyCoroutineContext

override fun resume(value: Int) {
}

override fun resumeWithException(exception: Throwable) {
}
}
}
10 changes: 5 additions & 5 deletions benchmarks/src/jmh/kotlin/benchmarks/ChannelCopyBenchmark.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ open class ChannelCopyBenchmark {
val pIn = ByteChannel(true)
val pOut = ByteChannel(true)

launch(coroutineContext) {
launch(this.coroutineContext) {
pOut.joinTo(pIn, true)
}

Expand All @@ -193,7 +193,7 @@ open class ChannelCopyBenchmark {
val pIn = ByteChannel(true)
val pOut = ByteChannel(true)

launch(coroutineContext) {
launch(this.coroutineContext) {
pOut.joinTo(pIn, true)
}

Expand All @@ -217,7 +217,7 @@ open class ChannelCopyBenchmark {
val pIn = ByteChannel(true)
val pOut = ByteChannel(true)

launch(coroutineContext) {
launch(this.coroutineContext) {
pOut.copyTo(pIn)
pIn.close()
}
Expand All @@ -242,7 +242,7 @@ open class ChannelCopyBenchmark {
val pIn = ByteChannel(true)
val pOut = ByteChannel(true)

launch(coroutineContext) {
launch(this.coroutineContext) {
pOut.copyTo(pIn)
pIn.close()
}
Expand Down Expand Up @@ -298,7 +298,7 @@ open class ChannelCopyBenchmark {

@Benchmark
fun runBlockingAndLaunch() = runBlocking {
launch(coroutineContext) {
launch(this.coroutineContext) {
yield()
}

Expand Down
137 changes: 49 additions & 88 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
allprojects {
group = 'org.jetbrains.kotlinx'
def deployVersion = properties['DeployVersion']
if (deployVersion != null) version = deployVersion
}

buildscript {
if (rootProject.properties['kotlinSnapshot'] != null) {
ext.useKotlinSnapshot = rootProject.properties['kotlinSnapshot'] != null
if (useKotlinSnapshot) {
ext.kotlin_version = '1.2-SNAPSHOT'
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
}
repositories {
jcenter()
maven { url "http://kotlin.bintray.com/kotlinx" }
maven { url "http://kotlin.bintray.com/kotlin-dev" }
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "https://kotlin.bintray.com/kotlin-dev" }
maven { url "https://jetbrains.bintray.com/kotlin-native-dependencies" }
maven { url "https://plugins.gradle.org/m2/" }
}
configurations.classpath {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.jetbrains.kotlin' && details.requested.name != 'kotlin-native-gradle-plugin') {
// fix version of all dependencies from org.jetbrains.kotlin group
// even when other dependencies require other versions indirectly,
// except kotlin-native, which has its own pre-release versioning
details.useVersion kotlin_version
}
}
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$kotlin_native_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicFU_version"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
}
}

allprojects {
def deployVersion = properties['DeployVersion']
if (deployVersion != null) version = deployVersion
if (useKotlinSnapshot) {
kotlin_version = '1.2-SNAPSHOT'
}
}


// Report Kotlin compiler version when building project
println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")

Expand All @@ -36,6 +54,7 @@ def sourceless = ['site']
static def platformOf(project) {
if (project.name.endsWith("-common")) return "common"
if (project.name.endsWith("-js")) return "js"
if (project.name.endsWith("-native")) return "native"
return "jvm"
}

Expand All @@ -44,95 +63,36 @@ static def platformLib(base, platform) {
return "$base-$platform"
}

configure(subprojects.findAll { !sourceless.contains(it.name) }) {
def platform = platformOf(it)
apply plugin: "kotlin-platform-$platform"

if (platform == "jvm") {
sourceCompatibility = 1.6
targetCompatibility = 1.6
}

kotlin.experimental.coroutines "enable"

if (platform == "js") {
tasks.withType(compileKotlin2Js.getClass()) {
kotlinOptions {
moduleKind = "umd"
sourceMap = true
metaInfo = true
// drop -js suffix from outputFile
def baseName = project.name - "-js"
outputFile = new File(outputFile.parent, baseName + ".js")
}
}
}

tasks.withType(Test) {
testLogging {
showStandardStreams = true
events "passed", "failed"
subprojects {
if (useKotlinSnapshot) {
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
def stressTest = project.properties['stressTest']
if (stressTest != null) systemProperties['stressTest'] = stressTest
}

repositories {
jcenter()
maven { url "http://kotlin.bintray.com/kotlinx" }
maven { url "https://dl.bintray.com/devexperts/Maven/" }
}

def kotlin_stdlib = platformLib("kotlin-stdlib", platform)
def kotlin_test = platformLib("kotlin-test", platform)

dependencies {
compile "org.jetbrains.kotlin:$kotlin_stdlib:$kotlin_version"
testCompile "org.jetbrains.kotlin:$kotlin_test:$kotlin_version"
}

if (platform == "common") {
dependencies {
testCompile "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"
configurations.all {
resolutionStrategy {
eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.jetbrains.kotlin') {
details.useVersion kotlin_version
}
}
}
}
}

if (platform == "jvm") {
dependencies {
testCompile "junit:junit:$junit_version"
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
}
configure(subprojects.findAll { !sourceless.contains(it.name) }) {
def platform = platformOf(it)
apply from: rootProject.file("gradle/compile-${platform}.gradle")
}

// --------------- Configure sub-projects that are part of the library ---------------

def internal = sourceless + ['benchmarks', 'knit', 'js-stub']

// configure atomicfu for JVM modules
configure(subprojects.findAll { !internal.contains(it.name) && platformOf(it) == "jvm" }) {
apply plugin: 'kotlinx-atomicfu'

dependencies {
compileOnly "org.jetbrains.kotlinx:atomicfu:$atomicFU_version"
testCompile "org.jetbrains.kotlinx:atomicfu:$atomicFU_version"
}

atomicFU {
inputFiles = sourceSets.main.output.classesDirs
outputDir = file("$buildDir/classes-atomicfu/main")
classPath = sourceSets.main.runtimeClasspath
}

jar {
mainSpec.sourcePaths.clear() // hack to clear existing paths
from files(atomicFU.outputs, sourceSets.main.output.resourcesDir)
}

test {
classpath = files(configurations.testRuntime, atomicFU.outputs, sourceSets.test.output.classesDirs,
sourceSets.main.output.resourcesDir)
}
// configure atomicfu
configure(subprojects.findAll { !internal.contains(it.name) }) {
def platform = platformOf(it)
apply from: rootProject.file("gradle/atomicfu-${platform}.gradle")
}

// configure dependencies on core
Expand All @@ -155,7 +115,8 @@ configure(subprojects.findAll { !internal.contains(it.name) && it.name != 'kotli

// --------------- Configure sub-projects that are published ---------------

def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js']
// todo: native is not published yet
def unpublished = internal + ['kotlinx-coroutines-rx-example', 'example-frontend-js', 'kotlinx-coroutines-core-native']

def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/"
def core_docs_file = "$projectDir/core/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
Expand Down
Loading