Skip to content

Commit

Permalink
Add a retry in the case of exit code 224; Seeks to address dotnet#354
Browse files Browse the repository at this point in the history
If this is insufficient there are some helix-based extra things to try.
  • Loading branch information
MattGal committed Nov 14, 2020
1 parent 9769171 commit 8fa53fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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
21 changes: 21 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,17 @@ 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.LogInformation($"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 +205,16 @@ 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.LogInformation($"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

0 comments on commit 8fa53fb

Please sign in to comment.