mirror of https://github.com/halo-dev/halo
Fix the unstable integration test of Lucene search engine (#6187)
#### 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 ```pull/6190/head
parent
68d94f6653
commit
c524ee4340
|
@ -13,11 +13,13 @@ import org.opentest4j.AssertionFailedError;
|
|||
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;
|
||||
|
@ -135,6 +137,7 @@ public class LuceneSearchEngineIntegrationTest {
|
|||
void deletePostPermanently(String postName) {
|
||||
client.get(Post.class, postName)
|
||||
.flatMap(client::delete)
|
||||
.retryWhen(optimisticLockRetry())
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(1)
|
||||
.verifyComplete();
|
||||
|
@ -144,6 +147,7 @@ public class LuceneSearchEngineIntegrationTest {
|
|||
client.get(Post.class, postName)
|
||||
.doOnNext(post -> post.getSpec().setDeleted(false))
|
||||
.flatMap(client::update)
|
||||
.retryWhen(optimisticLockRetry())
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(1)
|
||||
.verifyComplete();
|
||||
|
@ -153,6 +157,7 @@ public class LuceneSearchEngineIntegrationTest {
|
|||
client.get(Post.class, postName)
|
||||
.doOnNext(post -> post.getSpec().setDeleted(true))
|
||||
.flatMap(client::update)
|
||||
.retryWhen(optimisticLockRetry())
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(1)
|
||||
.verifyComplete();
|
||||
|
@ -162,6 +167,7 @@ public class LuceneSearchEngineIntegrationTest {
|
|||
client.get(Post.class, postName)
|
||||
.doOnNext(post -> post.getSpec().setVisible(PUBLIC))
|
||||
.flatMap(client::update)
|
||||
.retryWhen(optimisticLockRetry())
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(1)
|
||||
.verifyComplete();
|
||||
|
@ -171,6 +177,7 @@ public class LuceneSearchEngineIntegrationTest {
|
|||
client.get(Post.class, postName)
|
||||
.doOnNext(post -> post.getSpec().setVisible(PRIVATE))
|
||||
.flatMap(client::update)
|
||||
.retryWhen(optimisticLockRetry())
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(1)
|
||||
.verifyComplete();
|
||||
|
@ -179,6 +186,7 @@ public class LuceneSearchEngineIntegrationTest {
|
|||
void publishPost(String postName) {
|
||||
client.get(Post.class, postName)
|
||||
.flatMap(postService::publish)
|
||||
.retryWhen(optimisticLockRetry())
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(1)
|
||||
.verifyComplete();
|
||||
|
@ -187,6 +195,7 @@ public class LuceneSearchEngineIntegrationTest {
|
|||
void unpublishPost(String postName) {
|
||||
client.get(Post.class, postName)
|
||||
.flatMap(postService::unpublish)
|
||||
.retryWhen(optimisticLockRetry())
|
||||
.as(StepVerifier::create)
|
||||
.expectNextCount(1)
|
||||
.verifyComplete();
|
||||
|
@ -220,4 +229,10 @@ public class LuceneSearchEngineIntegrationTest {
|
|||
.expectNextCount(1)
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
Retry optimisticLockRetry() {
|
||||
return Retry.backoff(5, Duration.ofMillis(100))
|
||||
.filter(OptimisticLockingFailureException.class::isInstance);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue