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

Assertions for Task and Task<T> with CompleteWithin checks #1013

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@lg2de
Copy link
Contributor

lg2de commented Mar 23, 2019

This PR implements #1001.
In contrast to PR #1011 this attempt provides only the extensions on Task/Task<T> and should not be a breaking change.

As already noted, I found timing issues in my and other tests. Today I added a prototype to abstract real timing in the tests. What do you think?

Unfortunately I could not make ITimer internal as planned. FluentAssertions is a strong named assembly. So, the test assembly must use strong named too, if it should refer to ITimer. (Otherwise the InternalVisiblesTo attribute will fail.) This is not possible because the Chill package is not strong named.
Please help to find solution to make ITimer internal.

@lg2de lg2de referenced this pull request Mar 23, 2019

Open

Task func extensions #1011

@dennisdoomen

This comment has been minimized.

Copy link
Member

dennisdoomen commented Mar 24, 2019

You can't make ITimer internal because it's a parameter of the TaskAssertions class. And we kept all those assertion classes (the ones returned by the Should methods) because this allows people to extend them.

@lg2de

This comment has been minimized.

Copy link
Contributor Author

lg2de commented Mar 24, 2019


public bool Wait(Task task, TimeSpan timeout)
{
return task.Wait(timeout);

This comment has been minimized.

Copy link
@dennisdoomen

dennisdoomen Apr 20, 2019

Member

This can cause deadlocks (which seem to happen more often on AppVeyor). Consider using a construct like https://github.com/ChillBDD/Chill/blob/master/Src/Chill/Common/TaskExtensions.cs#L16 or use a Task.Run.

public void CompleteWithin(
TimeSpan timeSpan, string because = "", params object[] becauseArgs)
{
var completed = this.timer.Wait(Subject, timeSpan);

This comment has been minimized.

Copy link
@dennisdoomen

dennisdoomen Apr 20, 2019

Member

(minor) You don't need this here.

public Task Subject { get; private set; }

/// <summary>
/// Asserts that the current <see cref="Task"/> will complete within specified time range.

This comment has been minimized.

Copy link
@dennisdoomen

dennisdoomen Apr 20, 2019

Member

(nitpick) It's not really a time range, is it?

TimeSpan timeSpan, string because = "", params object[] becauseArgs)
{
var delayTask = this.timer.DelayAsync(timeSpan);
var completedTask = await Task.WhenAny(Subject, delayTask);

This comment has been minimized.

Copy link
@dennisdoomen

dennisdoomen Apr 20, 2019

Member

If the Task represented by Subject completes before the timeout, you must cancel the timer. Something like https://github.com/liquidprojections/LiquidProjections/blob/master/Src/LiquidProjections.Testing/TaskExtensions.cs#L9

/// <summary>
/// Implementation of <see cref="ITimer"/> for testing purposes only.
/// </summary>
public class TestingTimer : ITimer

This comment has been minimized.

Copy link
@dennisdoomen

dennisdoomen Apr 20, 2019

Member

Can be made internal, right?

@dennisdoomen dennisdoomen changed the title assertions for Task and Task<T> with CompleteWithin checks Assertions for Task and Task<T> with CompleteWithin checks Apr 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.