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

Proof of concept for event counter tests #23663

Closed
wants to merge 1 commit into from

Conversation

ajcvickers
Copy link
Member

@roji @dotnet/efteam This is testing to make sure we fire event counters when we intend to. (Two tests fail since I didn't fix the bugs in this PR.) To me, this seems like a reasonable compromise in terms of changing the product code in order to be able to test it. What do others think?

Copy link
Member

@gfoidl gfoidl left a comment

Choose a reason for hiding this comment

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

A different approach:

Make these fields protected and expose them in the (test-) subclass as properties, so that they can be read and reset.

The methods here could then be sealed again (as the class can't be sealed if want to subclass), and singleton can remain static readonly.


public class EventSourceFixture
{
public static TestEntityFrameworkEventSource TestEventSource = new();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public static TestEntityFrameworkEventSource TestEventSource = new();
public static readonly TestEntityFrameworkEventSource TestEventSource = new();

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

I'm generally not a big fan of changing product code to suit testing needs (and introducing virtual dispatches in runtime).

But if we feel there's enough value in preventing regressions (since we're already fixing the initial implementation bugs that we know of), we can do this.

public EventSourceTest(EventSourceFixture fixture)
{
_fixture = fixture;
_isTestThread.Value = true;
Copy link
Member

Choose a reason for hiding this comment

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

Technically, I'm not sure it's guaranteed that the thread constructing (and disposing) the class it the same one that runs the thread - it may be safer to just call a method inside each test which does this, and returns a disposable to reset back.


for (var i = 1; i <= 3; i++)
{
using (var context = new SomeDbContext())
Copy link
Member

Choose a reason for hiding this comment

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

nit: using declaration syntax

@ajcvickers
Copy link
Member Author

Superseded by #23826

@ajcvickers ajcvickers closed this Jan 6, 2021
@smitpatel smitpatel deleted the TheKnockingRockers1211 branch January 6, 2021 22:35
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