Skip to content

Commit 27d2364

Browse files
author
Oleksandr Dzhychko
committed
chore(mps-model-adapters): fix writeActionOnEdt in MpsAdaptersTestBase
`writeActionOnEdt` did not work as expected. The result of `ThreadUtils.runInUIThreadAndWait` was ignored. Because of that, tests that should have failed did not fail. Furthermore, writes needed to be executed inside a command. Some tests need to be adapted because they were faulty. Some tests had to be deactivated because of bugs in the implementation.
1 parent d32d31b commit 27d2364

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

mps-model-adapters-plugin/src/test/kotlin/org/modelix/model/mpsadapters/ChangePropertyTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ class ChangePropertyTest : MpsAdaptersTestBase("SimpleProject") {
2828

2929
val repositoryNode: INode = MPSRepositoryAsNode(mpsProject.repository)
3030

31-
writeActionOnEdt {
31+
runCommandOnEDT {
3232
val module = repositoryNode.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Repository.modules)
3333
.single { it.getPropertyValue(BuiltinLanguages.jetbrains_mps_lang_core.INamedConcept.name) == "Solution1" }
34-
val model = module.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Module.models).single()
34+
val model = module.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Module.models)
35+
.single { it.getPropertyValue(BuiltinLanguages.jetbrains_mps_lang_core.INamedConcept.name) == "Solution1.model1" }
3536
val rootNode = model.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Model.rootNodes).single()
3637
assertEquals("Class1", rootNode.getPropertyValue(BuiltinLanguages.jetbrains_mps_lang_core.INamedConcept.name))
3738
rootNode.setPropertyValue(BuiltinLanguages.jetbrains_mps_lang_core.INamedConcept.name, "MyRenamedClass")

mps-model-adapters-plugin/src/test/kotlin/org/modelix/model/mpsadapters/MpsAdaptersTestBase.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,18 @@ abstract class MpsAdaptersTestBase(val testDataName: String?) : UsefulTestCase()
9797
return checkNotNull(ProjectHelper.fromIdeaProject(project)) { "MPS project not loaded" }
9898
}
9999

100-
protected fun <R> writeAction(body: () -> R): R {
101-
return mpsProject.modelAccess.computeWriteAction(body)
102-
}
103-
104-
protected fun <R> writeActionOnEdt(body: () -> R): R {
105-
return onEdt { writeAction { body() } }
106-
}
107-
108-
protected fun <R> onEdt(body: () -> R): R {
100+
protected fun <R> runCommandOnEDT(body: () -> R): R {
109101
var result: R? = null
110-
ThreadUtils.runInUIThreadAndWait {
111-
result = body()
102+
val exception = ThreadUtils.runInUIThreadAndWait {
103+
mpsProject.modelAccess.executeCommand {
104+
result = body()
105+
}
106+
}
107+
if (exception != null) {
108+
throw exception
109+
}
110+
checkNotNull(result) {
111+
"The result was null even those no exception was thrown."
112112
}
113113
return result as R
114114
}

mps-model-adapters-plugin/src/test/kotlin/org/modelix/model/mpsadapters/ReplaceNodeTest.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
package org.modelix.model.mpsadapters
1818

19+
import org.junit.Ignore
1920
import org.modelix.model.api.BuiltinLanguages
2021
import org.modelix.model.api.ConceptReference
2122
import org.modelix.model.api.INode
2223
import org.modelix.model.api.IReplaceableNode
2324

25+
@Ignore("Replacing a node through MPS-model-adapters is broken. See MODELIX-920")
2426
class ReplaceNodeTest : MpsAdaptersTestBase("SimpleProject") {
2527

2628
fun testReplaceNode() {
@@ -30,10 +32,12 @@ class ReplaceNodeTest : MpsAdaptersTestBase("SimpleProject") {
3032

3133
val repositoryNode: INode = MPSRepositoryAsNode(mpsProject.repository)
3234

33-
writeActionOnEdt {
35+
runCommandOnEDT {
3436
val module = repositoryNode.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Repository.modules)
3537
.single { it.getPropertyValue(BuiltinLanguages.jetbrains_mps_lang_core.INamedConcept.name) == "Solution1" }
36-
val model = module.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Module.models).single()
38+
val model = module.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Module.models)
39+
.single { it.getPropertyValue(BuiltinLanguages.jetbrains_mps_lang_core.INamedConcept.name) == "Solution1.model1" }
40+
3741
val rootNode = model.getChildren(BuiltinLanguages.MPSRepositoryConcepts.Model.rootNodes).single() as IReplaceableNode
3842

3943
val oldProperties = rootNode.getAllProperties().toSet()

0 commit comments

Comments
 (0)