Skip to content

Commit dcae87d

Browse files
[ML] Fixing failing inference api streaming tests (elastic#118284)
* Fixing tests with alphanumeric strings * Removing prints
1 parent 4b868b0 commit dcae87d

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,6 @@ tests:
186186
- class: "org.elasticsearch.xpack.esql.qa.mixed.MixedClusterEsqlSpecIT"
187187
method: "test {scoring.*}"
188188
issue: https://github.com/elastic/elasticsearch/issues/117641
189-
- class: org.elasticsearch.xpack.inference.InferenceCrudIT
190-
method: testSupportedStream
191-
issue: https://github.com/elastic/elasticsearch/issues/117745
192189
- class: org.elasticsearch.xpack.esql.ccq.MultiClusterSpecIT
193190
method: test {scoring.QstrWithFieldAndScoringSortedEval}
194191
issue: https://github.com/elastic/elasticsearch/issues/117751
@@ -272,9 +269,6 @@ tests:
272269
- class: org.elasticsearch.packaging.test.ArchiveTests
273270
method: test51AutoConfigurationWithPasswordProtectedKeystore
274271
issue: https://github.com/elastic/elasticsearch/issues/118212
275-
- class: org.elasticsearch.xpack.inference.InferenceCrudIT
276-
method: testUnifiedCompletionInference
277-
issue: https://github.com/elastic/elasticsearch/issues/118210
278272
- class: org.elasticsearch.ingest.common.IngestCommonClientYamlTestSuiteIT
279273
issue: https://github.com/elastic/elasticsearch/issues/118215
280274
- class: org.elasticsearch.datastreams.DataStreamsClientYamlTestSuiteIT

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ public static void resetPortCounter() {
277277

278278
private static final SetOnce<Boolean> WARN_SECURE_RANDOM_FIPS_NOT_DETERMINISTIC = new SetOnce<>();
279279

280+
private static final String LOWER_ALPHA_CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
281+
private static final String UPPER_ALPHA_CHARACTERS = LOWER_ALPHA_CHARACTERS.toUpperCase(Locale.ROOT);
282+
private static final String DIGIT_CHARACTERS = "0123456789";
283+
private static final String ALPHANUMERIC_CHARACTERS = LOWER_ALPHA_CHARACTERS + UPPER_ALPHA_CHARACTERS + DIGIT_CHARACTERS;
284+
280285
static {
281286
Random random = initTestSeed();
282287
TEST_WORKER_VM_ID = System.getProperty(TEST_WORKER_SYS_PROPERTY, DEFAULT_TEST_WORKER_ID);
@@ -1200,6 +1205,21 @@ public static String randomAlphaOfLength(int codeUnits) {
12001205
return RandomizedTest.randomAsciiOfLength(codeUnits);
12011206
}
12021207

1208+
/**
1209+
* Generate a random string containing only alphanumeric characters.
1210+
* @param length the length of the string to generate
1211+
* @return the generated string
1212+
*/
1213+
public static String randomAlphanumericOfLength(int length) {
1214+
StringBuilder sb = new StringBuilder();
1215+
Random random = random();
1216+
for (int i = 0; i < length; i++) {
1217+
sb.append(ALPHANUMERIC_CHARACTERS.charAt(random.nextInt(ALPHANUMERIC_CHARACTERS.length())));
1218+
}
1219+
1220+
return sb.toString();
1221+
}
1222+
12031223
public static SecureString randomSecureStringOfLength(int codeUnits) {
12041224
var randomAlpha = randomAlphaOfLength(codeUnits);
12051225
return new SecureString(randomAlpha.toCharArray());

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/FeatureFlag.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
public enum FeatureFlag {
1919
TIME_SERIES_MODE("es.index_mode_feature_flag_registered=true", Version.fromString("8.0.0"), null),
2020
FAILURE_STORE_ENABLED("es.failure_store_feature_flag_enabled=true", Version.fromString("8.12.0"), null),
21-
SUB_OBJECTS_AUTO_ENABLED("es.sub_objects_auto_feature_flag_enabled=true", Version.fromString("8.16.0"), null);
21+
SUB_OBJECTS_AUTO_ENABLED("es.sub_objects_auto_feature_flag_enabled=true", Version.fromString("8.16.0"), null),
22+
INFERENCE_UNIFIED_API_ENABLED("es.inference_unified_feature_flag_enabled=true", Version.fromString("8.18.0"), null);
2223

2324
public final String systemProperty;
2425
public final Version from;

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceBaseRestTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.core.Nullable;
2020
import org.elasticsearch.inference.TaskType;
2121
import org.elasticsearch.test.cluster.ElasticsearchCluster;
22+
import org.elasticsearch.test.cluster.FeatureFlag;
2223
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
2324
import org.elasticsearch.test.rest.ESRestTestCase;
2425
import org.elasticsearch.xcontent.XContentBuilder;
@@ -46,6 +47,7 @@ public class InferenceBaseRestTest extends ESRestTestCase {
4647
.setting("xpack.security.enabled", "true")
4748
.plugin("inference-service-test")
4849
.user("x_pack_rest_user", "x-pack-test-password")
50+
.feature(FeatureFlag.INFERENCE_UNIFIED_API_ENABLED)
4951
.build();
5052

5153
@Override

x-pack/plugin/inference/qa/inference-service-tests/src/javaRestTest/java/org/elasticsearch/xpack/inference/InferenceCrudIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public void testSupportedStream() throws Exception {
466466
assertEquals(modelId, singleModel.get("inference_id"));
467467
assertEquals(TaskType.COMPLETION.toString(), singleModel.get("task_type"));
468468

469-
var input = IntStream.range(1, 2 + randomInt(8)).mapToObj(i -> randomUUID()).toList();
469+
var input = IntStream.range(1, 2 + randomInt(8)).mapToObj(i -> randomAlphanumericOfLength(5)).toList();
470470
try {
471471
var events = streamInferOnMockService(modelId, TaskType.COMPLETION, input);
472472

@@ -493,7 +493,7 @@ public void testUnifiedCompletionInference() throws Exception {
493493
assertEquals(modelId, singleModel.get("inference_id"));
494494
assertEquals(TaskType.COMPLETION.toString(), singleModel.get("task_type"));
495495

496-
var input = IntStream.range(1, 2 + randomInt(8)).mapToObj(i -> randomUUID()).toList();
496+
var input = IntStream.range(1, 2 + randomInt(8)).mapToObj(i -> randomAlphanumericOfLength(5)).toList();
497497
try {
498498
var events = unifiedCompletionInferOnMockService(modelId, TaskType.COMPLETION, input);
499499
var expectedResponses = expectedResultsIterator(input);

0 commit comments

Comments
 (0)