Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.util.UUID


/**
Expand Down Expand Up @@ -92,18 +93,13 @@ internal object FatalIssueGenerator {
}

fun forceCoroutinesAnr() {
CoroutineScope(Dispatchers.Main).launch {
(1..Int.MAX_VALUE).asFlow()
.onEach {
Thread.sleep(1)
}
.collect {
Log.i(TAG_NAME, "Item received: $it")
}
callOnMainThread {
Log.i(TAG_NAME, "forceCoroutinesAnr. Getting device")
val deviceId = DeviceFetcher.getDeviceId()
Log.d(TAG_NAME, "forceCoroutinesAnr. Device ID: $deviceId")
}
}


fun forceCoroutinesCrash(){
CoroutineScope(Dispatchers.IO).launch {
throw RuntimeException("Coroutine background thread crash")
Expand Down Expand Up @@ -195,4 +191,22 @@ internal object FatalIssueGenerator {
return "Task ID [$id] completed with a $duration of milliseconds"
}
}

object DeviceFetcher {

private suspend fun fetchDeviceId(): String {
delay(20000)
return "Device ID: ${UUID.randomUUID()}"
}

/**
* This call will block caller thread until fetchDeviceId completes
*/
fun getDeviceId(): String {
return runBlocking {
Log.i("DeviceScopeRegistry", "getDevice")
fetchDeviceId()
}
}
}
}
Loading