Skip to content

Commit 04f5ce9

Browse files
committed
Fixed YAML tests skipping YAML file with parsing issue
1 parent 6c0815c commit 04f5ce9

File tree

2 files changed

+34
-92
lines changed

2 files changed

+34
-92
lines changed

tests/Utility.php

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ public static function cleanUpCluster(Client $client): void
175175
self::ensureNoInitializingShards($client);
176176
self::wipeCluster($client);
177177
self::waitForClusterStateUpdatesToFinish($client);
178-
self::checkForUnexpectedlyRecreatedObjects($client);
179178
}
180179

181180
/**
@@ -830,85 +829,4 @@ private static function waitForClusterStateUpdatesToFinish(Client $client, int $
830829
$stillWaiting = ! empty($result['tasks']);
831830
} while ($stillWaiting && time() < ($start + $timeout));
832831
}
833-
834-
/**
835-
* Returns all the unexpected ilm policies, removing $exclusions from the list
836-
*/
837-
private static function getAllUnexpectedIlmPolicies(Client $client, array $exclusions): array
838-
{
839-
try {
840-
$policies = $client->ilm()->getLifecycle();
841-
} catch (ElasticsearchException $e) {
842-
return [];
843-
}
844-
foreach ($policies as $name => $value) {
845-
if (in_array($name, $exclusions)) {
846-
unset($policies[$name]);
847-
}
848-
}
849-
return $policies;
850-
}
851-
852-
/**
853-
* Returns all the unexpected templates
854-
*/
855-
private static function getAllUnexpectedTemplates(Client $client): array
856-
{
857-
if (!self::$hasXPack) {
858-
return [];
859-
}
860-
$unexpected = [];
861-
// In case of bwc testing, if all nodes are before 7.7.0 then no need
862-
// to attempt to delete component and composable index templates,
863-
// because these were introduced in 7.7.0:
864-
if (version_compare(self::getVersion($client), '7.6.99') > 0) {
865-
$result = $client->indices()->getIndexTemplate();
866-
foreach ($result['index_templates'] as $template) {
867-
if (!self::isXPackTemplate($template['name'])) {
868-
$unexpected[$template['name']] = true;
869-
}
870-
}
871-
$result = $client->cluster()->getComponentTemplate();
872-
foreach ($result['component_templates'] as $template) {
873-
if (!self::isXPackTemplate($template['name'])) {
874-
$unexpected[$template['name']] = true;
875-
}
876-
}
877-
}
878-
$result = $client->indices()->getIndexTemplate();
879-
foreach ($result['index_templates'] as $template) {
880-
if (!self::isXPackTemplate($template['name'])) {
881-
$unexpected[$template['name']] = true;
882-
}
883-
}
884-
return array_keys($unexpected);
885-
}
886-
887-
888-
/**
889-
* This method checks whether ILM policies or templates get recreated after
890-
* they have been deleted. If so, we are probably deleting them unnecessarily,
891-
* potentially causing test performance problems. This could happen for example
892-
* if someone adds a new standard ILM policy but forgets to put it in the
893-
* exclusion list in this test.
894-
*/
895-
private static function checkForUnexpectedlyRecreatedObjects(Client $client): void
896-
{
897-
if (self::$hasIlm) {
898-
$policies = self::getAllUnexpectedIlmPolicies($client, self::preserveILMPolicyIds());
899-
if (count($policies) > 0) {
900-
throw new Exception(sprintf(
901-
"Expected no ILM policies after deletions, but found %s",
902-
implode(',', array_keys($policies))
903-
));
904-
}
905-
}
906-
$templates = self::getAllUnexpectedTemplates($client);
907-
if (count($templates) > 0) {
908-
throw new Exception(sprintf(
909-
"Expected no templates after deletions, but found %s",
910-
implode(',', array_keys($templates))
911-
));
912-
}
913-
}
914832
}

util/YamlTests.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use RecursiveDirectoryIterator;
2323
use RecursiveIteratorIterator;
2424
use stdClass;
25+
use Throwable;
2526

2627
use function yaml_parse;
2728

@@ -34,6 +35,10 @@ class YamlTests
3435
const TEMPLATE_FUNCTION_SKIPPED = __DIR__ . '/template/test/function-skipped';
3536
const ELASTICSEARCH_GIT_URL = 'https://github.com/elastic/elasticsearch/tree/%s/rest-api-spec/src/main/resources/rest-api-spec/test/%s';
3637

38+
const YAML_FILES_TO_OMIT = [
39+
'platinum/eql/10_basic.yml'
40+
];
41+
3742
const SKIPPED_TEST_OSS = [
3843
'Cat\Nodeattrs\_10_BasicTest::TestCatNodesAttrsOutput' => 'Regexp error, it seems not compatible with PHP',
3944
'Cat\Shards\_10_BasicTest::TestCatShardsOutput' => 'Regexp error, it seems not compatible with PHP',
@@ -142,22 +147,41 @@ private function getAllTests(string $dir): array
142147
$parsed = [];
143148
// Iterate over the Yaml test files
144149
foreach (new RecursiveIteratorIterator($it) as $file) {
145-
if ($file->getExtension() === 'yml') {
146-
$content = file_get_contents($file->getPathname());
147-
$content = str_replace(' y: ', " 'y': ", $content); // replace "y:" with "'y':" due the y/true conversion in YAML 1.1
150+
if ($file->getExtension() !== 'yml') {
151+
continue;
152+
}
153+
$omit = false;
154+
foreach (self::YAML_FILES_TO_OMIT as $fileOmit) {
155+
if (false !== strpos($file->getPathname(), $fileOmit)) {
156+
$omit = true;
157+
break;
158+
}
159+
}
160+
if ($omit) {
161+
continue;
162+
}
163+
$content = file_get_contents($file->getPathname());
164+
$content = str_replace(' y: ', " 'y': ", $content); // replace "y:" with "'y':" due the y/true conversion in YAML 1.1
165+
try {
148166
$test = yaml_parse($content, -1, $ndocs, [
149167
YAML_MAP_TAG => function($value, $tag, $flags) {
150168
return empty($value) ? new stdClass : $value;
151169
}
152170
]);
153-
if (false === $test) {
154-
throw new Exception(sprintf(
155-
"YAML parse error file %s",
156-
$file->getPathname()
157-
));
158-
}
159-
$parsed[$file->getPathname()] = $test;
171+
} catch (Throwable $e) {
172+
throw new Exception(sprintf(
173+
"YAML parse error file %s: %s",
174+
$file->getPathname(),
175+
$e->getMessage()
176+
));
177+
}
178+
if (false === $test) {
179+
throw new Exception(sprintf(
180+
"YAML parse error file %s",
181+
$file->getPathname()
182+
));
160183
}
184+
$parsed[$file->getPathname()] = $test;
161185
}
162186
return $parsed;
163187
}

0 commit comments

Comments
 (0)