提问人:Robert Strauch 提问时间:11/16/2023 更新时间:11/16/2023 访问量:29
使用 WireMock @SpringBootTest在 GitLab CI 管道中失败,但在本地通过
@SpringBootTest with WireMock fails in GitLab CI pipeline but passes locally
问:
以下是使用 Testcontainers 启动 RabbitMQ 容器的简化版本。@SpringBootTest
要测试的基本工作流是:
- 向目标队列发送消息。
- 拒绝邮件,以便将其移动到相应的死信队列。
- 检查邮件是否存在于死信队列中。
- 检查是否向 RocketChat WireMock 发出了请求。
@RegisterExtension
protected static WireMockExtension rocketChatWireMock = WireMockExtension.newInstance()
.options(wireMockConfig().dynamicPort())
.build();
@DynamicPropertySource
static void configureRocketChatProperties(DynamicPropertyRegistry registry) {
registry.add("rocket-chat-url", () -> rocketChatWireMock.baseUrl());
}
@Test
void shouldSendAlertToRocketChat() throws JSONException {
final int retryCount = 3;
final String payload = buildPayload();
rocketChatWireMock.stubFor(post(anyUrl()).willReturn(ok()));
sendMessage("my-routing-key", payload, retryCount);
waitUntilMessageIsPresent("my-queue");
rejectMessage("my-queue");
waitUntilMessageIsPresent("parking-lot-queue");
final Message parkingLotMessage = rabbitTemplate.receive("parking-lot-queue");
assertThat(parkingLotMessage).isNotNull();
await().untilAsserted(() -> rocketChatWireMock.verify(postRequestedFor(anyUrl())));
}
在我的计算机上启动此测试时工作正常,但是在带有 GitLab 运行器的 GitLab CI 管道中运行时,它总是失败,并显示以下消息:
Caused by: com.github.tomakehurst.wiremock.client.VerificationException:
Expected at least one request matching: {
"method" : "POST"
}
答: 暂无答案
评论