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

refactor!: Improve EventExecutor #393

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

askpt
Copy link
Member

@askpt askpt commented Feb 28, 2025

This PR

This pull request includes several changes to the EventExecutor class and related classes in the OpenFeature project to improve code readability and performance. The main changes include replacing the use of List and Dictionary constructors with array initializers, refactoring methods to use Task instead of Thread, and enhancing null safety for the EventChannel.

Codebase improvements:

Null safety enhancements:

Related Issues

Reference #358

Notes

This PR fixes a null reference annotation in the FeatureProvider. This change could potentially break the external providers, but it is necessary since the EventChannel could be null.

…d signatures

Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
…t processing

Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
…o separate methods

Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
…ed new expressions

Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
…l cases

Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
…ider directly

Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
@askpt askpt linked an issue Feb 28, 2025 that may be closed by this pull request
Copy link

codecov bot commented Feb 28, 2025

Codecov Report

Attention: Patch coverage is 88.76404% with 10 lines in your changes missing coverage. Please review.

Project coverage is 85.92%. Comparing base (06e4e3a) to head (93c1f22).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/OpenFeature/EventExecutor.cs 87.95% 5 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #393      +/-   ##
==========================================
- Coverage   86.16%   85.92%   -0.25%     
==========================================
  Files          39       39              
  Lines        1605     1606       +1     
  Branches      173      173              
==========================================
- Hits         1383     1380       -3     
- Misses        186      189       +3     
- Partials       36       37       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@askpt askpt marked this pull request as ready for review February 28, 2025 13:01
@askpt askpt requested a review from a team as a code owner February 28, 2025 13:01
@askpt askpt enabled auto-merge February 28, 2025 13:11
@askpt askpt changed the title refactor!: improve EventExecutor refactor!: Improve EventExecutor Feb 28, 2025
@askpt askpt requested a review from Copilot February 28, 2025 13:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR refactors the EventExecutor and related classes for improved code readability, performance, and enhanced null safety. Key changes include replacing explicit constructor calls with array initializer syntax for collections, switching from Thread to Task-based asynchronous processing, and adding null-safety checks on EventChannel usages.

Reviewed Changes

File Description
src/OpenFeature/EventExecutor.cs Refactored to use Task.Run instead of Thread, updated collection initializations, and improved event handling.
test/OpenFeature.Tests/Providers/Memory/InMemoryProviderTests.cs Added null-forgiving operator to EventChannel usage in tests.
src/OpenFeature/Providers/Memory/InMemoryProvider.cs Added null checks before writing to the EventChannel to improve null safety.
test/OpenFeature.Tests/TestImplementations.cs Updated EventChannel usage with null-forgiving operator.
src/OpenFeature/FeatureProvider.cs Updated EventChannel to be nullable for enhanced null safety.

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

message = "Provider is ready";
}
else if (status == ProviderStatus.Error && eventType == ProviderEventTypes.ProviderError)
var message = status switch
Copy link
Member

Choose a reason for hiding this comment

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

nice. 😎

}
}

private void ProcessClientHandlers(Event e)
Copy link
Member

Choose a reason for hiding this comment

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

You removed a comment, but I guess the method name makes it clear what's happening now, so I'm fine with it.

Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

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

Good improvements, thanks.


private ILogger _logger;

public EventExecutor()
{
this._logger = NullLogger<EventExecutor>.Instance;
var eventProcessing = new Thread(this.ProcessEventAsync);
eventProcessing.Start();
Task.Run(this.ProcessEventAsync);
Copy link
Member

Choose a reason for hiding this comment

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

I should have caught this earlier.

@toddbaert toddbaert self-requested a review March 7, 2025 18:40
@toddbaert
Copy link
Member

@askpt could you explain the breaking change? How could the event channel be null if we set it? I must be missing something.

I guess this would force providers to do a null check, right? I guess this would only break providers? I won't have any impact on consumers will it? I don't think we want to release a v3 for this.

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.

2 participants