Skip to content

Commit

Permalink
fix flaky tests under DubboAppenderTest (apache#14900)
Browse files Browse the repository at this point in the history
* fix flaky test under DubboAppenderTest

* fix format issue

* format code issue

---------

Co-authored-by: li261 <[email protected]>
  • Loading branch information
ljmcr and li261 authored Nov 20, 2024
1 parent 27c51c3 commit 36b69f1
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -42,6 +40,9 @@ public void setUp() throws Exception {
when(event.getLevel()).thenReturn(Level.INFO);
when(event.getThreadName()).thenReturn("thread-name");
when(event.getMessage()).thenReturn(new SimpleMessage("message"));

DubboAppender.clear();
DubboAppender.doStop();
}

@AfterEach
Expand All @@ -52,7 +53,7 @@ public void tearDown() throws Exception {

@Test
void testAvailable() {
assumeFalse(DubboAppender.available);
assertThat(DubboAppender.available, is(false));
DubboAppender.doStart();
assertThat(DubboAppender.available, is(true));
DubboAppender.doStop();
Expand All @@ -62,8 +63,9 @@ void testAvailable() {
@Test
void testAppend() {
DubboAppender appender = new DubboAppender();
assertThat(DubboAppender.logList, hasSize(0));
appender.append(event);
assumeTrue(DubboAppender.logList.isEmpty());
assertThat(DubboAppender.logList, hasSize(0));
DubboAppender.doStart();
appender.append(event);
assertThat(DubboAppender.logList, hasSize(1));
Expand All @@ -75,7 +77,7 @@ void testClear() {
DubboAppender.doStart();
DubboAppender appender = new DubboAppender();
appender.append(event);
assumeTrue(1 == DubboAppender.logList.size());
assertThat(DubboAppender.logList, hasSize(1));
DubboAppender.clear();
assertThat(DubboAppender.logList, hasSize(0));
}
Expand Down

0 comments on commit 36b69f1

Please sign in to comment.