Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Conversation

@mikaelm12
Copy link
Contributor

Some tests for the ForceAsyncAwaiter

@dnfclas
Copy link

dnfclas commented Aug 29, 2017

@mikaelm12,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

var hubConnection = new HubConnection(connection, new LoggerFactory());
Assert.NotNull(SynchronizationContext.Current);
await hubConnection.StartAsync();
Assert.Null(SynchronizationContext.Current);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong. That doesn't happen...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, tbh I was kind of confused by this behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should we be testing this at the HubConnection level?

@mikaelm12
Copy link
Contributor Author

There were issues with using the default SyncContext. Things should look better now.

@moozzyk
Copy link
Contributor

moozzyk commented Aug 30, 2017

I think it would be better if - instead of/in addition to using event handlers - you created a mock transport (possibly wrapping an existing transport if it makes it easier) and checking sync context in the transport methods. If you use this pattern you can also test HubConnection async methods by mocking IConnection.

@mikaelm12
Copy link
Contributor Author

I was able to add tests at the HubConnection level by checking the SyncContexts in the Connected and Closed events. Do you think I should still mock the transport and implement the tests that way? I'd have to brush up on how to use Mocks 😅

{
await Task.Yield();
Assert.Null(SynchronizationContext.Current);
await Task.CompletedTask;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to await Task.CompletedTask

@muratg
Copy link

muratg commented Sep 28, 2017

@mikaelm12 ping

@mikaelm12
Copy link
Contributor Author

Closing for now as this isn't critical atm

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants