Skip to content

Commit b4a2cd8

Browse files
authored
Use 3rd party task to run integration tests on external service (#56588)
Backport of #56587 for 7.x
1 parent 52c555e commit b4a2cd8

File tree

18 files changed

+314
-497
lines changed

18 files changed

+314
-497
lines changed

plugins/repository-azure/build.gradle

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import org.elasticsearch.gradle.MavenFilteringHack
12
import org.elasticsearch.gradle.info.BuildParams
23

4+
import static org.elasticsearch.gradle.PropertyNormalization.DEFAULT
5+
import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
6+
37
/*
48
* Licensed to Elasticsearch under one or more contributor
59
* license agreements. See the NOTICE file distributed with
@@ -34,7 +38,7 @@ dependencies {
3438

3539
restResources {
3640
restApi {
37-
includeCore '_common', 'cluster', 'nodes'
41+
includeCore '_common', 'cluster', 'nodes', 'snapshot', 'bulk', 'count', 'indices'
3842
}
3943
}
4044

@@ -69,16 +73,13 @@ thirdPartyAudit {
6973
)
7074
}
7175

72-
check {
73-
// also execute the QA tests when testing the plugin
74-
dependsOn 'qa:microsoft-azure-storage:check'
75-
}
76+
boolean useFixture = false
7677

77-
testClusters {
78-
integTest {
79-
keystore 'azure.client.integration_test.account', 'azure_account'
80-
keystore 'azure.client.integration_test.key', 'azure_key'
81-
}
78+
def azureAddress = {
79+
assert useFixture: 'closure should not be used without a fixture'
80+
int ephemeralPort = project(':test:fixtures:azure-fixture').postProcessFixture.ext."test.fixtures.azure-fixture.tcp.8091"
81+
assert ephemeralPort > 0
82+
return 'ignored;DefaultEndpointsProtocol=http;BlobEndpoint=http://127.0.0.1:' + ephemeralPort + '/'
8283
}
8384

8485
String azureAccount = System.getenv("azure_storage_account")
@@ -87,19 +88,60 @@ String azureContainer = System.getenv("azure_storage_container")
8788
String azureBasePath = System.getenv("azure_storage_base_path")
8889
String azureSasToken = System.getenv("azure_storage_sas_token")
8990

91+
if (!azureAccount && !azureKey && !azureContainer && !azureBasePath && !azureSasToken) {
92+
azureAccount = 'azure_integration_test_account'
93+
azureKey = 'YXp1cmVfaW50ZWdyYXRpb25fdGVzdF9rZXk=' // The key is "azure_integration_test_key" encoded using base64
94+
azureContainer = 'container'
95+
azureBasePath = ''
96+
azureSasToken = ''
97+
useFixture = true
98+
99+
apply plugin: 'elasticsearch.test.fixtures'
100+
testFixtures.useFixture ':test:fixtures:azure-fixture', 'azure-fixture'
101+
}
102+
103+
Map<String, Object> expansions = [
104+
'container': azureContainer,
105+
'base_path': azureBasePath + "_integration_tests"
106+
]
107+
108+
processTestResources {
109+
inputs.properties(expansions)
110+
MavenFilteringHack.filter(it, expansions)
111+
}
112+
90113
test {
114+
// this is tested explicitly in a separate test task
91115
exclude '**/AzureStorageCleanupThirdPartyTests.class'
92116
}
93117

94-
task thirdPartyTest(type: Test) {
118+
testClusters {
119+
integTest {
120+
keystore 'azure.client.integration_test.account', azureAccount
121+
if (azureKey != null && azureKey.isEmpty() == false) {
122+
keystore 'azure.client.integration_test.key', azureKey
123+
}
124+
if (azureSasToken != null && azureSasToken.isEmpty() == false) {
125+
keystore 'azure.client.integration_test.sas_token', azureSasToken
126+
}
127+
if (useFixture) {
128+
setting 'azure.client.integration_test.endpoint_suffix', azureAddress
129+
String firstPartOfSeed = BuildParams.testSeed.tokenize(':').get(0)
130+
setting 'thread_pool.repository_azure.max', (Math.abs(Long.parseUnsignedLong(firstPartOfSeed, 16) % 10) + 1).toString(), System.getProperty('ignore.tests.seed') == null ? DEFAULT : IGNORE_VALUE
131+
}
132+
}
133+
}
134+
135+
task azureThirdPartyTest(type: Test) {
136+
dependsOn tasks.integTest
95137
include '**/AzureStorageCleanupThirdPartyTests.class'
96138
systemProperty 'test.azure.account', azureAccount ? azureAccount : ""
97139
systemProperty 'test.azure.key', azureKey ? azureKey : ""
98140
systemProperty 'test.azure.sas_token', azureSasToken ? azureSasToken : ""
99141
systemProperty 'test.azure.container', azureContainer ? azureContainer : ""
100142
systemProperty 'test.azure.base', (azureBasePath ? azureBasePath : "") + "_third_party_tests_" + BuildParams.testSeed
143+
if (useFixture) {
144+
nonInputProperties.systemProperty 'test.azure.endpoint_suffix', "${-> azureAddress.call() }"
145+
}
101146
}
102-
103-
if (azureAccount || azureKey || azureContainer || azureBasePath || azureSasToken) {
104-
check.dependsOn(thirdPartyTest)
105-
}
147+
check.dependsOn(azureThirdPartyTest)

plugins/repository-azure/qa/build.gradle

Lines changed: 0 additions & 1 deletion
This file was deleted.

plugins/repository-azure/qa/microsoft-azure-storage/build.gradle

Lines changed: 0 additions & 94 deletions
This file was deleted.

plugins/repository-azure/qa/microsoft-azure-storage/src/test/java/org/elasticsearch/repositories/azure/AzureStorageRepositoryClientYamlTestSuiteIT.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureStorageCleanupThirdPartyTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
5050
return pluginList(AzureRepositoryPlugin.class);
5151
}
5252

53+
@Override
54+
protected Settings nodeSettings() {
55+
final String endpoint = System.getProperty("test.azure.endpoint_suffix");
56+
if (Strings.hasText(endpoint)) {
57+
return Settings.builder()
58+
.put(super.nodeSettings())
59+
.put("azure.client.default.endpoint_suffix", endpoint)
60+
.build();
61+
}
62+
return super.nodeSettings();
63+
}
64+
5365
@Override
5466
protected SecureSettings credentials() {
5567
assertThat(System.getProperty("test.azure.account"), not(blankOrNullString()));

0 commit comments

Comments
 (0)