Skip to content

Commit

Permalink
Merge branch '6.0.x'
Browse files Browse the repository at this point in the history
Closes gh-13150
  • Loading branch information
jzheaux committed May 10, 2023
2 parents eea3b77 + e033e34 commit a4e13c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ private void start() {

private void error(Throwable error) {
if (this.state.get() == 1) {
this.scope.close();
this.scope.getCurrentObservation().error(error);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import org.springframework.mock.web.MockHttpServletResponse;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -109,6 +111,23 @@ void decorateFiltersWhenDefaultsThenUsesEventName() throws Exception {
assertThat(events.get(1).getName()).isEqualTo("authentication.basic.after");
}

// gh-12787
@Test
void decorateFiltersWhenErrorsThenClosesObservationOnlyOnce() throws Exception {
ObservationHandler<?> handler = mock(ObservationHandler.class);
given(handler.supportsContext(any())).willReturn(true);
ObservationRegistry registry = ObservationRegistry.create();
registry.observationConfig().observationHandler(handler);
ObservationFilterChainDecorator decorator = new ObservationFilterChainDecorator(registry);
FilterChain chain = mock(FilterChain.class);
Filter filter = mock(Filter.class);
willThrow(IllegalArgumentException.class).given(filter).doFilter(any(), any(), any());
FilterChain decorated = decorator.decorate(chain, List.of(filter));
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
() -> decorated.doFilter(new MockHttpServletRequest("GET", "/"), new MockHttpServletResponse()));
verify(handler).onScopeClosed(any());
}

private static class BasicAuthenticationFilter implements Filter {

@Override
Expand Down

0 comments on commit a4e13c5

Please sign in to comment.