Doist/ffs

Update streaming tests to the new testApplication API

goncalossilva opened this issue · 0 comments

Events are sent, but never received. I suspect it's down to both server and client running on the same process during testing, sharing the same coroutines dispatcher, and going into a deadlock. Unfortunately, it's not possible to configure the dispatcher of either to validate this assumption. They both use Dispartchers.IO and there are plans to provide ways to override them, but probably not soon.

The header documents the high-level approach I went for:

* @Test
* fun testStreamGet() = testApplication {
* val client = createTokenClient(Permission.READ)
* val projectId = client.projectId
* var eventCount = 0
*
* client.userClient.client.post("${PATH_PROJECT(projectId)}$PATH_FLAGS") {
* setBodyForm("name" to "test", "rule" to "true")
* }
*
* client.client.launch {
* client.client.stream(PATH_FLAGS) {
* eventCount++
* val flags = json.decodeFromString<List<Flag>>(it.data)
* assert(flags.size == 1)
* assert(flags[0].name == "test")
* assert(flags[0].rule == "true")
* }
* }
*
* client.userClient.client.post("${PATH_PROJECT(projectId)}$PATH_FLAGS") {
* setBodyForm("name" to "test", "rule" to "true")
* }
*
* assert(eventCount == 1)
* }