Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
test parallel execution with sync resolvers and suspending resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand committed Sep 10, 2018
1 parent 53c8eb8 commit fe1f8ae
Showing 1 changed file with 57 additions and 0 deletions.
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"))
}
}

0 comments on commit fe1f8ae

Please sign in to comment.