Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the unstable integration test of Lucene search engine #6187

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.retry.support.RetryTemplateBuilder;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.test.StepVerifier;
import reactor.util.retry.Retry;
import run.halo.app.content.Content;
import run.halo.app.content.ContentUpdateParam;
import run.halo.app.content.PostRequest;
Expand Down Expand Up @@ -135,6 +137,7 @@ void assertNoResult(int maxAttempts) {
void deletePostPermanently(String postName) {
client.get(Post.class, postName)
.flatMap(client::delete)
.retryWhen(optimisticLockRetry())
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();
Expand All @@ -144,6 +147,7 @@ void recoverPost(String postName) {
client.get(Post.class, postName)
.doOnNext(post -> post.getSpec().setDeleted(false))
.flatMap(client::update)
.retryWhen(optimisticLockRetry())
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();
Expand All @@ -153,6 +157,7 @@ void recyclePost(String postName) {
client.get(Post.class, postName)
.doOnNext(post -> post.getSpec().setDeleted(true))
.flatMap(client::update)
.retryWhen(optimisticLockRetry())
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();
Expand All @@ -162,6 +167,7 @@ void publicPost(String postName) {
client.get(Post.class, postName)
.doOnNext(post -> post.getSpec().setVisible(PUBLIC))
.flatMap(client::update)
.retryWhen(optimisticLockRetry())
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();
Expand All @@ -171,6 +177,7 @@ void privatePost(String postName) {
client.get(Post.class, postName)
.doOnNext(post -> post.getSpec().setVisible(PRIVATE))
.flatMap(client::update)
.retryWhen(optimisticLockRetry())
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();
Expand All @@ -179,6 +186,7 @@ void privatePost(String postName) {
void publishPost(String postName) {
client.get(Post.class, postName)
.flatMap(postService::publish)
.retryWhen(optimisticLockRetry())
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();
Expand All @@ -187,6 +195,7 @@ void publishPost(String postName) {
void unpublishPost(String postName) {
client.get(Post.class, postName)
.flatMap(postService::unpublish)
.retryWhen(optimisticLockRetry())
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();
Expand Down Expand Up @@ -220,4 +229,10 @@ void createPost(String postName) {
.expectNextCount(1)
.verifyComplete();
}

Retry optimisticLockRetry() {
return Retry.backoff(5, Duration.ofMillis(100))
.filter(OptimisticLockingFailureException.class::isInstance);
}

}