Skip to content

Commit be0e28c

Browse files
committed
Updated cleanUpCluster in Utility
1 parent 57ca4e6 commit be0e28c

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

tests/Utility.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,42 @@ public static function cleanUpCluster(Client $client): void
167167
self::ensureNoInitializingShards($client);
168168
self::wipeCluster($client);
169169
self::waitForClusterStateUpdatesToFinish($client);
170+
self::checkForUnexpectedlyRecreatedObjects($client);
171+
}
172+
173+
/**
174+
* This method checks whether ILM policies or templates get recreated after they have been deleted. If so, we are probably deleting
175+
* them unnecessarily, potentially causing test performance problems. This could happen for example if someone adds a new standard ILM
176+
* policy but forgets to put it in the exclusion list in this test.
177+
*
178+
* @see ESRestTestCase.java:checkForUnexpectedlyRecreatedObjects()
179+
*/
180+
private static function checkForUnexpectedlyRecreatedObjects(Client $client): void
181+
{
182+
if (self::$hasIlm) {
183+
$policies = self::getAllUnexpectedIlmPolicies($client);
184+
if (!empty($policies)) {
185+
throw new Exception(sprintf(
186+
"Expected no ILM policies after deletions, but found %s",
187+
implode(',', array_keys($policies))
188+
));
189+
}
190+
}
191+
}
192+
193+
/**
194+
* @see ESRestTestCase.java:getAllUnexpectedIlmPolicies()
195+
*/
196+
private static function getAllUnexpectedIlmPolicies(Client $client): array
197+
{
198+
try {
199+
return $client->ilm()->getLifecycle()->asArray();
200+
} catch (ClientResponseException $e) {
201+
if (in_array($e->getCode(), [400, 405])) {
202+
return [];
203+
}
204+
throw $e;
205+
}
170206
}
171207

172208
/**
@@ -621,9 +657,19 @@ private static function preserveILMPolicyIds(): array
621657
"ilm-history-ilm-policy",
622658
"slm-history-ilm-policy",
623659
"watch-history-ilm-policy",
660+
"watch-history-ilm-policy-16",
624661
"ml-size-based-ilm-policy",
625662
"logs",
626-
"metrics"
663+
"metrics",
664+
"synthetics",
665+
"7-days-default",
666+
"30-days-default",
667+
"90-days-default",
668+
"180-days-default",
669+
"365-days-default",
670+
".fleet-actions-results-ilm-policy",
671+
".deprecation-indexing-ilm-policy",
672+
".monitoring-8-ilm-policy"
627673
];
628674
}
629675

0 commit comments

Comments
 (0)