This commit is contained in:
zhongchao
2022-03-11 19:41:19 +08:00
parent 9275ed5ff2
commit 180bdfd50a
35 changed files with 1260 additions and 834 deletions

View File

@@ -1,11 +1,10 @@
package com.mogo.functions.test
import androidx.lifecycle.lifecycleScope
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mogo.eagle.core.data.autopilot.AutoPilotRecordResult
import com.mogo.eagle.core.function.hmi.ui.MoGoHmiFragment
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager
import com.mogo.eagle.core.function.main.MainLauncherActivity
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
@@ -14,7 +13,6 @@ import org.junit.Test
import org.junit.runner.RunWith
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.random.Random
@@ -31,14 +29,14 @@ class AutoPilotBadCaseTest {
@ExperimentalCoroutinesApi @Test
fun showBadCaseEntrance1(): Unit = runBlocking(Dispatchers.Main) {
val f = ensureMoGoHmiFragmentShow()
delay(5000)
var index = 0
(1 until 50)
.map { it }
.asFlow()
.onEach {
delay(TimeUnit.SECONDS.toMillis(5))
f.onAutopilotRecordResult(AutoPilotRecordResult().also {
CallerDevaToolsManager.onReceiveBadCaseRecord(AutoPilotRecordResult().also {
it.diskFree = (100 + index).toLong()
it.duration = 60.0
it.fileName = "/user/general/record_$index.log"
@@ -58,7 +56,7 @@ class AutoPilotBadCaseTest {
@ExperimentalCoroutinesApi @Test
fun showBadCaseEntrance2():Unit = runBlocking(Dispatchers.Main) {
val f = ensureMoGoHmiFragmentShow()
delay(5000)
var index = 0
(1 until 50)
.map { it }
@@ -69,7 +67,7 @@ class AutoPilotBadCaseTest {
} else {
delay(Random(20).nextLong())
}
f.onAutopilotRecordResult(AutoPilotRecordResult().also {
CallerDevaToolsManager.onReceiveBadCaseRecord(AutoPilotRecordResult().also {
it.diskFree = (100 + index).toLong()
it.duration = 60.0
it.fileName = "/user/general/record_$index.log"
@@ -80,11 +78,6 @@ class AutoPilotBadCaseTest {
it.timestamp = SimpleDateFormat("yyyyMMddHHmmss").format(Date())
index++
})
if (index == 5) {
f.lifecycleScope.cancel()
}
}
.flowOn(Dispatchers.Default)
.collect()
@@ -93,14 +86,13 @@ class AutoPilotBadCaseTest {
@ExperimentalCoroutinesApi @Test
fun showBadCaseEntrance3(): Unit = runBlocking(Dispatchers.Main) {
val f = ensureMoGoHmiFragmentShow()
var index = 0
(1 until 50)
.map { it }
.asFlow()
.onEach {
delay(TimeUnit.SECONDS.toMillis(20))
f.onAutopilotRecordResult(AutoPilotRecordResult().also {
CallerDevaToolsManager.onReceiveBadCaseRecord(AutoPilotRecordResult().also {
it.diskFree = (100 + index).toLong()
it.duration = 60.0
it.fileName = "/user/general/record_$index.log"
@@ -116,30 +108,4 @@ class AutoPilotBadCaseTest {
.collect()
delay(TimeUnit.HOURS.toMillis(2))
}
private suspend fun ensureMoGoHmiFragmentShow(): MoGoHmiFragment = suspendCancellableCoroutine {
launch.onActivity { itx ->
val executor = Executors.newSingleThreadScheduledExecutor()
executor.scheduleAtFixedRate({
var find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiFragment } as? MoGoHmiFragment
while (find == null) {
find =
itx.supportFragmentManager.fragments.find { it is MoGoHmiFragment } as? MoGoHmiFragment
}
while (!find.isResumed) {
Thread.sleep(500)
}
it.resumeWith(Result.success(find))
try {
Thread.sleep(500)
executor.shutdownNow()
} catch (e: Throwable) {
e.printStackTrace()
}
}, 50, 500, TimeUnit.MILLISECONDS)
}
}
}