Skip to content

Commit

Permalink
[ML] Fixing streaming tests locale issue (elastic#118481)
Browse files Browse the repository at this point in the history
* Fixing the string locale

* Missing a toUpper
  • Loading branch information
jonathan-buttner authored Dec 11, 2024
1 parent 9837e78 commit 5572777
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,6 @@ tests:
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
method: test {p0=migrate/10_reindex/Test Reindex With Unsupported Mode}
issue: https://github.com/elastic/elasticsearch/issues/118273
- class: org.elasticsearch.xpack.inference.InferenceCrudIT
method: testUnifiedCompletionInference
issue: https://github.com/elastic/elasticsearch/issues/118405
- class: org.elasticsearch.xpack.security.operator.OperatorPrivilegesIT
method: testEveryActionIsEitherOperatorOnlyOrNonOperator
issue: https://github.com/elastic/elasticsearch/issues/118220
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,7 @@ public static String randomAlphaOfLength(int codeUnits) {

/**
* Generate a random string containing only alphanumeric characters.
* <b>The locale for the string is {@link Locale#ROOT}.</b>
* @param length the length of the string to generate
* @return the generated string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -471,7 +472,7 @@ public void testSupportedStream() throws Exception {
var events = streamInferOnMockService(modelId, TaskType.COMPLETION, input);

var expectedResponses = Stream.concat(
input.stream().map(String::toUpperCase).map(str -> "{\"completion\":[{\"delta\":\"" + str + "\"}]}"),
input.stream().map(s -> s.toUpperCase(Locale.ROOT)).map(str -> "{\"completion\":[{\"delta\":\"" + str + "\"}]}"),
Stream.of("[DONE]")
).iterator();
assertThat(events.size(), equalTo((input.size() + 1) * 2));
Expand Down Expand Up @@ -510,7 +511,9 @@ public void testUnifiedCompletionInference() throws Exception {
}

private static Iterator<String> expectedResultsIterator(List<String> input) {
return Stream.concat(input.stream().map(String::toUpperCase).map(InferenceCrudIT::expectedResult), Stream.of("[DONE]")).iterator();
// The Locale needs to be ROOT to match what the test service is going to respond with
return Stream.concat(input.stream().map(s -> s.toUpperCase(Locale.ROOT)).map(InferenceCrudIT::expectedResult), Stream.of("[DONE]"))
.iterator();
}

private static String expectedResult(String input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Flow;
Expand Down Expand Up @@ -142,7 +143,7 @@ public void unifiedCompletionInfer(
}

private StreamingChatCompletionResults makeResults(List<String> input) {
var responseIter = input.stream().map(String::toUpperCase).iterator();
var responseIter = input.stream().map(s -> s.toUpperCase(Locale.ROOT)).iterator();
return new StreamingChatCompletionResults(subscriber -> {
subscriber.onSubscribe(new Flow.Subscription() {
@Override
Expand Down Expand Up @@ -173,7 +174,7 @@ private ChunkedToXContent completionChunk(String delta) {
}

private StreamingUnifiedChatCompletionResults makeUnifiedResults(UnifiedCompletionRequest request) {
var responseIter = request.messages().stream().map(message -> message.content().toString().toUpperCase()).iterator();
var responseIter = request.messages().stream().map(message -> message.content().toString().toUpperCase(Locale.ROOT)).iterator();
return new StreamingUnifiedChatCompletionResults(subscriber -> {
subscriber.onSubscribe(new Flow.Subscription() {
@Override
Expand Down

0 comments on commit 5572777

Please sign in to comment.