Skip to content

Commit

Permalink
Merge pull request #150 from aPureBase/temp-solution-for-data-loader-…
Browse files Browse the repository at this point in the history
…issues

No lazy coroutines
  • Loading branch information
jeggy authored Jun 10, 2021
2 parents 2be753a + bb38dd9 commit 05a7eb2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# KGraphQL version
version=0.17.9-alpha
version=0.17.9-alpha-2

# Dependencies
coroutine_version=1.3.9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DeferredJsonMap internal constructor(
}

fun asDeferred() : Deferred<JsonElement> {
return async(coroutineContext, start = CoroutineStart.LAZY) {
return async(coroutineContext) {
awaitAll()
build()
}
Expand All @@ -62,8 +62,8 @@ class DeferredJsonMap internal constructor(
job.complete()
}

fun deferredLaunch(lazy: Boolean = true, block: suspend DeferredJsonMap.() -> Unit) {
moreJobs.add(async(job, start = if (lazy) CoroutineStart.LAZY else CoroutineStart.DEFAULT) {
fun deferredLaunch(block: suspend DeferredJsonMap.() -> Unit) {
moreJobs.add(async(job) {
block(this@DeferredJsonMap)
})
}
Expand Down
40 changes: 28 additions & 12 deletions kgraphql/src/test/kotlin/com/apurebase/kgraphql/DataLoaderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.util.concurrent.atomic.AtomicInteger

// This is just for safety, so when the tests fail and
// end up in an endless waiting state, they'll fail after this amount
val timeout = ofSeconds(10)!!
val timeout = ofSeconds(60)!!
const val repeatTimes = 2

class DataLoaderTest {
Expand Down Expand Up @@ -89,6 +89,7 @@ class DataLoaderTest {
dataProperty<Int, List<Person>>("colleagues") {
prepare { it.id }
loader { keys ->
delay(10)
println("== Running [colleagues] loader with keys: $keys ==")
keys.map { ExecutionResult.Success(colleagues[it] ?: listOf()) }
}
Expand Down Expand Up @@ -166,7 +167,10 @@ class DataLoaderTest {
"Testing 3" -> "Jógvan" to "Høgni"
else -> "${it}Nest-0" to "${it}Nest-1"
}
ExecutionResult.Success(listOf(ABC(a1), ABC(a2)))
delay(1)
ExecutionResult.Success(
(1..7).map { if (it % 2 == 0) ABC(a1) else ABC(a2) }
)
}
}
prepare { parent ->
Expand Down Expand Up @@ -291,7 +295,7 @@ class DataLoaderTest {
return fn(true) + fn(false)
}

@RepeatedTest(repeatTimes)
@RepeatedTest(repeatTimes, name = "Nested array loaders")
fun `Nested array loaders`() {
assertTimeoutPreemptively(timeout) {
val (schema) = schema()
Expand All @@ -313,7 +317,7 @@ class DataLoaderTest {
}
}

@RepeatedTest(repeatTimes)
@RepeatedTest(repeatTimes, name = "Old basic resolvers in new executor")
fun `Old basic resolvers in new executor`() {
assertTimeoutPreemptively(timeout) {
val (schema) = schema()
Expand All @@ -334,7 +338,7 @@ class DataLoaderTest {
}
}

@RepeatedTest(repeatTimes)
@RepeatedTest(repeatTimes, name = "Very basic new Level executor")
fun `Very basic new Level executor`() {
assertTimeoutPreemptively(timeout) {
val (schema) = schema()
Expand All @@ -358,7 +362,7 @@ class DataLoaderTest {
}
}

@RepeatedTest(repeatTimes)
@RepeatedTest(repeatTimes, name = "dataloader with nullable prepare keys")
fun `dataloader with nullable prepare keys`() {
assertTimeoutPreemptively(timeout) {
val (schema) = schema()
Expand All @@ -383,7 +387,7 @@ class DataLoaderTest {
}
}

@RepeatedTest(repeatTimes)
@RepeatedTest(repeatTimes, name = "Basic dataloader test")
fun `Basic dataloader test`() {
assertTimeoutPreemptively(timeout) {
val (schema) = schema()
Expand All @@ -409,7 +413,7 @@ class DataLoaderTest {
}
}

@RepeatedTest(2)
@RepeatedTest(2, name = "basic data loader")
fun `basic data loader`() {
assertTimeoutPreemptively(timeout) {
val (schema, counters) = schema()
Expand Down Expand Up @@ -437,7 +441,7 @@ class DataLoaderTest {
}
}

@RepeatedTest(repeatTimes)
@RepeatedTest(repeatTimes, name = "data loader cache per request only")
fun `data loader cache per request only`() {
assertTimeoutPreemptively(timeout) {
val (schema, counters) = schema()
Expand All @@ -462,7 +466,7 @@ class DataLoaderTest {
}
}

@RepeatedTest(repeatTimes)
@RepeatedTest(repeatTimes, name = "multiple layers of dataLoaders")
fun `multiple layers of dataLoaders`() {
assertTimeoutPreemptively(timeout) {
val (schema) = schema()
Expand All @@ -472,12 +476,24 @@ class DataLoaderTest {
abc {
value
B
children {
children { # 7
value
B
children {
children { # 49
value
B
children { # 343
value
B
children { # 2.401
value
B
children { # 16.807
value
B
}
}
}
}
}
}
Expand Down

0 comments on commit 05a7eb2

Please sign in to comment.