project-reactor - 在并行测试环境中使用 StepVerifier
问题描述
在并行测试环境中使用 StepVerifierwithVirtualTime
和方法时遇到了一些麻烦。create
private static final Duration DELAY = Duration.ofSeconds(1);
public void testA() {
StepVerifier.withVirtualTime(() -> Mono.just(1).delayElement(DELAY))
.thenAwait(DELAY)
.expectNext(1)
.expectComplete()
.verify();
}
public void testB() {
StepVerifier.create(Mono.just(1).delayElement(DELAY))
.thenAwait(DELAY)
.expectNext(1)
.expectComplete()
.verify();
}
Maven Surefire 插件配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<groups>unit</groups>
<includes>
<include>**/*Test.java</include>
</includes>
<parallel>methods</parallel>
<threadCount>2</threadCount>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
这些测试失败,但有以下异常(GitHub 上提供的完整堆栈跟踪,请参阅下面的链接。):
[ERROR] testA(com.github.hisener.StepVerifierTest) Time elapsed: 0.04 s <<< FAILURE!
java.lang.NullPointerException: timedScheduler
at java.base/java.util.Objects.requireNonNull(Objects.java:246)
[ERROR] testB(com.github.hisener.StepVerifierTest) Time elapsed: 0.043 s <<< FAILURE!
reactor.core.Exceptions$ReactorRejectedExecutionException: Scheduler unavailable
at reactor.core.Exceptions.failWithRejected(Exceptions.java:249)
例如,我认为它与delayElements
以下测试之一无关,timeout
它们也失败了:
public void testA() {
StepVerifier.withVirtualTime(() -> Mono.just(1)).expectNext(1).expectComplete().verify();
}
public void testB() {
StepVerifier.create(Mono.just(1).timeout(DELAY)).expectNext(1).expectComplete().verify();
}
我已经在 TestNG 和 Junit 5 上进行了测试,但没有运气。代码可在 GitHub 上获得:
解决方案
StepVerifier#withVirtualTime
用虚拟时间替换所有默认调度程序,因此并行使用它不是一个好主意
推荐阅读
- java - java.lang.NoSuchMethodError:android中没有虚拟方法getTextBounds错误
- api - VIPTELA SDWAN API 调用问题
- javascript - 有什么方法可以从 ejs 调用 axios 吗?
- c - 使用函数和指针将分数减少到最低项
- javascript - 如何以编程方式发送复选框单击?
- node.js - AWS sdk 使用 sso 获取凭证
- php - Laravel 分页只显示第一页的内容
- javascript - 如何将数组拆分为多个数组?
- python - 我可以得到flask_ngrok或py-ngrok生成的ip地址或域名并返回到127.0.0.1/
- laravel - Laravel 黄昏与 browserstack 在多个设备和浏览器上运行测试