Skip to content

Commit

Permalink
Fixed #12636 Flaky ContextScopeListener test (#12638)
Browse files Browse the repository at this point in the history
Fixed #12636 by backporting fix from #12603
  • Loading branch information
gregw authored Dec 14, 2024
1 parent 4041e24 commit cd4a09b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,11 @@ public boolean addEventListener(EventListener listener)
{
if (super.addEventListener(listener))
{
if (listener instanceof ContextScopeListener)
if (listener instanceof ContextScopeListener contextScopeListener)
{
_contextListeners.add((ContextScopeListener)listener);
_contextListeners.add(contextScopeListener);
if (__context.get() != null)
((ContextScopeListener)listener).enterScope(__context.get(), null);
contextScopeListener.enterScope(__context.get(), null);
}
return true;
}
Expand All @@ -605,9 +605,12 @@ public boolean removeEventListener(EventListener listener)
{
if (super.removeEventListener(listener))
{
if (listener instanceof ContextScopeListener)
_contextListeners.remove(listener);

if (listener instanceof ContextScopeListener contextScopeListener)
{
_contextListeners.remove(contextScopeListener);
if (__context.get() != null)
contextScopeListener.exitScope(__context.get(), null);
}
return true;
}
return false;
Expand Down Expand Up @@ -1053,6 +1056,7 @@ public boolean handle(Request request, Response response, Callback callback) thr
return true;

// Past this point we are calling the downstream handler in scope.
Context lastContext = getCurrentContext();
ClassLoader lastLoader = enterScope(contextRequest);
ContextResponse contextResponse = wrapResponse(contextRequest, response);
try
Expand All @@ -1068,7 +1072,7 @@ public boolean handle(Request request, Response response, Callback callback) thr
{
// We exit scope here, even though handle() is asynchronous,
// as we have wrapped all our callbacks to re-enter the scope.
exitScope(contextRequest, request.getContext(), lastLoader);
exitScope(contextRequest, lastContext, lastLoader);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void exitScope(Context context, Request request)
ContentResponse response = _client.GET(uri);
assertThat(response.getStatus(), equalTo(HttpStatus.OK_200));

Awaitility.waitAtMost(5, TimeUnit.SECONDS).pollInterval(100, TimeUnit.MILLISECONDS).until(() -> _history.size() == 9);
Awaitility.waitAtMost(5, TimeUnit.SECONDS).pollInterval(100, TimeUnit.MILLISECONDS).until(() -> _history.size() >= 9);
assertHistory(
"enterScope /initialPath",
"doGet",
Expand Down

0 comments on commit cd4a09b

Please sign in to comment.