Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class TransportService extends AbstractLifecycleComponent
/**
* A feature flag enabling transport upgrades for serverless.
*/
private static final String SERVERLESS_TRANSPORT_SYSTEM_PROPERTY = "es.serverless_transport";
static final String SERVERLESS_TRANSPORT_SYSTEM_PROPERTY = "es.serverless_transport";
private static final boolean SERVERLESS_TRANSPORT_FEATURE_FLAG = Booleans.parseBoolean(
System.getProperty(SERVERLESS_TRANSPORT_SYSTEM_PROPERTY),
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ public void testRejectsMismatchedBuildHash() {
public void testAcceptsMismatchedServerlessBuildHash() {
assumeTrue("Current build needs to be a snapshot", Build.current().isSnapshot());
assumeTrue("Security manager needs to be disabled", System.getSecurityManager() == null);
System.setProperty("es.serverless", Boolean.TRUE.toString()); // security manager blocks this
System.setProperty(TransportService.SERVERLESS_TRANSPORT_SYSTEM_PROPERTY, Boolean.TRUE.toString()); // security manager blocks
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the test reliably fail before this change? You mentioned reproducing it, but I wasn't sure of the frequency.

I'm wondering why this didn't fail in the first place when it was added. Maybe we could bundle the try-block logic into a method, and exercise it once with System.setProperty(TransportService.SERVERLESS_TRANSPORT_SYSTEM_PROPERTY, Boolean.TRUE.toString()); set to true (succeeds) and then a second time set to false (should throw)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does the test reliably fail before this change?

yes, test fails every time with

./gradlew ":server:test" --tests "org.elasticsearch.transport.TransportServiceHandshakeTests.testAcceptsMismatchedServerlessBuildHash" -Dtests.seed=8278A46E39005C96 -Dtests.jvm.argline="-Des.entitlements.enabled=" -Dtests.locale=en-001 -Dtests.timezone=US/Pacific -Druntime.java=24

I believe test suppose to test this flag by going through debugger.

private void maybeThrowOnIncompatibleBuild(@Nullable DiscoveryNode node, @Nullable Exception e) {
if (SERVERLESS_TRANSPORT_FEATURE_FLAG == false && isIncompatibleBuild(version, buildHash)) {
throwOnIncompatibleBuild(node, e);
}
}

But it set with "es.serverless_transport".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we could bundle the try-block

Do you mean put System.setProperty inside try-catch? I dont think System.setProperty throws here. Also if it throws entire test case will not run.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, then it reliably fixes the test 👍 Thanks.

Optionally I'd suggest making the test more robust by also proving the test setup would normally throw, and then verifying that it does not throw with the serverless Property set -- e.g. put the try-block code in a method and call it twice, with and without the Property setting. But that's a test improvement, not a test fix, so I don't feel strongly about it.

Copy link
Member

Choose a reason for hiding this comment

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

I was curious why it started to fail now since all related changes have been around more than 1 year. It turns out the reason is that the test was never executed because of the following line

assumeTrue("Security manager needs to be disabled", System.getSecurityManager() == null);

SecurityManager is removed in JDK 24. Hence it started to fail now with JDK24 while it is skipped when running with all prior JDK versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the test was "muted" for all this time? :)

Copy link
Member

@ywangd ywangd Feb 13, 2025

Choose a reason for hiding this comment

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

Yeah I think it definitely has Not ran since #95754

// this
try {
final DisruptingTransportInterceptor transportInterceptorA = new DisruptingTransportInterceptor();
final DisruptingTransportInterceptor transportInterceptorB = new DisruptingTransportInterceptor();
Expand All @@ -404,7 +405,7 @@ public void testAcceptsMismatchedServerlessBuildHash() {
AbstractSimpleTransportTestCase.connectToNode(transportServiceA, transportServiceB.getLocalNode(), TestProfiles.LIGHT_PROFILE);
assertTrue(transportServiceA.nodeConnected(transportServiceB.getLocalNode()));
} finally {
System.clearProperty("es.serverless");
System.clearProperty(TransportService.SERVERLESS_TRANSPORT_SYSTEM_PROPERTY);
}
}

Expand Down