Skip to content

Commit c8202c4

Browse files
linkdotnetegil
andauthored
feat: Increase timeout to 5 minutes if a debugger is attached (#1178)
* feat: Increase timeout to Infinite if a debugger is attached * Added docs * Update docs/site/docs/interaction/awaiting-async-state.md Co-authored-by: Egil Hansen <egil@assimilated.dk> * Update docs/site/docs/interaction/awaiting-async-state.md Co-authored-by: Egil Hansen <egil@assimilated.dk> * Always remove the timeout when debugger is attached * Update docs --------- Co-authored-by: Egil Hansen <egil@assimilated.dk>
1 parent d73f519 commit c8202c4

5 files changed

Lines changed: 15 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad
66

77
## [Unreleased]
88

9-
109
### Added
1110

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

1414
## [1.22.19] - 2023-07-28
1515

docs/site/docs/interaction/awaiting-async-state.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ The timeout, which defaults to one second, can be controlled by passing a `TimeS
4747
If the timeout is reached, a <xref:Bunit.Extensions.WaitForHelpers.WaitForFailedException> exception is thrown with the following error message:
4848

4949
> The state predicate did not pass before the timeout period passed.
50+
51+
## Debugging code that uses `WaitForState`, `WaitForAssertion`, or `WaitForElement`
52+
53+
When `bUnit` detects that a debugger is attached (`Debugger.IsAttached`), it will automatically disable the timeout functionality of the "wait for" methods.

src/bunit.core/Extensions/WaitForHelpers/RenderedFragmentWaitForHelperExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public static class RenderedFragmentWaitForHelperExtensions
2020
/// <param name="statePredicate">The predicate to invoke after each render, which must returns <c>true</c> when the desired state has been reached.</param>
2121
/// <param name="timeout">The maximum time to wait for the desired state.</param>
2222
/// <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>
23+
/// <remarks>
24+
/// If a debugger is attached the timeout is set to <see cref="Timeout.InfiniteTimeSpan" />, giving the possibility to debug without the timeout triggering.
25+
/// </remarks>
2326
public static void WaitForState(this IRenderedFragmentBase renderedFragment, Func<bool> statePredicate, TimeSpan? timeout = null)
2427
{
2528
using var waiter = new WaitForStateHelper(renderedFragment, statePredicate, timeout);

src/bunit.core/Extensions/WaitForHelpers/WaitForAssertionHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class WaitForAssertionHelper : WaitForHelper<object?>
2323
/// <param name="renderedFragment">The rendered fragment to wait for renders from and assert against.</param>
2424
/// <param name="assertion">The verification or assertion to perform.</param>
2525
/// <param name="timeout">The maximum time to attempt the verification.</param>
26+
/// <remarks>
27+
/// If a debugger is attached the timeout is set to <see cref="Timeout.InfiniteTimeSpan" />, giving the possibility to debug without the timeout triggering.
28+
/// </remarks>
2629
public WaitForAssertionHelper(IRenderedFragmentBase renderedFragment, Action assertion, TimeSpan? timeout = null)
2730
: base(
2831
renderedFragment,

src/bunit.core/Extensions/WaitForHelpers/WaitForHelper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using Bunit.Rendering;
23
using Microsoft.Extensions.Logging;
34

@@ -194,6 +195,8 @@ private void SubscribeToOnAfterRender()
194195

195196
private static TimeSpan GetRuntimeTimeout(TimeSpan? timeout)
196197
{
197-
return timeout ?? TestContextBase.DefaultWaitTimeout;
198+
return Debugger.IsAttached
199+
? Timeout.InfiniteTimeSpan
200+
: timeout ?? TestContextBase.DefaultWaitTimeout;
198201
}
199202
}

0 commit comments

Comments
 (0)