Start recording screen again if we get cut off after 3 minutes

This commit is contained in:
Steve Soltys 2023-09-14 18:42:22 +00:00
parent 59cef31183
commit 04c5089113
2 changed files with 34 additions and 6 deletions

View file

@ -8,9 +8,14 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.UiDevice
import com.stevesoltys.seedvault.e2e.screen.impl.DocumentPickerScreen import com.stevesoltys.seedvault.e2e.screen.impl.DocumentPickerScreen
import com.stevesoltys.seedvault.e2e.screen.impl.RecoveryCodeScreen 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.lang.Thread.sleep
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Calendar import java.util.Calendar
import java.util.concurrent.atomic.AtomicBoolean
interface LargeTestBase { interface LargeTestBase {
@ -43,19 +48,35 @@ interface LargeTestBase {
uiAutomation.executeShellCommand(command).close() uiAutomation.executeShellCommand(command).close()
} }
@OptIn(DelicateCoroutinesApi::class)
@WorkerThread @WorkerThread
fun startScreenRecord(testName: String) { suspend fun startScreenRecord(
keepRecordingScreen: AtomicBoolean,
testName: String,
) {
val simpleDateFormat = SimpleDateFormat("yyyyMMdd_hhmmss") val simpleDateFormat = SimpleDateFormat("yyyyMMdd_hhmmss")
val timeStamp = simpleDateFormat.format(Calendar.getInstance().time) val timeStamp = simpleDateFormat.format(Calendar.getInstance().time)
val fileName = "${timeStamp}_${testName.replace(" ", "_")}" val fileName = "${timeStamp}_${testName.replace(" ", "_")}"
val folder = testVideoPath() val folder = testVideoPath()
runCommand("mkdir -p $folder") 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 @WorkerThread
fun stopScreenRecord() { fun stopScreenRecord(keepRecordingScreen: AtomicBoolean) {
keepRecordingScreen.set(false)
runCommand("pkill -2 screenrecord") runCommand("pkill -2 screenrecord")
} }

View file

@ -3,6 +3,7 @@ package com.stevesoltys.seedvault.e2e
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stevesoltys.seedvault.restore.RestoreViewModel import com.stevesoltys.seedvault.restore.RestoreViewModel
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager
import kotlinx.coroutines.runBlocking
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
@ -11,6 +12,7 @@ import org.junit.runner.RunWith
import org.koin.core.component.KoinComponent import org.koin.core.component.KoinComponent
import org.koin.core.component.inject import org.koin.core.component.inject
import java.io.File import java.io.File
import java.util.concurrent.atomic.AtomicBoolean
@RunWith(AndroidJUnit4::class) @RunWith(AndroidJUnit4::class)
internal abstract class SeedvaultLargeTest : internal abstract class SeedvaultLargeTest :
@ -33,18 +35,20 @@ internal abstract class SeedvaultLargeTest :
private val baselineRecoveryCodePath = "$baselineBackupFolderPath/$RECOVERY_CODE_FILE" private val baselineRecoveryCodePath = "$baselineBackupFolderPath/$RECOVERY_CODE_FILE"
private val keepRecordingScreen = AtomicBoolean(true)
@Before @Before
open fun setUp() { open fun setUp() = runBlocking {
clearDocumentPickerAppData() clearDocumentPickerAppData()
clearTestBackups() clearTestBackups()
startScreenRecord(name.methodName) startScreenRecord(keepRecordingScreen, name.methodName)
restoreBaselineBackup() restoreBaselineBackup()
} }
@After @After
open fun tearDown() { open fun tearDown() {
stopScreenRecord() stopScreenRecord(keepRecordingScreen)
} }
/** /**
@ -59,6 +63,9 @@ internal abstract class SeedvaultLargeTest :
chooseStorageLocation(folderName = BASELINE_BACKUP_FOLDER, exists = true) chooseStorageLocation(folderName = BASELINE_BACKUP_FOLDER, exists = true)
typeInRestoreCode(baselineBackupRecoveryCode()) typeInRestoreCode(baselineBackupRecoveryCode())
performRestore() performRestore()
// remove baseline backup after restore
runCommand("rm -Rf $baselineBackupFolderPath/*")
} }
} }