Skip to content

Commit 5582794

Browse files
authored
[ML] Fix ModelRegistryMetadataTests intermittent failures (#125883)
unmute test
1 parent 1f7e26c commit 5582794

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

muted-tests.yml

-3
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,6 @@ tests:
389389
- class: org.elasticsearch.xpack.ilm.TimeSeriesDataStreamsIT
390390
method: testSearchableSnapshotAction
391391
issue: https://github.com/elastic/elasticsearch/issues/125867
392-
- class: org.elasticsearch.xpack.inference.registry.ModelRegistryMetadataTests
393-
method: testUpgrade
394-
issue: https://github.com/elastic/elasticsearch/issues/125554
395392
- class: org.elasticsearch.xpack.downsample.DataStreamLifecycleDownsampleDisruptionIT
396393
method: testDataStreamLifecycleDownsampleRollingRestart
397394
issue: https://github.com/elastic/elasticsearch/issues/123769

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/registry/ModelRegistryMetadata.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
public class ModelRegistryMetadata implements Metadata.ProjectCustom {
5252
public static final String TYPE = "model_registry";
5353

54-
public static final ModelRegistryMetadata EMPTY = new ModelRegistryMetadata(ImmutableOpenMap.of(), Set.of());
54+
public static final ModelRegistryMetadata EMPTY_NOT_UPGRADED = new ModelRegistryMetadata(ImmutableOpenMap.of(), Set.of());
55+
public static final ModelRegistryMetadata EMPTY_UPGRADED = new ModelRegistryMetadata(ImmutableOpenMap.of());
5556

5657
private static final ParseField UPGRADED_FIELD = new ParseField("upgraded");
5758
private static final ParseField MODELS_FIELD = new ParseField("models");
@@ -87,7 +88,7 @@ public class ModelRegistryMetadata implements Metadata.ProjectCustom {
8788

8889
public static ModelRegistryMetadata fromState(ProjectMetadata projectMetadata) {
8990
ModelRegistryMetadata resp = projectMetadata.custom(TYPE);
90-
return resp != null ? resp : EMPTY;
91+
return resp != null ? resp : EMPTY_NOT_UPGRADED;
9192
}
9293

9394
public ModelRegistryMetadata withAddedModel(String inferenceEntityId, MinimalServiceSettings settings) {

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/registry/ModelRegistryMetadataTests.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
import java.util.Map;
2323
import java.util.Set;
2424

25+
import static org.hamcrest.Matchers.containsString;
2526
import static org.hamcrest.Matchers.equalTo;
2627

2728
public class ModelRegistryMetadataTests extends AbstractChunkedSerializingTestCase<ModelRegistryMetadata> {
2829
public static ModelRegistryMetadata randomInstance() {
29-
return randomInstance(randomBoolean());
30+
return randomInstance(randomBoolean(), true);
3031
}
3132

32-
public static ModelRegistryMetadata randomInstance(boolean isUpgraded) {
33-
if (rarely() && isUpgraded == false) {
34-
return ModelRegistryMetadata.EMPTY;
33+
public static ModelRegistryMetadata randomInstance(boolean isUpgraded, boolean acceptsEmpty) {
34+
if (rarely() && acceptsEmpty) {
35+
return isUpgraded ? ModelRegistryMetadata.EMPTY_UPGRADED : ModelRegistryMetadata.EMPTY_NOT_UPGRADED;
3536
}
3637
int size = randomIntBetween(1, 5);
3738

@@ -82,7 +83,7 @@ protected Writeable.Reader<ModelRegistryMetadata> instanceReader() {
8283
}
8384

8485
public void testUpgrade() {
85-
var metadata = randomInstance(false);
86+
var metadata = randomInstance(false, false);
8687
var metadataWithTombstones = metadata.withRemovedModel(Set.of(randomFrom(metadata.getModelMap().keySet())));
8788

8889
var indexMetadata = metadata.withAddedModel(randomAlphanumericOfLength(10), MinimalServiceSettingsTests.randomInstance());
@@ -99,9 +100,10 @@ public void testUpgrade() {
99100
}
100101

101102
public void testAlreadyUpgraded() {
102-
var metadata = randomInstance(true);
103-
var indexMetadata = randomInstance(true);
103+
var metadata = randomInstance(true, true);
104+
var indexMetadata = randomInstance(true, true);
104105

105106
var exc = expectThrows(IllegalArgumentException.class, () -> metadata.withUpgradedModels(indexMetadata.getModelMap()));
107+
assertThat(exc.getMessage(), containsString("upgraded"));
106108
}
107109
}

0 commit comments

Comments
 (0)