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

Feature/assertionscope #1091

Merged
merged 17 commits into from Jul 8, 2019
Merged

Feature/assertionscope #1091

merged 17 commits into from Jul 8, 2019

Conversation

@conklinb
Copy link
Contributor

@conklinb conklinb commented Jun 26, 2019

Adds safety to tests using AssertionScope while running many tests in parallel

IMPORTANT

  • The code complies with the Coding Guidelines for C#.
  • The changes are covered by a new or existing set of unit tests which follow the Arrange-Act-Assert syntax such as is used in this example.
  • If the contribution affects the documentation, please include your changes to documentation.md in this pull request so the documentation will appear on the website.
@conklinb
Copy link
Contributor Author

@conklinb conklinb commented Jun 26, 2019

Looks like the tests need updated to support threading. On it

Loading

Src/FluentAssertions/FluentAssertions.csproj Outdated Show resolved Hide resolved
Loading
Src/FluentAssertions/Execution/AssertionScope.cs Outdated Show resolved Hide resolved
Loading
Src/FluentAssertions/Execution/DefaultAssertionStrategy.cs Outdated Show resolved Hide resolved
Loading
Src/FluentAssertions/Execution/AssertionScope.cs Outdated Show resolved Hide resolved
Loading
Src/FluentAssertions/Execution/AssertionScope.cs Outdated Show resolved Hide resolved
Loading
@conklinb
Copy link
Contributor Author

@conklinb conklinb commented Jun 27, 2019

Sorry about the one file per commit "commits" right now. Work VPN doesn't want to let me log in via bash or gh desktop

Loading

@conklinb
Copy link
Contributor Author

@conklinb conklinb commented Jun 28, 2019

All comments addressed

Loading

@jnyrup
Copy link
Member

@jnyrup jnyrup commented Jun 29, 2019

The revised implementation looks great to me 👍.

Now to verification.
I observe that if I remove the [ThreadStatic] from the current implementation the tests fail, whereas this PR succeeds.
So this PR seems at least as good as master.

I've tried to come up with a test to verify that the changes are also an improvement over master.
The test below fails in master, but succeeds with this PR.
If this test like this gets added (with better names than First and Second) I'm confident with these changes.

[Fact]
public async Task When_using_AssertionScope_across_thread_boundaries_it_should_work()
{
    using (var semaphore = new SemaphoreSlim(0, 1))
    {
        await Task.WhenAll(First(semaphore), Second(semaphore));
    }
}

private static async Task First(SemaphoreSlim semaphore)
{
    await Task.Yield();
    var scope = new AssertionScope();
    await semaphore.WaitAsync();
    scope.Should().BeSameAs(AssertionScope.Current);
}

private static async Task Second(SemaphoreSlim semaphore)
{
    await Task.Yield();
    var scope = new AssertionScope();
    semaphore.Release();
    scope.Should().BeSameAs(AssertionScope.Current);
}

Loading

Adding Tests for boundaries
@conklinb
Copy link
Contributor Author

@conklinb conklinb commented Jul 8, 2019

Added Tests

Loading

jnyrup
jnyrup approved these changes Jul 8, 2019
@conklinb
Copy link
Contributor Author

@conklinb conklinb commented Jul 8, 2019

Is there anything else you need in order to get this merged?

Loading

@dennisdoomen dennisdoomen merged commit 1b6c4d3 into fluentassertions:master Jul 8, 2019
1 check passed
Loading
@jnyrup jnyrup mentioned this pull request Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants