Skip to content

Test Framework #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 1, 2022
Merged

Test Framework #121

merged 6 commits into from
Sep 1, 2022

Conversation

cretz
Copy link
Member

@cretz cretz commented Aug 31, 2022

What was changed

Added test framework. There is a lot here, so see the code and README updates to understand what was added. Ignore the regenerated protos in temporalio/api and temporalio/bridge/proto.

Future changes:

  • Convert all existing tests to use it
  • Add a temporalio.testing.WorkflowEnvironment.start_embedded backed by Temporalite so we can run tests against both test server and real server

Checklist

  1. Closes Test framework #81

@cretz cretz requested a review from a team August 31, 2022 22:20
@cretz cretz force-pushed the testing branch 2 times, most recently from bdcf2ac to 2e3e2ef Compare September 1, 2022 13:18
affect calls activity code might make to functions on the `temporalio.activity` package.

* `info` property can be set to customize what is returned from `activity.info()`
* `on_heartbeat` property can be set to handle `activity.heartbeat()` calls
Copy link
Member

Choose a reason for hiding this comment

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

You might want to mention that when a worker runs an activity it throttles sending out heartbeats to the server so that users don't rely on this function in their tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can document, but can you clarify what you mean by:

users don't rely on this function in their tests

This is the one literally invoked for each heartbeat call unthrottled and I'd expect they can rely on that. Or are you saying so they don't improperly assume every heartbeat is heavy and that people call it quickly a lot so on_heartbeat should not be assumed to be 1:1 with server heartbeat?

Copy link
Member

Choose a reason for hiding this comment

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

the latter, thanks for clarifying.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will document when I send in PR for #120

@@ -1,4 +1,25 @@
"""
@generated by mypy-protobuf. Do not edit manually!
isort:skip_file
The MIT License

Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be 2020-2022?

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 is generated code that was added as the result of a mypy-protobuf update. Specifically nipunn1313/mypy-protobuf#385 now writes our license headers. So this is literally from the top of https://github.com/temporalio/api/blob/master/temporal/api/history/v1/message.proto.

Copy link
Member

Choose a reason for hiding this comment

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

We should update there.

"""

@staticmethod
def from_client(client: temporalio.client.Client) -> WorkflowEnvironment:
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

Copy link
Member Author

@cretz cretz Sep 1, 2022

Choose a reason for hiding this comment

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

Wait until you see a future PR where I will have start_embedded static function that's gonna download/run Temporalite like it does the test server. I wrestled with myself on whether that's valuable, but considering that I'm gonna do that for my own Python tests, I think it is.

(don't worry, I'm not putting "Temporalite" into the public API anywhere just in case it's folded into another binary later)

Copy link
Member

Choose a reason for hiding this comment

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

Yes please, but please put this in Core so we can have it for TS and newer SDKs.

Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

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

Love the improvements over TS, I'm considering borrowing some of this.

It'd be great if you could move the download and test server process management logic to core so we can reuse it in other SDKs (not blocking of course).

@cretz cretz merged commit 07da1b9 into temporalio:main Sep 1, 2022
@cretz cretz deleted the testing branch September 1, 2022 20:53
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.

Test framework
2 participants