Disable auto updating on device and better prepare logcat (#20732)

* Disable updated and setup logcat for tests

* - move shell commands to more generic spot

* Update android.cake

* - add test filter as arg

* Update android.cake

* - try removing play store

* Update android.cake

* - formalize retries a bit

* - fix

* Update android.cake

* Update android.cake
This commit is contained in:
Shane Neuville 2024-03-06 13:22:58 -06:00 коммит произвёл GitHub
Родитель f76cc0679b
Коммит 51cabfd400
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 85 добавлений и 3 удалений

Просмотреть файл

@ -9,6 +9,7 @@ var localDotnet = GetBuildVariable("workloads", "local") == "local";
var vsVersion = GetBuildVariable("VS", "");
string MSBuildExe = Argument("msbuild", EnvironmentVariable("MSBUILD_EXE", ""));
string nugetSource = Argument("nugetsource", "");
string testFilter = Argument("test-filter", EnvironmentVariable("TEST_FILTER"));
string TestTFM = Argument("testtfm", "");
var useNuget = Argument("usenuget", true);
@ -731,6 +732,16 @@ void RunTestWithLocalDotNet(string csproj)
void RunTestWithLocalDotNet(string csproj, string config, string pathDotnet = null, Dictionary<string,string> argsExtra = null, bool noBuild = false, string resultsFileNameWithoutExtension = null, string filter = "")
{
if (string.IsNullOrWhiteSpace(filter))
{
filter = testFilter;
}
if (!string.IsNullOrWhiteSpace(filter))
{
Information("Run Tests With Filter {0}", filter);
}
string binlog;
string results;
var name = System.IO.Path.GetFileNameWithoutExtension(csproj);

Просмотреть файл

@ -111,6 +111,7 @@ Setup(context =>
var sdk = api >= 27 ? "google_apis_playstore" : "google_apis";
if (api == 27 && DEVICE_ARCH == "x86_64")
sdk = "default";
ANDROID_AVD_IMAGE = $"system-images;android-{api};{sdk};{DEVICE_ARCH}";
Information("Going to run image: {0}", ANDROID_AVD_IMAGE);
@ -143,6 +144,12 @@ Setup(context =>
Information("Starting Emulator: {0}...", ANDROID_AVD);
emulatorProcess = AndroidEmulatorStart(ANDROID_AVD, emuSettings);
}
if (IsCIBuild())
{
AdbLogcat(new AdbLogcatOptions() { Clear = true });
AdbShell("logcat -G 16M");
}
});
Teardown(context =>
@ -343,8 +350,29 @@ Task("uitest")
SetEnvironmentVariable("APPIUM_LOG_FILE", $"{BINLOG_DIR}/appium_android.log");
Information("Run UITests project {0}", PROJECT.FullPath);
RunTestWithLocalDotNet(PROJECT.FullPath, CONFIGURATION, noBuild: true, resultsFileNameWithoutExtension: $"{name}-{CONFIGURATION}-android");
Information("Run UITests project {0}", PROJECT.FullPath);
int numOfRetries = 0;
if (IsCIBuild())
numOfRetries = 1;
for(int retryCount = 0; retryCount <= numOfRetries; retryCount++)
{
try
{
RunTestWithLocalDotNet(PROJECT.FullPath, CONFIGURATION, noBuild: true, resultsFileNameWithoutExtension: $"{name}-{CONFIGURATION}-android");
break;
}
catch(Exception)
{
if (retryCount == numOfRetries)
{
WriteLogCat();
throw;
}
}
}
});
Task("cg-uitest")
@ -392,8 +420,50 @@ Task("cg-uitest")
FailRunOnOnlyInconclusiveTests(System.IO.Path.Combine(nunitSettings.Work.FullPath, "TestResult.xml"));
});
Task("logcat")
.Does(() =>
{
WriteLogCat();
});
RunTarget(TARGET);
void WriteLogCat(string filename = null)
{
if (string.IsNullOrWhiteSpace(filename))
{
var timeStamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
filename = $"logcat_{TARGET}_{timeStamp}.log";
}
EnsureDirectoryExists(GetLogDirectory());
// I tried AdbLogcat here but the pipeline kept reporting "cannot create file"
var location = $"{GetLogDirectory()}/{filename}";
Information("Writing logcat to {0}", location);
var processSettings = new ProcessSettings();
processSettings.RedirectStandardOutput = true;
processSettings.RedirectStandardError = true;
var adb = $"{ANDROID_SDK_ROOT}/platform-tools/adb";
Information("Running: {0} logcat -d", adb);
processSettings.Arguments = $"logcat -d";
using (var fs = new System.IO.FileStream(location, System.IO.FileMode.Create))
using (var sw = new StreamWriter(fs))
{
processSettings.RedirectedStandardOutputHandler = (output) => {
sw.WriteLine(output);
return output;
};
var process = StartProcess($"{adb}", processSettings);
Information("exit code {0}", process);
}
Information("Logcat written to {0}", location);
}
void SetupAppPackageNameAndResult()
{
if (string.IsNullOrEmpty(TEST_APP)) {

Просмотреть файл

@ -115,7 +115,8 @@ steps:
- pwsh: ./build.ps1 -Script eng/devices/${{ parameters.platform }}.cake --target=uitest --project="${{ parameters.path }}" --appproject="${{ parameters.app }}" --device="${{ parameters.device }}" --apiversion="${{ parameters.version }}" --configuration="${{ parameters.configuration }}" --results="$(TestResultsDirectory)" --binlog="$(LogDirectory)" ${{ parameters.cakeArgs }} --verbosity=diagnostic
displayName: $(Agent.JobName)
retryCountOnTaskFailure: 1
${{ if ne(parameters.platform, 'android')}}:
retryCountOnTaskFailure: 1
- bash: |
suffix=$(date +%Y%m%d%H%M%S)