carlw
05/26/2017, 3:58 PMedvin
05/26/2017, 3:59 PMedvin
05/26/2017, 3:59 PMcarlw
05/26/2017, 4:02 PMkastork
05/26/2017, 4:22 PMkastork
05/26/2017, 4:22 PMroberto.guerra
05/26/2017, 4:28 PMGrooking FP
.alexp11223
05/26/2017, 5:49 PMTestFx
? Or just tests for non-UI stuff?
btw if I am following MVVM, is it normal to have async methods like that in ViewModel?
fun loadTokens() {
tokens.clear() // observable list
runAsync(status) {
loadSomeStuff(someData).tokens
} ui {
tokens.addAll(it)
} fail {
fire(ErrorEvent(it))
}
}
I tried to test this VM and found out that I can't do it because of async 🙂
Also I just noticed that I use someData
(string property) inside async, which I guess is not very thread safe...carlw
05/26/2017, 5:51 PMcarlw
05/26/2017, 5:52 PMalexp11223
05/26/2017, 6:05 PMit
is result returned on success, or exception in fail. someData
is just a property containing query parameter (I guess I should assign the value to local variable before runAsync
to make it thread safe)
and that seemed fine until I tried to unit test VM.
I am not sure how to wait for result in tests.
I can't even do something like this because FX thread is busy and ui
cannot fire:
vm.loadTokens()
while (vm.status.running) { }
assert.........
edvin
05/26/2017, 6:36 PMedvin
05/26/2017, 6:37 PMrunAndWait
in the framework. That might give you some ideas.kastork
05/26/2017, 7:15 PMalexp11223
05/26/2017, 7:17 PMkastork
05/26/2017, 7:27 PMkastork
05/26/2017, 7:28 PMalexp11223
05/26/2017, 8:00 PMval vm = TokensViewModel()
init {
FxToolkit.registerPrimaryStage()
}
@Test
fun loadsTokens() {
vm.loadTokens()
await().atMost(10000, MILLISECONDS).until { !vm.status.running.value }
assertNotEquals(0, vm.tokens.size)
}
but I am not completely sure why and how it works.
And looks like it is polling status
not from UI threadedvin
05/26/2017, 9:57 PMedvin
05/26/2017, 9:57 PMedvin
05/26/2017, 9:57 PMalexp11223
05/26/2017, 10:04 PMui
etc. will not fireedvin
05/26/2017, 10:08 PMedvin
05/26/2017, 10:10 PMedvin
05/27/2017, 8:25 AMToolkit.getToolkit().enterNestedEventLoop(this)
. I will commit awaitUntil
later today. I think it should solve your use case in a good way 🙂edvin
05/27/2017, 8:26 AMedvin
05/27/2017, 8:27 AM