Skip to content

Commit

Permalink
fix(modelql): set INodeResolutionScope when running query on INode
Browse files Browse the repository at this point in the history
  • Loading branch information
odzhychko committed Jan 7, 2025
1 parent ad10cfd commit f8861f5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions modelql-untyped/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ kotlin {
}
val commonTest by getting {
dependencies {
implementation(project(":model-datastructure"))
implementation(kotlin("test"))
implementation(libs.kotlin.coroutines.test)
}
}
val jvmMain by getting {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ fun INode.createQueryExecutor(): IQueryExecutor<INode> {
}

suspend fun <R> INode.query(body: (IMonoStep<INode>) -> IMonoStep<R>): R {
return buildQuery(body).execute().value
return this.getArea().runWithAdditionalScopeInCoroutine {
buildQuery(body).execute().value
}
}

suspend fun <R> INode.queryFlux(body: (IMonoStep<INode>) -> IFluxStep<R>): List<R> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.modelix.modelql.untyped

import kotlinx.coroutines.test.runTest
import org.modelix.model.api.TreePointer
import org.modelix.model.api.getRootNode
import org.modelix.model.client.IdGenerator
import org.modelix.model.lazy.CLTree
import org.modelix.model.lazy.NonCachingObjectStore
import org.modelix.model.persistent.MapBaseStore
import kotlin.test.Test
import kotlin.test.assertEquals

class UntypedModelQLTest {
private val tree = CLTree(NonCachingObjectStore(MapBaseStore()))
private val branch = TreePointer(tree, IdGenerator.getInstance(1))
private val rootNode = branch.getRootNode()

@Test
fun nodeCanBeResolvedInQuery() = runTest {
val resolvedNode = rootNode.query { root ->
root.nodeReference().resolve()
}
assertEquals(rootNode.reference, resolvedNode.reference)
}
}

0 comments on commit f8861f5

Please sign in to comment.