Follow-up fix client tests reliability
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
This commit is contained in:
parent
37120f2ae5
commit
e996a5de1e
4 changed files with 22 additions and 30 deletions
|
|
@ -446,18 +446,9 @@ public abstract class AbstractMcpAsyncClientTests {
|
||||||
resources -> Mono.fromRunnable(() -> resourcesNotificationReceived.set(true)))
|
resources -> Mono.fromRunnable(() -> resourcesNotificationReceived.set(true)))
|
||||||
.promptsChangeConsumer(prompts -> Mono.fromRunnable(() -> promptsNotificationReceived.set(true))),
|
.promptsChangeConsumer(prompts -> Mono.fromRunnable(() -> promptsNotificationReceived.set(true))),
|
||||||
mcpAsyncClient -> {
|
mcpAsyncClient -> {
|
||||||
|
StepVerifier.create(mcpAsyncClient.initialize())
|
||||||
var transport = createMcpTransport();
|
.expectNextMatches(Objects::nonNull)
|
||||||
var client = McpClient.async(transport)
|
.verifyComplete();
|
||||||
.requestTimeout(getRequestTimeout())
|
|
||||||
.toolsChangeConsumer(tools -> Mono.fromRunnable(() -> toolsNotificationReceived.set(true)))
|
|
||||||
.resourcesChangeConsumer(
|
|
||||||
resources -> Mono.fromRunnable(() -> resourcesNotificationReceived.set(true)))
|
|
||||||
.promptsChangeConsumer(
|
|
||||||
prompts -> Mono.fromRunnable(() -> promptsNotificationReceived.set(true)))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
StepVerifier.create(client.initialize()).expectNextMatches(Objects::nonNull).verifyComplete();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,15 +119,20 @@ public abstract class AbstractMcpSyncClientTests {
|
||||||
}, action);
|
}, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
<T> void verifyCallTimesOut(Function<McpSyncClient, T> operation, String action) {
|
<T> void verifyCallTimesOut(Function<McpSyncClient, T> blockingOperation, String action) {
|
||||||
withClient(createMcpTransport(), mcpSyncClient -> {
|
withClient(createMcpTransport(), mcpSyncClient -> {
|
||||||
// This scheduler is not replaced by virtual time scheduler
|
// This scheduler is not replaced by virtual time scheduler
|
||||||
Scheduler customScheduler = Schedulers.newBoundedElastic(1, 1, "actualBoundedElastic");
|
Scheduler customScheduler = Schedulers.newBoundedElastic(1, 1, "actualBoundedElastic");
|
||||||
|
|
||||||
StepVerifier.withVirtualTime(() -> Mono.fromSupplier(() -> operation.apply(mcpSyncClient))
|
StepVerifier.withVirtualTime(() -> Mono.fromSupplier(() -> blockingOperation.apply(mcpSyncClient))
|
||||||
// offload the blocking call to the real scheduler
|
// Offload the blocking call to the real scheduler
|
||||||
.subscribeOn(customScheduler))
|
.subscribeOn(customScheduler))
|
||||||
.expectSubscription()
|
.expectSubscription()
|
||||||
|
// This works without actually waiting but executes all the
|
||||||
|
// tasks pending execution on the VirtualTimeScheduler.
|
||||||
|
// It is possible to execute the blocking code from the operation
|
||||||
|
// because it is blocked on a dedicated Scheduler and the main
|
||||||
|
// flow is not blocked and uses the VirtualTimeScheduler.
|
||||||
.thenAwait(getInitializationTimeout())
|
.thenAwait(getInitializationTimeout())
|
||||||
.consumeErrorWith(e -> assertThat(e).isInstanceOf(McpError.class)
|
.consumeErrorWith(e -> assertThat(e).isInstanceOf(McpError.class)
|
||||||
.hasMessage("Client must be initialized before " + action))
|
.hasMessage("Client must be initialized before " + action))
|
||||||
|
|
|
||||||
|
|
@ -402,18 +402,9 @@ public abstract class AbstractMcpAsyncClientTests {
|
||||||
resources -> Mono.fromRunnable(() -> resourcesNotificationReceived.set(true)))
|
resources -> Mono.fromRunnable(() -> resourcesNotificationReceived.set(true)))
|
||||||
.promptsChangeConsumer(prompts -> Mono.fromRunnable(() -> promptsNotificationReceived.set(true))),
|
.promptsChangeConsumer(prompts -> Mono.fromRunnable(() -> promptsNotificationReceived.set(true))),
|
||||||
mcpAsyncClient -> {
|
mcpAsyncClient -> {
|
||||||
|
StepVerifier.create(mcpAsyncClient.initialize())
|
||||||
var transport = createMcpTransport();
|
.expectNextMatches(Objects::nonNull)
|
||||||
var client = McpClient.async(transport)
|
.verifyComplete();
|
||||||
.requestTimeout(getRequestTimeout())
|
|
||||||
.toolsChangeConsumer(tools -> Mono.fromRunnable(() -> toolsNotificationReceived.set(true)))
|
|
||||||
.resourcesChangeConsumer(
|
|
||||||
resources -> Mono.fromRunnable(() -> resourcesNotificationReceived.set(true)))
|
|
||||||
.promptsChangeConsumer(
|
|
||||||
prompts -> Mono.fromRunnable(() -> promptsNotificationReceived.set(true)))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
StepVerifier.create(client.initialize()).expectNextMatches(Objects::nonNull).verifyComplete();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,15 +120,20 @@ public abstract class AbstractMcpSyncClientTests {
|
||||||
}, action);
|
}, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
<T> void verifyCallTimesOut(Function<McpSyncClient, T> operation, String action) {
|
<T> void verifyCallTimesOut(Function<McpSyncClient, T> blockingOperation, String action) {
|
||||||
withClient(createMcpTransport(), mcpSyncClient -> {
|
withClient(createMcpTransport(), mcpSyncClient -> {
|
||||||
// This scheduler is not replaced by virtual time scheduler
|
// This scheduler is not replaced by virtual time scheduler
|
||||||
Scheduler customScheduler = Schedulers.newBoundedElastic(1, 1, "actualBoundedElastic");
|
Scheduler customScheduler = Schedulers.newBoundedElastic(1, 1, "actualBoundedElastic");
|
||||||
|
|
||||||
StepVerifier.withVirtualTime(() -> Mono.fromSupplier(() -> operation.apply(mcpSyncClient))
|
StepVerifier.withVirtualTime(() -> Mono.fromSupplier(() -> blockingOperation.apply(mcpSyncClient))
|
||||||
// offload the blocking call to the real scheduler
|
// Offload the blocking call to the real scheduler
|
||||||
.subscribeOn(customScheduler))
|
.subscribeOn(customScheduler))
|
||||||
.expectSubscription()
|
.expectSubscription()
|
||||||
|
// This works without actually waiting but executes all the
|
||||||
|
// tasks pending execution on the VirtualTimeScheduler.
|
||||||
|
// It is possible to execute the blocking code from the operation
|
||||||
|
// because it is blocked on a dedicated Scheduler and the main
|
||||||
|
// flow is not blocked and uses the VirtualTimeScheduler.
|
||||||
.thenAwait(getInitializationTimeout())
|
.thenAwait(getInitializationTimeout())
|
||||||
.consumeErrorWith(e -> assertThat(e).isInstanceOf(McpError.class)
|
.consumeErrorWith(e -> assertThat(e).isInstanceOf(McpError.class)
|
||||||
.hasMessage("Client must be initialized before " + action))
|
.hasMessage("Client must be initialized before " + action))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue