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

Add tests for context values with scope semantics #3516

Merged
merged 4 commits into from
Jul 7, 2023
Merged

Conversation

chemicL
Copy link
Member

@chemicL chemicL commented Jun 23, 2023

No description provided.

@chemicL chemicL added the area/context This issue is related to the Context label Jun 23, 2023
@chemicL chemicL self-assigned this Jun 23, 2023
@chemicL chemicL marked this pull request as ready for review July 5, 2023 11:58
@chemicL chemicL requested a review from a team as a code owner July 5, 2023 11:58
Copy link
Contributor

@OlegDokuka OlegDokuka left a comment

Choose a reason for hiding this comment

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

overall LGTM. Do we wanna add more scenarios. e.g. flatMap, concatMap, and similars?


AtomicReference<ScopedValue> valueInsideFlatMap = new AtomicReference<>();

try (ScopedValue.Scope v1scope1 = v1.open()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we wanna check as well that if one modifies Scope then nothing wrong happens?

Copy link
Member Author

Choose a reason for hiding this comment

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

in what sense do you mean? modifying the v1scope1 or opening a new scope?

Copy link
Contributor

@OlegDokuka OlegDokuka Jul 5, 2023

Choose a reason for hiding this comment

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

I was thinking about 2 cases:

  • one call scope close() manually (probably that would break everything and should be illegal 🧐)
  • one opens a scope manually and then closes it manually somewhere else in the chain e.g.
    java var scope = ... mono .doOnSubscibe(__-> scope.set(Scope.open())) .doAfterTerminate(__-> scope.get().close())
    which should be probably legal and should not break anything (but I'm not sure)

Copy link
Member Author

Choose a reason for hiding this comment

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

one call scope close() manually (probably that would break everything and should be illegal 🧐)

Yes, this is illegal and the behaviour should be undefined. Adding tests for it would become some sort of a specification.

one opens a scope manually and then closes it manually somewhere else in the chain e.g.
java var scope = ... mono .doOnSubscibe(-> scope.set(Scope.open())) .doAfterTerminate(-> scope.get().close())
which should be probably legal and should not break anything (but I'm not sure)

In this case it's also illegal in my opinion - the reactive chain is agnostic of Thread switches. Scopes are Thread-bound. If you open a Scope in one Thread, you must close it in the same Thread. Doing that using reactive operators is dangerous, I'd avoid adding a test that shows such a pattern.

@OlegDokuka
Copy link
Contributor

OlegDokuka commented Jul 5, 2023

Also, should not this be targeted for 3.5.x?

@chemicL chemicL changed the base branch from main to 3.5.x July 5, 2023 12:11
@chemicL
Copy link
Member Author

chemicL commented Jul 5, 2023

Also, should not this be targeted for 3.5.x?

I actually updated that at the same time you started reviewing. The PR was in draft mode before 3.5.x existed, so it aimed for main initialy.

@chemicL
Copy link
Member Author

chemicL commented Jul 6, 2023

overall LGTM. Do we wanna add more scenarios. e.g. flatMap, concatMap, and similars?

I added a test for flatMap in a concurrent scenario to verify that appropriate scopes are created in child threads.

@chemicL
Copy link
Member Author

chemicL commented Jul 6, 2023

@OlegDokuka I updated to the latest code from micrometer-metrics/context-propagation#123 which is now finalized.

@chemicL chemicL merged commit 5358e4d into 3.5.x Jul 7, 2023
7 checks passed
@reactorbot
Copy link

@chemicL this PR seems to have been merged on a maintenance branch, please ensure the change is merge-forwarded to intermediate maintenance branches and up to main 🙇

chemicL added a commit that referenced this pull request Jul 7, 2023
@chemicL chemicL deleted the test-scopes branch July 7, 2023 10:41
@chemicL chemicL added this to the 3.5.8 milestone Jul 12, 2023
@chemicL chemicL added the type/enhancement A general enhancement label Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/context This issue is related to the Context type/enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants