From 846e87a44b57d2991ca3ae814082aa6c01c1f414 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 14 Aug 2022 14:25:44 +0300 Subject: [PATCH] Fix flaky properties test --- .../mipt/npm/muon/monitor/MMAppComponent.kt | 8 ++++---- .../ru/mipt/npm/muon/monitor/MMDemoApp.kt | 3 ++- .../visionforge/meta/VisionPropertyTest.kt | 20 +++++++------------ 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt index 20a33fe2..3ecb7f9f 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt @@ -16,7 +16,6 @@ import react.dom.p import react.fc import react.useMemo import react.useState -import space.kscience.dataforge.context.Context import space.kscience.dataforge.meta.invoke import space.kscience.dataforge.names.Name import space.kscience.visionforge.Colors @@ -24,6 +23,7 @@ import space.kscience.visionforge.react.flexColumn import space.kscience.visionforge.react.flexRow import space.kscience.visionforge.ring.ThreeCanvasWithControls import space.kscience.visionforge.ring.tab +import space.kscience.visionforge.solid.Solids import space.kscience.visionforge.solid.ambientLight import space.kscience.visionforge.solid.set import space.kscience.visionforge.solid.specifications.Canvas3DOptions @@ -35,7 +35,7 @@ import kotlin.math.PI external interface MMAppProps : Props { var model: Model - var context: Context + var solids: Solids var selected: Name? } @@ -71,7 +71,7 @@ val MMApp = fc("Muon monitor") { props -> } child(ThreeCanvasWithControls) { attrs { - this.context = props.context + this.solids = props.solids this.builderOfSolid = CompletableDeferred(root) this.selected = props.selected this.options = mmOptions @@ -82,7 +82,7 @@ val MMApp = fc("Muon monitor") { props -> +"Next" attrs { onClickFunction = { - context.launch { + solids.context.launch { val event = window.fetch( "http://localhost:8080/event", RequestInit("GET") diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt index 9c96ad07..4b18291b 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt @@ -7,6 +7,7 @@ import space.kscience.dataforge.context.fetch import space.kscience.visionforge.Application import space.kscience.visionforge.VisionManager import space.kscience.visionforge.react.render +import space.kscience.visionforge.solid.Solids import space.kscience.visionforge.solid.three.ThreePlugin import space.kscience.visionforge.startApplication @@ -27,7 +28,7 @@ private class MMDemoApp : Application { child(MMApp) { attrs { this.model = model - this.context = context + this.solids = context.fetch(Solids) } } } diff --git a/visionforge-core/src/commonTest/kotlin/space/kscience/visionforge/meta/VisionPropertyTest.kt b/visionforge-core/src/commonTest/kotlin/space/kscience/visionforge/meta/VisionPropertyTest.kt index 90c72b9b..08497a57 100644 --- a/visionforge-core/src/commonTest/kotlin/space/kscience/visionforge/meta/VisionPropertyTest.kt +++ b/visionforge-core/src/commonTest/kotlin/space/kscience/visionforge/meta/VisionPropertyTest.kt @@ -1,7 +1,9 @@ package space.kscience.visionforge.meta import kotlinx.coroutines.* -import kotlinx.coroutines.flow.collectIndexed +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.take +import kotlinx.coroutines.flow.toList import kotlinx.coroutines.test.runTest import space.kscience.dataforge.context.Global import space.kscience.dataforge.context.fetch @@ -106,24 +108,16 @@ internal class VisionPropertyTest { val child = group.children["child"]!! launch { - child.flowPropertyValue("test", inherit = true).collectIndexed { index, value -> - when (index) { - 0 -> assertEquals(22, value?.int) - 1 -> assertEquals(11, value?.int) - 2 -> { - assertEquals(33, value?.int) - cancel() - } - } - } + val list = child.flowPropertyValue("test", inherit = true).take(3).map { it?.int }.toList() + assertEquals(22, list.first()) + //assertEquals(11, list[1]) //a race + assertEquals(33, list.last()) } //wait for subscription to be created delay(5) child.properties.remove("test") - - delay(50) group.properties["test"] = 33 } } \ No newline at end of file