- Notifications
You must be signed in to change notification settings - Fork 196
/
Copy pathTestAsync.kt
65 lines (63 loc) · 3.25 KB
/
TestAsync.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
importkotlinx.coroutines.*
classTestAsync {
// for >7.2
// private val sdk = TestConfig().sdk
//
// // see https://kotlinlang.org/docs/reference/coroutines/composing-suspending-functions.html#structured-concurrency-with-async
// private suspend fun recentParallel(dashLimit: Long?, lookLimit: Long?): Pair<Array<Dashboard>, Array<Look>> = coroutineScope {
// val recentDashboards = async { sdk.ok<Array<Dashboard>>(sdk.search_dashboards(
// limit = dashLimit, last_viewed_at = "not null", sorts = "last_viewed_at desc")) }
// val recentLooks = async { sdk.ok<Array<Look>>(sdk.search_looks(
// limit = lookLimit, last_viewed_at = "not null", sorts = "last_viewed_at desc")) }
// Pair(recentDashboards.await(), recentLooks.await())
// }
//
// private fun listLimits() : Pair<Long?, Long?> {
// // estimate what may be the correct count of viewed looked and dashboards
// // since `last_viewed_at` is not in DashboardBase, it's going to be an approximation
// val allDash = sdk.ok<Array<DashboardBase>>(sdk.all_dashboards("id"))
// val allLooks = sdk.ok<Array<Look>>(sdk.all_looks("id, last_viewed_at"))
// val viewedLooks = allLooks.filter { l -> l.last_viewed_at !== null }
// val dashLimit = minOf(9, allDash.count())
// val lookLimit = minOf( 9, viewedLooks.count())
// assertNotEquals(0, dashLimit, "There are no viewed dashboards")
// assertNotEquals(0, lookLimit, "There are no viewed looks")
// return Pair(dashLimit.toLong(), lookLimit.toLong())
// }
//
// @Test
// fun testRecentParallel() {
// val limits = listLimits()
// runBlocking {
// val pair = recentParallel(limits.first, limits.second)
// val dashboards = pair.first
// val looks = pair.second
// assertNotNull(dashboards)
// assertNotNull(looks)
// assertEquals(limits.first!!.toInt(), dashboards.count(), "${limits.first} viewed Dashboards")
// assertEquals(limits.second!!.toInt(), looks.count(), "${limits.second} viewed Looks")
// }
// }
//
// private suspend fun recentSerial(dashLimit: Long?, lookLimit: Long?): Pair<Array<Dashboard>, Array<Look>> = coroutineScope {
// val recentDashboards = withContext(Dispatchers.Default) { sdk.ok<Array<Dashboard>>(sdk.search_dashboards(
// limit = dashLimit, last_viewed_at = "not null", sorts = "last_viewed_at desc")) }
// val recentLooks = withContext(Dispatchers.Default) { sdk.ok<Array<Look>>(sdk.search_looks(
// limit = lookLimit, last_viewed_at = "not null", sorts = "last_viewed_at desc")) }
// Pair(recentDashboards, recentLooks)
// }
//
// @Test
// fun testRecentSerial() {
// val limits = listLimits()
// runBlocking {
// val pair = recentSerial(limits.first, limits.second)
// val dashboards = pair.first
// val looks = pair.second
// assertNotNull(dashboards)
// assertNotNull(looks)
// assertEquals(limits.first!!.toInt(), dashboards.count(), "${limits.first} viewed Dashboards")
// assertEquals(limits.second!!.toInt(), looks.count(), "${limits.second} viewed Looks")
// }
// }
}