Skip to content
Prev Previous commit
Fix comment and add timeout
  • Loading branch information
ericstj committed Apr 5, 2023
commit efbb10188460a20edd1d24f3ed51c8c8ebaf4efd
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public async Task StopAsync(CancellationToken cancellationToken)
await Task.Run(Stop, cancellationToken).ConfigureAwait(false);
}

// When the underlying service is stopped this will cause the ServiceBase.Run method to complete and return, which completes _serviceStopRequested.
// When the underlying service is stopped this will cause the ServiceBase.Run method to complete and return, which completes _serviceDispatcherStopped.
await _serviceDispatcherStopped.Task.ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using Microsoft.DotNet.RemoteExecutor;
using Microsoft.Win32.SafeHandles;
using Xunit;

namespace Microsoft.Extensions.Hosting
{
Expand Down Expand Up @@ -47,6 +48,18 @@ private WindowsServiceTester(SafeServiceHandle serviceHandle, RemoteInvokeHandle
{ }
}

public TimeSpan WaitForStatusTimeout { get; set; } = TimeSpan.FromSeconds(30);

public new void WaitForStatus(ServiceControllerStatus desiredStatus) =>
WaitForStatus(desiredStatus, WaitForStatusTimeout);

public new void WaitForStatus(ServiceControllerStatus desiredStatus, TimeSpan timeout)
{
base.WaitForStatus(desiredStatus, timeout);

Assert.Equal(Status, desiredStatus);
}

// the following overloads are necessary to ensure the compiler will produce the correct signature from a lambda.
public static WindowsServiceTester Create(Func<Task> serviceMain, [CallerMemberName] string serviceName = null) => Create(RemoteExecutor.Invoke(serviceMain, remoteInvokeOptions), serviceName);

Expand Down