From 156f4f15f7c02abd4b88bc90d263e1bf1b157321 Mon Sep 17 00:00:00 2001 From: Maxim Fateev Date: Tue, 1 Oct 2024 09:57:02 -0700 Subject: [PATCH] SDKTestWorkflowRule wasn't calling shutdown (#2243) * Fixed SDKTestWorkflowRule to call shutdown * Fixed test broken after rule fix --- .../test/java/io/temporal/workflow/SagaTest.java | 1 + .../activityTests/ParallelLocalActivitiesTest.java | 1 - .../workflow/activityTests/TestLocalActivity.java | 4 ---- .../searchattributes/UpsertSearchAttributeTest.java | 8 ++++++-- .../UpsertTypedSearchAttributeTest.java | 13 ++++++++++--- .../testing/internal/SDKTestWorkflowRule.java | 9 ++++++++- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java index 78a29a6df..c049337d2 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/SagaTest.java @@ -57,6 +57,7 @@ public void testSaga() { "activity customActivity1", "executeChildWorkflow TestNoArgsWorkflowFunc", "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, + "registerUpdateHandlers update", "newThread workflow-method", "executeActivity ThrowIO", "activity ThrowIO", diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java index 2b27d42f5..17957dbf5 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/ParallelLocalActivitiesTest.java @@ -69,7 +69,6 @@ public void testParallelLocalActivities() { expected.add("newThread workflow-method"); for (int i = 0; i < TestParallelLocalActivitiesWorkflowImpl.COUNT; i++) { expected.add("executeLocalActivity SleepActivity"); - expected.add("currentTimeMillis"); } for (int i = 0; i < TestParallelLocalActivitiesWorkflowImpl.COUNT; i++) { expected.add("local activity SleepActivity"); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TestLocalActivity.java b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TestLocalActivity.java index 841944c0a..f69880fad 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TestLocalActivity.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/activityTests/TestLocalActivity.java @@ -71,12 +71,10 @@ public void testLocalActivity() { "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, "newThread workflow-method", "executeLocalActivity ThrowIO", - "currentTimeMillis", "local activity ThrowIO", "local activity ThrowIO", "local activity ThrowIO", "executeLocalActivity Activity2", - "currentTimeMillis", "local activity Activity2", "executeActivity Activity2", "activity Activity2"); @@ -115,12 +113,10 @@ public void testLocalActivityNoInput() { "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, "newThread workflow-method", "executeLocalActivity ThrowIO", - "currentTimeMillis", "local activity ThrowIO", "local activity ThrowIO", "local activity ThrowIO", "executeLocalActivity Activity2", - "currentTimeMillis", "local activity Activity2", "executeActivity Activity2", "activity Activity2"); diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/searchattributes/UpsertSearchAttributeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/searchattributes/UpsertSearchAttributeTest.java index 286552f70..f00a5a0b5 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/searchattributes/UpsertSearchAttributeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/searchattributes/UpsertSearchAttributeTest.java @@ -69,8 +69,12 @@ public void testUpsertSearchAttributes() { "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, "newThread workflow-method", "upsertSearchAttributes", - "executeActivity Activity", - "activity Activity"); + "sleep PT0.1S", + "upsertSearchAttributes", + "sleep PT0.1S", + "upsertSearchAttributes", + "upsertSearchAttributes", + "sleep PT0.1S"); testWorkflowRule.assertHistoryEvent( execution.getWorkflowId(), EventType.EVENT_TYPE_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES); } diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/searchattributes/UpsertTypedSearchAttributeTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/searchattributes/UpsertTypedSearchAttributeTest.java index 779037e4b..d41422ee7 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/searchattributes/UpsertTypedSearchAttributeTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/searchattributes/UpsertTypedSearchAttributeTest.java @@ -72,9 +72,16 @@ public void testUpsertSearchAttributes() { .setExpected( "interceptExecuteWorkflow " + SDKTestWorkflowRule.UUID_REGEXP, "newThread workflow-method", - "upsertSearchAttributes", - "executeActivity Activity", - "activity Activity"); + "upsertTypedSearchAttributes", + "sleep PT0.1S", + "upsertTypedSearchAttributes", + "sleep PT0.1S", + "upsertTypedSearchAttributes", + "upsertTypedSearchAttributes", + "sleep PT0.1S", + "upsertTypedSearchAttributes", + "upsertTypedSearchAttributes", + "upsertTypedSearchAttributes"); testWorkflowRule.assertHistoryEvent( execution.getWorkflowId(), EventType.EVENT_TYPE_UPSERT_WORKFLOW_SEARCH_ATTRIBUTES); } diff --git a/temporal-testing/src/main/java/io/temporal/testing/internal/SDKTestWorkflowRule.java b/temporal-testing/src/main/java/io/temporal/testing/internal/SDKTestWorkflowRule.java index 97907f02b..7d1c18b55 100644 --- a/temporal-testing/src/main/java/io/temporal/testing/internal/SDKTestWorkflowRule.java +++ b/temporal-testing/src/main/java/io/temporal/testing/internal/SDKTestWorkflowRule.java @@ -232,7 +232,14 @@ public SDKTestWorkflowRule build() { } public Statement apply(@Nonnull Statement base, Description description) { - Statement testWorkflowStatement = base; + Statement testWorkflowStatement = + new Statement() { + @Override + public void evaluate() throws Throwable { + base.evaluate(); + shutdown(); + } + }; Test annotation = description.getAnnotation(Test.class); boolean timeoutIsOverriddenOnTestAnnotation = annotation != null && annotation.timeout() > 0;