diff --git a/src/test/kotlin/com/github/pgutkowski/kgraphql/integration/ParallelExecutionTest.kt b/src/test/kotlin/com/github/pgutkowski/kgraphql/integration/ParallelExecutionTest.kt new file mode 100644 index 00000000..91afd9c7 --- /dev/null +++ b/src/test/kotlin/com/github/pgutkowski/kgraphql/integration/ParallelExecutionTest.kt @@ -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("data/automated-0"), CoreMatchers.equalTo("0")) + MatcherAssert.assertThat(map.extract("data/automated-271"), CoreMatchers.equalTo("271")) + MatcherAssert.assertThat(map.extract("data/automated-314"), CoreMatchers.equalTo("314")) + MatcherAssert.assertThat(map.extract("data/automated-500"), CoreMatchers.equalTo("500")) + MatcherAssert.assertThat(map.extract("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("data/automated-0"), CoreMatchers.equalTo("0")) + MatcherAssert.assertThat(map.extract("data/automated-271"), CoreMatchers.equalTo("271")) + MatcherAssert.assertThat(map.extract("data/automated-314"), CoreMatchers.equalTo("314")) + MatcherAssert.assertThat(map.extract("data/automated-500"), CoreMatchers.equalTo("500")) + MatcherAssert.assertThat(map.extract("data/automated-999"), CoreMatchers.equalTo("999")) + } +} \ No newline at end of file