Skip to content

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

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

@conklinb
Copy link
Contributor Author

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

@conklinb
Copy link
Contributor Author

All comments addressed

@jnyrup
Copy link
Member

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);
}

Adding Tests for boundaries
@conklinb
Copy link
Contributor Author

conklinb commented Jul 8, 2019

Added Tests

@conklinb
Copy link
Contributor Author

conklinb commented Jul 8, 2019

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

@dennisdoomen dennisdoomen merged commit 1b6c4d3 into fluentassertions:master Jul 8, 2019
@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

Development

Successfully merging this pull request may close these issues.

3 participants