Skip to content

Conversation

skomis-mm
Copy link
Contributor

What issue does this PR address?
fixes 1112

Does this PR introduce a breaking change?

  • no

Please check if the PR fulfills these requirements

  • The commit follows our guidelines
  • Unit Tests for the changes have been added (for bug fixes / features)

Sergey Komisarchik added 2 commits February 21, 2018 12:04
- force schedule async continuations on a new thread
Task t;
try
{
t = testAction();
Copy link
Member

Choose a reason for hiding this comment

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

Not sure at all about what I'm saying, but ... shouldn't there be an await here (i.e. in the try instead of after the finally ?

Copy link
Contributor Author

@skomis-mm skomis-mm Feb 21, 2018

Choose a reason for hiding this comment

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

Thanks for the feedback! The problem with reverting sync context after await is that on await point I'm not owning thread anymore and this thread will lose its original context (Xunit.Sdk.AsyncTestSyncContext) so I'm not sure that this will be safe for other tests or xunit. After await point I'll be already likely on a different thread anyway. You can set/reset safely while you own the thread, for example, for sync implementations. That's why I can't use here using statement.

@@ -383,4 +401,9 @@ public bool IsCallable()
}
}
#endif

class ForceNewThreadSyncContext : SynchronizationContext
Copy link
Member

Choose a reason for hiding this comment

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

Mostly a personal opinion, but maybe having a IDisposable class would make the test code a bit more readable (less aync lambdas , and less indentation generally) , a bit like https://github.com/serilog/serilog/blob/dev/test/Serilog.Tests/Support/TemporarySelfLog.cs and its usage in

using (TemporarySelfLog.SaveTo(outputs))

It would be nice to have test code that looks like :

using(NewThreadSynchronizationContext.Start()){
  // the code that needs to be tested with that SynchronizationContext
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

couldn't use await inside disposable block, see explanation above

@nblumhardt
Copy link
Member

Awesome stuff, I didn't notice we'd taken an implicit dependency on the test runner implementation, here.

@nblumhardt nblumhardt merged commit 7629de6 into serilog:dev Feb 21, 2018
@nblumhardt nblumhardt mentioned this pull request May 17, 2018
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.

LogContext CI test failure
3 participants