This repository was archived by the owner on Nov 29, 2023. It is now read-only.
forked from pgutkowski/KGraphQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test parallel execution with sync resolvers and suspending resolvers
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/test/kotlin/com/github/pgutkowski/kgraphql/integration/ParallelExecutionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.github.pgutkowski.kgraphql.integration | ||
|
||
import com.github.pgutkowski.kgraphql.KGraphQL | ||
import com.github.pgutkowski.kgraphql.assertNoErrors | ||
import com.github.pgutkowski.kgraphql.extract | ||
import com.github.pgutkowski.kgraphql.deserialize | ||
import kotlinx.coroutines.experimental.delay | ||
import org.hamcrest.CoreMatchers | ||
import org.hamcrest.MatcherAssert | ||
import org.junit.Test | ||
|
||
class ParallelExecutionTest { | ||
|
||
val syncResolversSchema = KGraphQL.schema { | ||
repeat(1000) { | ||
query("automated-${it}") { | ||
resolver { -> | ||
Thread.sleep(3) | ||
"${it}" | ||
} | ||
} | ||
} | ||
} | ||
|
||
val suspendResolverSchema = KGraphQL.schema { | ||
repeat(1000) { | ||
query("automated-${it}") { | ||
suspendResolver { -> | ||
delay(3) | ||
"${it}" | ||
} | ||
} | ||
} | ||
} | ||
|
||
val query = "{ " + (0..999).map { "automated-${it}" }.joinToString(", ") + " }" | ||
|
||
@Test | ||
fun `1000 synchronous resolvers sleeping with Thread sleep`(){ | ||
val map = deserialize(syncResolversSchema.execute(query)) | ||
MatcherAssert.assertThat(map.extract<String>("data/automated-0"), CoreMatchers.equalTo("0")) | ||
MatcherAssert.assertThat(map.extract<String>("data/automated-271"), CoreMatchers.equalTo("271")) | ||
MatcherAssert.assertThat(map.extract<String>("data/automated-314"), CoreMatchers.equalTo("314")) | ||
MatcherAssert.assertThat(map.extract<String>("data/automated-500"), CoreMatchers.equalTo("500")) | ||
MatcherAssert.assertThat(map.extract<String>("data/automated-999"), CoreMatchers.equalTo("999")) | ||
} | ||
|
||
@Test | ||
fun `1000 suspending resolvers sleeping with suspending delay`(){ | ||
val map = deserialize(suspendResolverSchema.execute(query)) | ||
MatcherAssert.assertThat(map.extract<String>("data/automated-0"), CoreMatchers.equalTo("0")) | ||
MatcherAssert.assertThat(map.extract<String>("data/automated-271"), CoreMatchers.equalTo("271")) | ||
MatcherAssert.assertThat(map.extract<String>("data/automated-314"), CoreMatchers.equalTo("314")) | ||
MatcherAssert.assertThat(map.extract<String>("data/automated-500"), CoreMatchers.equalTo("500")) | ||
MatcherAssert.assertThat(map.extract<String>("data/automated-999"), CoreMatchers.equalTo("999")) | ||
} | ||
} |