Skip to content

Commit

Permalink
Fix the unstable integration test of Lucene search engine (#6187)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/kind failing-test
/area core
/milestone 2.17.x

#### What this PR does / why we need it:

This PR allows retrying to operate on posts when optimistic locking errors occur.

#### Which issue(s) this PR fixes:

Fixes #6186 

#### Does this PR introduce a user-facing change?

```release-note
None
```
  • Loading branch information
JohnNiang committed Jun 28, 2024
1 parent 68d94f6 commit c524ee4
Showing 1 changed file with 15 additions and 0 deletions.
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);
}

}

0 comments on commit c524ee4

Please sign in to comment.