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

feat: Increase timeout to 5 minutes if a debugger is attached #1178

Merged
merged 6 commits into from
Aug 13, 2023
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad

## [Unreleased]


### Added

- `net8.0` support
- Increased timeout of `WaitForAssertion` to infinite when a debugger is attached. By [@linkdotnet](https://github.com/linkdotnet).

## [1.22.19] - 2023-07-28

Expand Down
4 changes: 4 additions & 0 deletions docs/site/docs/interaction/awaiting-async-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ The timeout, which defaults to one second, can be controlled by passing a `TimeS
If the timeout is reached, a <xref:Bunit.Extensions.WaitForHelpers.WaitForFailedException> exception is thrown with the following error message:

> The state predicate did not pass before the timeout period passed.

## Debugging code that uses `WaitForState`, `WaitForAssertion`, or `WaitForElement`

When `bUnit` detects that a debugger is attached (`Debugger.IsAttached`), it will automatically disable the timeout functionality of the "wait for" methods.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public static class RenderedFragmentWaitForHelperExtensions
/// <param name="statePredicate">The predicate to invoke after each render, which must returns <c>true</c> when the desired state has been reached.</param>
/// <param name="timeout">The maximum time to wait for the desired state.</param>
/// <exception cref="WaitForFailedException">Thrown if the <paramref name="statePredicate"/> throw an exception during invocation, or if the timeout has been reached. See the inner exception for details.</exception>
/// <remarks>
/// If a debugger is attached the timeout is set to <see cref="Timeout.InfiniteTimeSpan" />, giving the possibility to debug without the timeout triggering.
/// </remarks>
public static void WaitForState(this IRenderedFragmentBase renderedFragment, Func<bool> statePredicate, TimeSpan? timeout = null)
{
using var waiter = new WaitForStateHelper(renderedFragment, statePredicate, timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class WaitForAssertionHelper : WaitForHelper<object?>
/// <param name="renderedFragment">The rendered fragment to wait for renders from and assert against.</param>
/// <param name="assertion">The verification or assertion to perform.</param>
/// <param name="timeout">The maximum time to attempt the verification.</param>
/// <remarks>
/// If a debugger is attached the timeout is set to <see cref="Timeout.InfiniteTimeSpan" />, giving the possibility to debug without the timeout triggering.
/// </remarks>
public WaitForAssertionHelper(IRenderedFragmentBase renderedFragment, Action assertion, TimeSpan? timeout = null)
: base(
renderedFragment,
Expand Down
5 changes: 4 additions & 1 deletion src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using Bunit.Rendering;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -194,6 +195,8 @@ private void SubscribeToOnAfterRender()

private static TimeSpan GetRuntimeTimeout(TimeSpan? timeout)
{
return timeout ?? TestContextBase.DefaultWaitTimeout;
return Debugger.IsAttached
? Timeout.InfiniteTimeSpan
: timeout ?? TestContextBase.DefaultWaitTimeout;
}
}
Loading