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

SOLR-17265: Fix randomized PRS testing #2436

Merged
merged 5 commits into from
May 2, 2024

Conversation

HoustonPutman
Copy link
Contributor

https://issues.apache.org/jira/browse/SOLR-17265

This fixes the test errors introduced by #2230

I'm not really certain what the previous logic was supposed to be doing, but isPRS() practically returned a random true or false every time it was called, since the "use.per-replica" sysProp was never set.

I've simplified the logic considerably. Before a class is run "solr.prs.default" is set to either true or false (either randomly, or determined by the Class annotation). Then ever call to isPRS() will read that sysProp to determine if the default is PRS or not.

public static boolean isPRS() {
return PRS_DEFAULT_PROP == null
? random().nextBoolean()
Copy link
Contributor

Choose a reason for hiding this comment

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

oh wow I see how this was the problem, leading to too-little control in consistency over wether it's enabled or not in practice

Copy link
Contributor

@gus-asf gus-asf left a comment

Choose a reason for hiding this comment

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

+1 to this and David's comments

Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

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

I'd like us to approach this in a general/patterned way; this isn't the only setting to do this for. Another is the distributed cluster processing booleans, which is already handled. See org.apache.solr.cloud.SolrCloudTestCase#configureCluster and MiniSolrCloudCluster.build

I feel both should be configured similarly (at the same places mostly).

Comment on lines 144 to 157
public static void setPrsDefault() {
Class<?> target = RandomizedTest.getContext().getTargetClass();
if (target != null && target.isAnnotationPresent(NoPrs.class)) return;
if (isPRS()) {
System.setProperty("solr.prs.default", "true");
String existingPrsDefault = EnvUtils.getProperty(PRS_DEFAULT_PROP);
String newPrsDefault;
if (target != null && target.isAnnotationPresent(NoPrs.class)) {
if (existingPrsDefault != null) {
System.setProperty(SAVED_PRS_DEFAULT_PROP, existingPrsDefault);
}
newPrsDefault = "false";
} else if (existingPrsDefault != null) {
newPrsDefault = existingPrsDefault;
} else {
newPrsDefault = Boolean.toString(random().nextBoolean());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we instead rely on TestRuleRestoreSystemProperties, thus don't need to restore whatever the pre-existing sys prop (set at CLI?) is?

@HoustonPutman
Copy link
Contributor Author

Thanks for the info on those. I've standardized both the reseting of sysProps as well as where the option is set from.

Comment on lines 62 to 63
public static TestRule syspropRestore =
new TestRuleRestoreSystemProperties(NUMERIC_DOCVALUES_SYSPROP, PRS_DEFAULT_PROP);
Copy link
Contributor

@dsmiley dsmiley May 1, 2024

Choose a reason for hiding this comment

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

AFAIK, this shouldn't be necessary because SolrTestCase (root of all Solr tests) already declares SystemPropertiesRestoreRule as a ClassRule and also STCJ4 has a test rule for this as well for test/method level restoration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh that makes sense. I'll remove the custom ones.

Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

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

Looks good, assuming tests pass.

@HoustonPutman HoustonPutman merged commit cae69c7 into apache:main May 2, 2024
3 checks passed
@HoustonPutman HoustonPutman deleted the prs-tests-fix branch May 2, 2024 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants