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

Improve SimpleAliasRegistryTests #31353

Closed
2 tasks done
sbrannen opened this issue Oct 3, 2023 · 5 comments
Closed
2 tasks done

Improve SimpleAliasRegistryTests #31353

sbrannen opened this issue Oct 3, 2023 · 5 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: task A general task
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Oct 3, 2023

Overview

This is a followup to #31348.

As stated in the TODO in SimpleAliasRegistryTests, the resolveAliasesWithComplexPlaceholderReplacement() test is flaky.

It passes as-is with ALIAS4 set to "testAlias4", and it also passes for values such as "x", "xx", "xxx", "xxxx", and likely numerous other values.

However, it fails for "alias4", "xxxxx", "testAli", and likely numerous other values.

The issue might be due to the use of a Mockito mock, but I do not currently have the time to investigate it further.

Deliverables

  • Determine why the test is flaky.
  • Set ALIAS4 to "alias4" once the issue is resolved.
@sbrannen sbrannen added type: task A general task in: core Issues in core modules (aop, beans, core, context, expression) labels Oct 3, 2023
@sbrannen sbrannen added this to the 6.1.x milestone Oct 3, 2023
@sbrannen
Copy link
Member Author

sbrannen commented Oct 4, 2023

@e-freni has volunteered to investigate this issue and potentially submit a PR to resolve it.

@e-freni
Copy link
Contributor

e-freni commented Oct 13, 2023

@sbrannen I investigated the issue, and it concerns the hashmap. The length of the string affects the hash used for sorting in the hashmap. Consequently, 'x,' 'xx,' and 'testAlias4' push the key to be the first element tested, which allows the expected exception to be thrown. If you use 'alias4,' the calculated hash pushes the value to the end of the map, thus the method self-corrects the content of 'aliasMap' and prevents the exception from occurring. It can be fixed for 'alias4' if it's fixed, but for all variable string lengths, the test logic needs to be modified to cover those cases. Even though I would make them explicit and not with ALIAS4 constant. Let me know if this solution works for you, and I'll get to it.

@snicoll
Copy link
Member

snicoll commented Dec 22, 2023

@e-freni thanks very much for investigating. If you're still up for it, we'd be happy to review a PR. Let us know please.

@sbrannen sbrannen self-assigned this Jan 11, 2024
@sbrannen
Copy link
Member Author

Indeed, thanks for the detailed analysis, @e-freni! 👍

The length of the string affects the hash used for sorting in the hashmap. Consequently, 'x,' 'xx,' and 'testAlias4' push the key to be the first element tested, which allows the expected exception to be thrown. If you use 'alias4,' the calculated hash pushes the value to the end of the map, thus the method self-corrects the content of 'aliasMap' and prevents the exception from occurring.

Aha... you're saying the iteration order over the map elements in resolveAliases(...) (via aliasCopy.forEach((alias, registeredName) -> { ...) depends on the hash code values of the alias keys in the map.

So that means the main issue is not with the test but rather what I would consider a bug in SimpleAliasRegistry.

Specifically, changing the names of aliases while maintaining the exact same set of logical alias pairs should not work sometimes and fail at other times.

@sbrannen sbrannen added type: bug A general bug and removed type: task A general task labels Jan 11, 2024
@sbrannen sbrannen modified the milestones: 6.1.x, 6.1.4 Jan 11, 2024
@sbrannen sbrannen assigned jhoeller and sbrannen and unassigned sbrannen Jan 11, 2024
@sbrannen sbrannen changed the title Determine why resolveAliasesWithComplexPlaceholderReplacement() test is flaky Fix flaky resolveAliasesWithComplexPlaceholderReplacement() test Jan 12, 2024
@sbrannen sbrannen added type: task A general task and removed type: bug A general bug labels Jan 12, 2024
@sbrannen sbrannen changed the title Fix flaky resolveAliasesWithComplexPlaceholderReplacement() test Fix flaky test in SimpleAliasRegistryTests Jan 12, 2024
@sbrannen sbrannen changed the title Fix flaky test in SimpleAliasRegistryTests Improve SimpleAliasRegistryTests Jan 14, 2024
@sbrannen
Copy link
Member Author

Based on the input from @e-freni and further findings while investigating the issue, I have repurposed this issue to simply improve the status quo for SimpleAliasRegistryTests.

The "flakiness" of the alias resolution algorithm is now being investigated in #32024.

sbrannen added a commit to sbrannen/spring-framework that referenced this issue Jan 14, 2024
Prior to this commit, the alias resolution error message in
SimpleAliasRegistry was misleading.

When a resolution conflict is detected, the IllegalStateException
thrown by resolveAliases(...) now states that the resolved alias is
already registered for an `existingName` instead of the `registeredName`.

See spring-projectsgh-31353
Closes spring-projectsgh-32025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: task A general task
Projects
None yet
Development

No branches or pull requests

4 participants