Skip to content

Commit ed6e76a

Browse files
authored
Adjust SearchableSnapshotsLicenseIntegTests.testShardAllocationOnInvalidLicense (#77757) (#77760)
This tests sometimes fails because it expects the last PostStartTrialRequest to always "upgrade" the current license that it just nullified to a trial license; but there is a race in this test with the LicenceService that detects that no license exists in the cluster state (because the test set it to null) and self generates a trial license for the cluster too. When the self generation is processed before the PostStartTrialRequest the latter will return a TRIAL_ALREADY_ACTIVATED response. Since the purpose of this test is to verify that the searchable snapshot shards failed when the license change and came back when the trial license if activated again, I think we can just adjust the test to accommodate for the 2 types of responses. Closes #72329
1 parent 79956c2 commit ed6e76a

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsLicenseIntegTests.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.cluster.ClusterState;
2424
import org.elasticsearch.cluster.health.ClusterHealthStatus;
2525
import org.elasticsearch.cluster.metadata.Metadata;
26-
import org.elasticsearch.cluster.service.ClusterService;
2726
import org.elasticsearch.common.Strings;
2827
import org.elasticsearch.common.settings.Settings;
2928
import org.elasticsearch.license.DeleteLicenseAction;
@@ -36,7 +35,6 @@
3635
import org.elasticsearch.license.PostStartTrialResponse;
3736
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
3837
import org.elasticsearch.test.ESIntegTestCase;
39-
import org.elasticsearch.test.junit.annotations.TestLogging;
4038
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction;
4139
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest;
4240
import org.elasticsearch.xpack.searchablesnapshots.action.ClearSearchableSnapshotsCacheAction;
@@ -56,6 +54,7 @@
5654
import static org.hamcrest.Matchers.greaterThan;
5755
import static org.hamcrest.Matchers.instanceOf;
5856
import static org.hamcrest.Matchers.notNullValue;
57+
import static org.hamcrest.Matchers.oneOf;
5958

6059
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST)
6160
public class SearchableSnapshotsLicenseIntegTests extends BaseFrozenSearchableSnapshotsIntegTestCase {
@@ -145,7 +144,6 @@ public void testClearCacheRequiresLicense() throws ExecutionException, Interrupt
145144
}
146145
}
147146

148-
@TestLogging(reason = "https://github.com/elastic/elasticsearch/issues/72329", value = "org.elasticsearch.license:DEBUG")
149147
public void testShardAllocationOnInvalidLicense() throws Exception {
150148
// check that shards have been failed as part of invalid license
151149
assertBusy(
@@ -170,23 +168,19 @@ public void testShardAllocationOnInvalidLicense() throws Exception {
170168
waitNoPendingTasksOnAll();
171169
ensureClusterStateConsistency();
172170

173-
try {
174-
PostStartTrialRequest startTrialRequest = new PostStartTrialRequest().setType(License.LicenseType.TRIAL.getTypeName())
175-
.acknowledge(true);
176-
PostStartTrialResponse resp = client().execute(PostStartTrialAction.INSTANCE, startTrialRequest).get();
177-
assertEquals(PostStartTrialResponse.Status.UPGRADED_TO_TRIAL, resp.getStatus());
178-
} catch (AssertionError ae) {
179-
try {
180-
final ClusterService clusterService = internalCluster().getCurrentMasterNodeInstance(ClusterService.class);
181-
logger.error(
182-
"Failed to start trial license again, cluster state on master node is:\n{}",
183-
Strings.toString(clusterService.state(), false, true)
184-
);
185-
} catch (Exception e) {
186-
ae.addSuppressed(e);
187-
}
188-
throw ae;
189-
}
171+
PostStartTrialRequest request = new PostStartTrialRequest().setType(License.LicenseType.TRIAL.getTypeName()).acknowledge(true);
172+
final PostStartTrialResponse response = client().execute(PostStartTrialAction.INSTANCE, request).get();
173+
assertThat(
174+
response.getStatus(),
175+
oneOf(
176+
PostStartTrialResponse.Status.UPGRADED_TO_TRIAL,
177+
// The LicenceService automatically generates a license of {@link LicenceService#SELF_GENERATED_LICENSE_TYPE} type
178+
// if there is no license found in the cluster state (see {@link LicenceService#registerOrUpdateSelfGeneratedLicense).
179+
// Since this test explicitly removes the LicensesMetadata from cluster state it is possible that the self generated
180+
// license is created before the PostStartTrialRequest is acked.
181+
PostStartTrialResponse.Status.TRIAL_ALREADY_ACTIVATED
182+
)
183+
);
190184
// check if cluster goes green again after valid license has been put in place
191185
ensureGreen(indexName);
192186
}

0 commit comments

Comments
 (0)