-
Notifications
You must be signed in to change notification settings - Fork 158
Fix NDE caused by removing Workflow.getVersion with a succeeding Work… #2370
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Quinn-With-Two-Ns
merged 2 commits into
temporalio:master
from
Quinn-With-Two-Ns:issue-2367
Jan 16, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...dk/src/test/java/io/temporal/workflow/versionTests/GetVersionRemovalBeforeMarkerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. | ||
* | ||
* Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Modifications copyright (C) 2017 Uber Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this material except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.temporal.workflow.versionTests; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import io.temporal.activity.LocalActivityOptions; | ||
import io.temporal.testing.internal.SDKTestWorkflowRule; | ||
import io.temporal.worker.WorkerOptions; | ||
import io.temporal.workflow.Workflow; | ||
import io.temporal.workflow.shared.TestActivities; | ||
import io.temporal.workflow.shared.TestActivities.TestActivitiesImpl; | ||
import io.temporal.workflow.shared.TestWorkflows.TestWorkflow1; | ||
import io.temporal.workflow.unsafe.WorkflowUnsafe; | ||
import java.time.Duration; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class GetVersionRemovalBeforeMarkerTest { | ||
private static boolean hasReplayed; | ||
|
||
@Rule | ||
public SDKTestWorkflowRule testWorkflowRule = | ||
SDKTestWorkflowRule.newBuilder() | ||
.setWorkflowTypes(TestGetVersionRemovalWorkflowImpl.class) | ||
.setActivityImplementations(new TestActivitiesImpl()) | ||
// Forcing a replay. Full history arrived from a normal queue causing a replay. | ||
.setWorkerOptions( | ||
WorkerOptions.newBuilder() | ||
.setStickyQueueScheduleToStartTimeout(Duration.ZERO) | ||
.build()) | ||
.build(); | ||
|
||
@Test | ||
public void testSideEffectAfterGetVersion() { | ||
TestWorkflow1 workflowStub = | ||
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflow1.class); | ||
String result = workflowStub.execute("SideEffect"); | ||
assertTrue(hasReplayed); | ||
assertEquals("side effect", result); | ||
} | ||
|
||
@Test | ||
public void testMutableSideEffectAfterGetVersion() { | ||
TestWorkflow1 workflowStub = | ||
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflow1.class); | ||
String result = workflowStub.execute("MutableSideEffect"); | ||
assertTrue(hasReplayed); | ||
assertEquals("mutable side effect", result); | ||
} | ||
|
||
@Test | ||
public void testGetVersionAfterGetVersion() { | ||
TestWorkflow1 workflowStub = | ||
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflow1.class); | ||
String result = workflowStub.execute("GetVersion"); | ||
assertTrue(hasReplayed); | ||
assertEquals("6", result); | ||
} | ||
|
||
@Test | ||
public void testLocalActivityAfterGetVersion() { | ||
TestWorkflow1 workflowStub = | ||
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflow1.class); | ||
String result = workflowStub.execute("LocalActivity"); | ||
assertTrue(hasReplayed); | ||
assertEquals("activity", result); | ||
} | ||
|
||
public static class TestGetVersionRemovalWorkflowImpl implements TestWorkflow1 { | ||
private final TestActivities.VariousTestActivities activities = | ||
Workflow.newLocalActivityStub( | ||
TestActivities.VariousTestActivities.class, | ||
LocalActivityOptions.newBuilder() | ||
.setStartToCloseTimeout(Duration.ofSeconds(5)) | ||
.build()); | ||
|
||
@Override | ||
public String execute(String action) { | ||
// Test removing a version check in replaying code with an additional thread running. | ||
if (!WorkflowUnsafe.isReplaying()) { | ||
int version = Workflow.getVersion("changeId", 1, 2); | ||
assertEquals(version, 2); | ||
} else { | ||
hasReplayed = true; | ||
} | ||
String result = ""; | ||
if (action.equals("SideEffect")) { | ||
result = Workflow.sideEffect(String.class, () -> "side effect"); | ||
} else if (action.equals("MutableSideEffect")) { | ||
result = | ||
Workflow.mutableSideEffect( | ||
"mutable-side-effect-i", | ||
String.class, | ||
(a, b) -> !a.equals(b), | ||
() -> "mutable side effect"); | ||
} else if (action.equals("GetVersion")) { | ||
int v = Workflow.getVersion("otherChangeId", 5, 6); | ||
result = String.valueOf(v); | ||
} else if (action.equals("LocalActivity")) { | ||
result = activities.activity(); | ||
} | ||
// Sleep to trigger at lest one more workflow task | ||
Workflow.sleep(Duration.ofSeconds(1)); | ||
return result; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand what's happening here. So is
!VersionMarkerUtils.hasVersionMarkerStructure(command.getCommand())
basically sayingisFakeVersionMarker
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this code deserves a comment. I will add it.
!VersionMarkerUtils.hasVersionMarkerStructure(command.getCommand())
is basically checking if the command is from aWorkflow.getVersion
call. What I am checking here is, if the history event is a version marker, but the command isn't that means this event can't match with the command so it must be a removed version marker