Skip to content

Commit

Permalink
Fix flaky ReactiveWebServerLoadBalancerInteropTest (#5999)
Browse files Browse the repository at this point in the history
Motivation:

```
com.linecorp.armeria.spring.web.reactive.ReactiveWebServerLoadBalancerInteropTest.[1] sessionProtocol=H1C, path=/controller/api/ping
java.util.ConcurrentModificationException
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1714)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at com.linecorp.armeria.spring.web.reactive.ReactiveWebServerLoadBalancerInteropTest.assertNoErrorLogByHttpWebHandlerAdapter(ReactiveWebServerLoadBalancerInteropTest.java:148)
```

It seems that `logAppender.list` was modified while retrieving elements

Modifications:

- Use `CopyOnWriteArrayList` to collect `ILoggingEvent`

Result:

Fixes #5462
  • Loading branch information
ikhoon authored Nov 28, 2024
1 parent 6963c92 commit 2e58501
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.ServerResponse.ok;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -50,7 +52,7 @@

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import ch.qos.logback.core.AppenderBase;
import reactor.core.publisher.Mono;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
Expand Down Expand Up @@ -79,7 +81,7 @@ RouterFunction<ServerResponse> routerFunction() {
int port;

final Logger httpWebHandlerAdapterLogger = (Logger) LoggerFactory.getLogger(HttpWebHandlerAdapter.class);
final ListAppender<ILoggingEvent> logAppender = new ListAppender<>();
final ConcurrentListAppender<ILoggingEvent> logAppender = new ConcurrentListAppender<>();

@BeforeEach
public void attachAppender() {
Expand Down Expand Up @@ -148,4 +150,14 @@ private void assertNoErrorLogByHttpWebHandlerAdapter() {
.collect(Collectors.toList()))
.isEmpty();
}

private static final class ConcurrentListAppender<E> extends AppenderBase<E> {

List<E> list = new CopyOnWriteArrayList<>();

@Override
protected void append(E eventObject) {
list.add(eventObject);
}
}
}

0 comments on commit 2e58501

Please sign in to comment.