Skip to content

Commit

Permalink
Add StopServer for AdbServer
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Oct 20, 2023
1 parent 79344a1 commit 5428875
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 2 deletions.
12 changes: 12 additions & 0 deletions AdvancedSharpAdbClient.Tests/AdbServerTests.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,17 @@ public async void RestartServerAsyncTest()
Assert.Equal("host:version", socket.Requests[0]);
Assert.Equal("host:kill", socket.Requests[1]);
}

/// <summary>
/// Tests the <see cref="AdbServer.StopServerAsync(CancellationToken)"/> method.
/// </summary>
[Fact]
public async void StopServerAsyncTest()
{
await adbServer.StopServerAsync();

Assert.Single(socket.Requests);
Assert.Equal("host:kill", socket.Requests[0]);
}
}
}
12 changes: 12 additions & 0 deletions AdvancedSharpAdbClient.Tests/AdbServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@ public void RestartServerTest()
Assert.Equal("host:kill", socket.Requests[1]);
}

/// <summary>
/// Tests the <see cref="AdbServer.StopServer"/> method.
/// </summary>
[Fact]
public void StopServerTest()
{
adbServer.StopServer();

Assert.Single(socket.Requests);
Assert.Equal("host:kill", socket.Requests[0]);
}

/// <summary>
/// Tests the <see cref="AdbServer(IAdbClient, Func{string, IAdbCommandLineClient})"/> method.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions AdvancedSharpAdbClient.Tests/Dummys/DummyAdbServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,15 @@ public Task<StartServerResult> StartServerAsync(string adbPath, bool restartServ
tcs.SetResult(result);
return tcs.Task;
}

/// <inheritdoc/>
public void StopServer() => Status = Status with { IsRunning = false };

/// <inheritdoc/>
public Task StopServerAsync(CancellationToken cancellationToken)
{
StopServer();
return Task.CompletedTask;
}
}
}
3 changes: 3 additions & 0 deletions AdvancedSharpAdbClient/AdbServer.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public Task<StartServerResult> RestartServerAsync(CancellationToken cancellation
public virtual Task<StartServerResult> RestartServerAsync(string adbPath, CancellationToken cancellationToken = default) =>
StringExtensions.IsNullOrWhiteSpace(adbPath) ? RestartServerAsync(cancellationToken) : StartServerAsync(adbPath, true, cancellationToken);

/// <inheritdoc/>
public virtual Task StopServerAsync(CancellationToken cancellationToken = default) => adbClient.KillAdbAsync(cancellationToken);

/// <inheritdoc/>
public virtual async Task<AdbServerStatus> GetStatusAsync(CancellationToken cancellationToken = default)
{
Expand Down
3 changes: 3 additions & 0 deletions AdvancedSharpAdbClient/AdbServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public virtual StartServerResult StartServer(string adbPath, bool restartServerI
public virtual StartServerResult RestartServer(string adbPath) =>
StringExtensions.IsNullOrWhiteSpace(adbPath) ? RestartServer() : StartServer(adbPath, true);

/// <inheritdoc/>
public virtual void StopServer() => adbClient.KillAdb();

/// <inheritdoc/>
public virtual AdbServerStatus GetStatus()
{
Expand Down
7 changes: 6 additions & 1 deletion AdvancedSharpAdbClient/Interfaces/IAdbServer.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ public partial interface IAdbServer
Task<StartServerResult> RestartServerAsync(string adbPath, CancellationToken cancellationToken);

/// <summary>
/// Gets the status of the adb server.
/// Stop the adb server asynchronously.
/// </summary>
Task StopServerAsync(CancellationToken cancellationToken);

/// <summary>
/// Gets the status of the adb server asynchronously.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> which return a <see cref="AdbServerStatus"/> object that describes the status of the adb server.</returns>
Expand Down
8 changes: 7 additions & 1 deletion AdvancedSharpAdbClient/Interfaces/IAdbServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public partial interface IAdbServer
/// <see cref="AdbServer.StartServer(string, bool)"/> and passed the full path to the adb server.</remarks>
StartServerResult RestartServer();

/// <summary>Restarts the adb server with new adb path if it suddenly became unavailable. Call this class if, for example,
/// <summary>
/// Restarts the adb server with new adb path if it suddenly became unavailable. Call this class if, for example,
/// you receive an <see cref="AdbException"/> with the <see cref="AdbException.ConnectionReset"/> flag
/// set to <see langword="true"/> - a clear indicating the ADB server died.
/// </summary>
Expand All @@ -66,6 +67,11 @@ public partial interface IAdbServer
/// <see cref="AdbServer.StartServer(string, bool)"/> and passed the full path to the adb server.</remarks>
StartServerResult RestartServer(string adbPath);

/// <summary>
/// Stop the adb server.
/// </summary>
void StopServer();

/// <summary>
/// Gets the status of the adb server.
/// </summary>
Expand Down

0 comments on commit 5428875

Please sign in to comment.