Start recording screen again if we get cut off after 3 minutes
This commit is contained in:
parent
59cef31183
commit
04c5089113
2 changed files with 34 additions and 6 deletions
|
@ -8,9 +8,14 @@ import androidx.test.platform.app.InstrumentationRegistry
|
|||
import androidx.test.uiautomator.UiDevice
|
||||
import com.stevesoltys.seedvault.e2e.screen.impl.DocumentPickerScreen
|
||||
import com.stevesoltys.seedvault.e2e.screen.impl.RecoveryCodeScreen
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import java.lang.Thread.sleep
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
interface LargeTestBase {
|
||||
|
||||
|
@ -43,19 +48,35 @@ interface LargeTestBase {
|
|||
uiAutomation.executeShellCommand(command).close()
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
@WorkerThread
|
||||
fun startScreenRecord(testName: String) {
|
||||
suspend fun startScreenRecord(
|
||||
keepRecordingScreen: AtomicBoolean,
|
||||
testName: String,
|
||||
) {
|
||||
val simpleDateFormat = SimpleDateFormat("yyyyMMdd_hhmmss")
|
||||
val timeStamp = simpleDateFormat.format(Calendar.getInstance().time)
|
||||
val fileName = "${timeStamp}_${testName.replace(" ", "_")}"
|
||||
|
||||
val folder = testVideoPath()
|
||||
|
||||
runCommand("mkdir -p $folder")
|
||||
runCommand("screenrecord $folder/$fileName.mp4")
|
||||
|
||||
// screen record automatically stops after 3 minutes
|
||||
// we need to block on a loop and split it into multiple files
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
var index = 0
|
||||
|
||||
while (keepRecordingScreen.get()) {
|
||||
device.executeShellCommand("screenrecord $folder/$fileName-${index++}.mp4")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun stopScreenRecord() {
|
||||
fun stopScreenRecord(keepRecordingScreen: AtomicBoolean) {
|
||||
keepRecordingScreen.set(false)
|
||||
|
||||
runCommand("pkill -2 screenrecord")
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.stevesoltys.seedvault.e2e
|
|||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.stevesoltys.seedvault.restore.RestoreViewModel
|
||||
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
|
@ -11,6 +12,7 @@ import org.junit.runner.RunWith
|
|||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import java.io.File
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
internal abstract class SeedvaultLargeTest :
|
||||
|
@ -33,18 +35,20 @@ internal abstract class SeedvaultLargeTest :
|
|||
|
||||
private val baselineRecoveryCodePath = "$baselineBackupFolderPath/$RECOVERY_CODE_FILE"
|
||||
|
||||
private val keepRecordingScreen = AtomicBoolean(true)
|
||||
|
||||
@Before
|
||||
open fun setUp() {
|
||||
open fun setUp() = runBlocking {
|
||||
clearDocumentPickerAppData()
|
||||
clearTestBackups()
|
||||
|
||||
startScreenRecord(name.methodName)
|
||||
startScreenRecord(keepRecordingScreen, name.methodName)
|
||||
restoreBaselineBackup()
|
||||
}
|
||||
|
||||
@After
|
||||
open fun tearDown() {
|
||||
stopScreenRecord()
|
||||
stopScreenRecord(keepRecordingScreen)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,6 +63,9 @@ internal abstract class SeedvaultLargeTest :
|
|||
chooseStorageLocation(folderName = BASELINE_BACKUP_FOLDER, exists = true)
|
||||
typeInRestoreCode(baselineBackupRecoveryCode())
|
||||
performRestore()
|
||||
|
||||
// remove baseline backup after restore
|
||||
runCommand("rm -Rf $baselineBackupFolderPath/*")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue