Skip to content

Commit 1818d3b

Browse files
Speeding up test
1 parent 6079500 commit 1818d3b

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ private TraceContext getCurrentTraceInfo() {
127127
void waitForAuthRequestCompletion(TimeValue timeValue) throws IllegalStateException {
128128
try {
129129
if (requestCompleteLatch.await(timeValue.getMillis(), TimeUnit.MILLISECONDS) == false) {
130-
throw new IllegalStateException("The authorization request did not complete.");
130+
throw new IllegalStateException("The wait time has expired for authorization to complete.");
131131
}
132-
} catch (IllegalStateException | InterruptedException e) {
133-
logger.warn("Interrupted while waiting for the authorization request to complete", e);
132+
} catch (InterruptedException e) {
133+
throw new IllegalStateException("Waiting for authorization to complete was interrupted");
134134
}
135135
}
136136
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandlerTests.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,13 @@ public void testGetAuthorization_ReturnsAValidResponse() throws IOException {
194194
}
195195

196196
@SuppressWarnings("unchecked")
197-
public void testGetAuthorization_OnResponseCalledOnce() throws IllegalStateException {
197+
public void testGetAuthorization_OnResponseCalledOnce() throws IOException {
198198
var senderFactory = HttpRequestSenderTests.createSenderFactory(threadPool, clientManager);
199199
var eisGatewayUrl = getUrl(webServer);
200200
var logger = mock(Logger.class);
201201
var authHandler = new ElasticInferenceServiceAuthorizationHandler(eisGatewayUrl, threadPool, logger);
202202

203203
ActionListener<ElasticInferenceServiceAuthorization> listener = mock(ActionListener.class);
204-
205204
String responseJson = """
206205
{
207206
"models": [
@@ -214,17 +213,18 @@ public void testGetAuthorization_OnResponseCalledOnce() throws IllegalStateExcep
214213
""";
215214
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(responseJson));
216215

217-
authHandler.getAuthorization(listener, senderFactory.createSender());
218-
authHandler.waitForAuthRequestCompletion(TimeValue.timeValueSeconds(1));
219-
220-
verify(listener, times(1)).onResponse(any());
216+
try (var sender = senderFactory.createSender()) {
217+
authHandler.getAuthorization(listener, sender);
218+
authHandler.waitForAuthRequestCompletion(TIMEOUT);
221219

222-
var loggerArgsCaptor = ArgumentCaptor.forClass(String.class);
223-
verify(logger, times(1)).debug(loggerArgsCaptor.capture());
220+
verify(listener, times(1)).onResponse(any());
221+
var loggerArgsCaptor = ArgumentCaptor.forClass(String.class);
222+
verify(logger, times(1)).debug(loggerArgsCaptor.capture());
224223

225-
var message = loggerArgsCaptor.getValue();
226-
assertThat(message, is("Retrieving authorization information from the Elastic Inference Service."));
227-
verifyNoMoreInteractions(logger);
224+
var message = loggerArgsCaptor.getValue();
225+
assertThat(message, is("Retrieving authorization information from the Elastic Inference Service."));
226+
verifyNoMoreInteractions(logger);
227+
}
228228
}
229229

230230
public void testGetAuthorization_InvalidResponse() throws IOException {
@@ -262,5 +262,4 @@ public void testGetAuthorization_InvalidResponse() throws IOException {
262262
}
263263

264264
}
265-
266265
}

0 commit comments

Comments
 (0)