@@ -104,6 +104,20 @@ public void testThreadContextPropagation() {
104104 assertEquals ("asynctesting123" , result );
105105 }
106106
107+ @ Test
108+ public void testPromiseCallbackContextPropagation () {
109+ Worker worker = testEnvironment .newWorker (TASK_QUEUE );
110+ worker .registerWorkflowImplementationTypes (ContextPropagationCallbackWorkflowImpl .class );
111+ testEnvironment .start ();
112+ MDC .put ("test" , "testing123" );
113+ WorkflowClient client = testEnvironment .getWorkflowClient ();
114+ WorkflowOptions options = WorkflowOptions .newBuilder ().setTaskQueue (TASK_QUEUE ).build ();
115+ TestWorkflows .TestWorkflow1 workflow =
116+ client .newWorkflowStub (TestWorkflows .TestWorkflow1 .class , options );
117+ String result = workflow .execute ("input1" );
118+ assertEquals ("asynccallback123" , result );
119+ }
120+
107121 @ Test
108122 public void testActivityContextPropagation () {
109123 Worker worker = testEnvironment .newWorker (TASK_QUEUE );
@@ -339,6 +353,25 @@ private String async() {
339353 }
340354 }
341355
356+ public static class ContextPropagationCallbackWorkflowImpl
357+ implements TestWorkflows .TestWorkflow1 {
358+
359+ @ Override
360+ public String execute (String input ) {
361+ Promise <String > asyncPromise = Async .function (this ::async );
362+ // The callback must see the context of the thread that registered it, not the context the
363+ // thread completing the promise happens to carry.
364+ MDC .put ("test" , "callback123" );
365+ Promise <String > callback = asyncPromise .thenApply (result -> result + MDC .get ("test" ));
366+ MDC .put ("test" , "testing123" );
367+ return callback .get ();
368+ }
369+
370+ private String async () {
371+ return "async" ;
372+ }
373+ }
374+
342375 public static class ContextActivityImpl implements TestActivities .TestActivity1 {
343376 @ Override
344377 public String execute (String input ) {
0 commit comments