Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a retry in the case of exit code 224 #361

Merged
merged 2 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/Microsoft.DotNet.XHarness.Android/AdbExitCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum AdbExitCodes
SUCCESS = 0,
INSTRUMENTATION_SUCCESS = -1,
INSTRUMENTATION_TIMEOUT = -2,
ADB_BROKEN_PIPE = 224,
ADB_UNINSTALL_APP_NOT_ON_DEVICE = 255,
ADB_UNINSTALL_APP_NOT_ON_EMULATOR = 1,
}
Expand Down
23 changes: 23 additions & 0 deletions src/Microsoft.DotNet.XHarness.Android/AdbRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ public int InstallApk(string apkPath)
throw new FileNotFoundException($"Could not find {apkPath}");
}
var result = RunAdbCommand($"install \"{apkPath}\"");

// If this keeps happening, we should look into exercising Helix infra retry logic when on Helix
// since users should be able assume tests themselves can't break the ADB server.
if (result.ExitCode == (int)AdbExitCodes.ADB_BROKEN_PIPE)
{
_log.LogWarning($"Hit broken pipe error; Will make one attempt to restart ADB server, and retry the install");

KillAdbServer();
StartAdbServer();
result = RunAdbCommand($"install \"{apkPath}\"");
}

if (result.ExitCode != 0)
{
_log.LogError($"Error:{Environment.NewLine}{result}");
Expand All @@ -194,6 +206,17 @@ public int UninstallApk(string apkName)

_log.LogInformation($"Attempting to remove apk '{apkName}': ");
var result = RunAdbCommand($"uninstall {apkName}");

// See note above in install()
if (result.ExitCode == (int)AdbExitCodes.ADB_BROKEN_PIPE)
{
_log.LogWarning($"Hit broken pipe error; Will make one attempt to restart ADB server, and retry the uninstallation");

KillAdbServer();
StartAdbServer();
result = RunAdbCommand($"uninstall {apkName}");
}

if (result.ExitCode == (int)AdbExitCodes.SUCCESS)
{
_log.LogInformation($"Successfully uninstalled {apkName}.");
Expand Down