Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Sushisource
Copy link
Member

What was changed

Write name and version to task completions

Why?

Parity

Checklist

  1. Closes Update sdk-name and sdk-version in task-level metadata if changed #1838

  2. How was this tested:
    Added unit tests

  3. Any docs updates needed?

@Sushisource Sushisource requested a review from a team as a code owner February 20, 2025 20:08
Comment on lines 241 to 242
@Test
public void setsSdkNameAndVersionIfDifferentFromHistory() throws Throwable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test and the next I can't get to work because the setup in this suite isn't meant to work with more than one completion. I tried adjusting the mocks but it just led down dead end of the mock really not being suitable.

@Quinn-With-Two-Ns I can't find any tests that will allow me to really do what I want, which is just pass in some history and get a WFT response out that I can inspect, at this level. There are a bunch that operate at the workflow state machines level, but that's one level too deep. Any pointers would be welcome

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests in io/temporal/internal/statemachines take in a history and you can inspect the result. All the tests there are focused on a particular state machine, but no reason you can't add tests that focus on the workflow task state machine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is this logic isn't in the workflow task state machine, it's in ReplayWorkflowRunTaskHandler, but, whatever. For the sake of making this easier to test with the existing stuff I'll just push it down and require one extra getter and just make sure it's set for completions with an integ test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is all fixed. The one remaining test at that level ensures the name/ver returned by state machines is actually attached to the response

if (!Strings.isNullOrEmpty(result.getWriteSdkVersion())) {
metadata.setSdkVersion(result.getWriteSdkVersion());
}
completedRequest.setSdkMetadata(metadata.build());
Copy link
Member

@cretz cretz Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this set an empty workflow task completed metadata even if there are no SDK flags and no SDK name/version to set? I'm worried it's put on task complete as is which means every event in history JSON dump will have {} even if empty (there is difference between empty and null). I think this whole chunk of code should be surrounded by if (!result.getSdkFlags().isEmpty() || !Strings.isNullOrEmpty(result.getWriteSdkName()) || !Strings.isNullOrEmpty(result.getWriteSdkVersion())) {.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it will do that, I'll change.

}
flags.setSdkFlag(sdkFlag);
}
if (!Strings.isNullOrEmpty(completedEvent.getSdkMetadata().getSdkName())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pardon my lack of Java proto knowledge, can you confirm (like some other lang proto impls) that a getter for a message returns an empty form of the message even if the underlying value is null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does

@Sushisource Sushisource force-pushed the sdk-version-stamps branch 2 times, most recently from f643065 to b2ddb5b Compare February 20, 2025 22:36
Comment on lines 257 to 258
.setSdkName(writeSdkName)
.setSdkVersion(writeSdkVersion)
Copy link
Member

@cretz cretz Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure proto builder setters for strings are null safe (a quick peek at some generated code shows that this may throw a NPE, should probably only call these setters if string is non-null and non-empty)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

God they aren't. That's absolutely silly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 May be showing a test coverage hole too. Alongside Quinn's suggestion of integration test, can we make sure there is some kind of test that would have failed if this code had not changed?

Copy link
Member Author

@Sushisource Sushisource Feb 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the integ test but it'd require some very different test setup than what's available now to verify this particular scenario it seems. I don't have a good way to manually alter history (which I'd need to do) but still test this layer of the code. I think the other tests offer solid coverage

@Quinn-With-Two-Ns
Copy link
Contributor

Can we add an integration test as well that tests this end to end , ideally the test workflow should contain multiple workflow tasks and evict the workflow from cache during the test

@Sushisource Sushisource merged commit 963ea9f into temporalio:master Feb 21, 2025
8 checks passed
@Sushisource Sushisource deleted the sdk-version-stamps branch February 21, 2025 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update sdk-name and sdk-version in task-level metadata if changed
3 participants