Skip to content

Commit a4ce071

Browse files
Trying to get request checks to work
1 parent f4ede68 commit a4ce071

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/AuthorizationTaskExecutorIT.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,30 @@ static List<UnparsedModel> getEisEndpoints(ModelRegistry modelRegistry) {
198198
}
199199

200200
private void restartPollingTaskAndWaitForAuthResponse() throws Exception {
201-
restartPollingTaskAndWaitForAuthResponse(admin(), authorizationTaskExecutor);
201+
restartPollingTaskAndWaitForAuthResponse(admin(), authorizationTaskExecutor, webServer);
202202
}
203203

204-
static void restartPollingTaskAndWaitForAuthResponse(AdminClient adminClient, AuthorizationTaskExecutor authTaskExecutor)
205-
throws Exception {
204+
static void restartPollingTaskAndWaitForAuthResponse(
205+
AdminClient adminClient,
206+
AuthorizationTaskExecutor authTaskExecutor,
207+
MockWebServer mockWebServer
208+
) throws Exception {
206209
cancelAuthorizationTask(adminClient);
207210

208211
// wait for the new task to be recreated and an authorization response to be processed
209212
waitForAuthorizationToComplete(authTaskExecutor);
213+
214+
assertBusy(() -> {
215+
var requests = mockWebServer.requests();
216+
assertThat(requests.size(), is(1));
217+
});
210218
}
211219

212220
static void waitForAuthorizationToComplete(AuthorizationTaskExecutor authTaskExecutor) throws Exception {
213221
assertBusy(() -> {
214222
var newPoller = authTaskExecutor.getCurrentPollerTask();
215223
assertNotNull(newPoller);
216224
newPoller.waitForAuthorizationToComplete(TimeValue.THIRTY_SECONDS);
217-
218-
var requests = webServer.requests();
219-
assertThat(requests.size(), is(1));
220225
});
221226
}
222227

x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/CCMServiceIT.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import static org.elasticsearch.xpack.inference.external.http.Utils.getUrl;
3636
import static org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT.AUTHORIZED_RAINBOW_SPRINKLES_RESPONSE;
3737
import static org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT.AUTH_TASK_ACTION;
38+
import static org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT.EMPTY_AUTH_RESPONSE;
3839
import static org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT.assertChatCompletionEndpointExists;
3940
import static org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT.getEisEndpoints;
4041
import static org.elasticsearch.xpack.inference.integration.AuthorizationTaskExecutorIT.removeEisPreconfiguredEndpoints;
@@ -165,13 +166,17 @@ public void testCreatesEisChatCompletionEndpoint() throws Exception {
165166
waitForTask(AUTH_TASK_ACTION, admin());
166167
waitForAuthorizationToComplete(authorizationTaskExecutor);
167168

169+
assertHasRequestWithAuth();
170+
171+
assertChatCompletionEndpointExists(modelRegistry);
172+
}
173+
174+
private void assertHasRequestWithAuth() throws Exception {
168175
assertBusy(() -> {
169176
var requests = webServer.requests();
170177
assertThat(requests.size(), is(1));
171178
assertThat(requests.get(0).getHeader(HttpHeaders.AUTHORIZATION), is("Bearer secret"));
172179
});
173-
174-
assertChatCompletionEndpointExists(modelRegistry);
175180
}
176181

177182
private void forceClusterUpdate() {
@@ -184,6 +189,8 @@ public void testDisableCCM_RemovesAuthorizationTask() throws Exception {
184189
assertCCMDisabled();
185190
waitForNoTask(AUTH_TASK_ACTION, admin());
186191

192+
webServer.clearRequests();
193+
webServer.enqueue(new MockResponse().setResponseCode(200).setBody(EMPTY_AUTH_RESPONSE));
187194
var listener = new TestPlainActionFuture<Void>();
188195
ccmService.get().storeConfiguration(new CCMModel(new SecureString("secret".toCharArray())), listener);
189196
listener.actionGet(TimeValue.THIRTY_SECONDS);
@@ -194,6 +201,8 @@ public void testDisableCCM_RemovesAuthorizationTask() throws Exception {
194201
waitForTask(AUTH_TASK_ACTION, admin());
195202
waitForAuthorizationToComplete(authorizationTaskExecutor);
196203

204+
assertHasRequestWithAuth();
205+
197206
disableCCM();
198207
assertCCMDisabled();
199208
waitForNoTask(AUTH_TASK_ACTION, admin());

0 commit comments

Comments
 (0)