Skip to content
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

Replay testing #300

Merged
merged 22 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions examples/bin/update_replay_test_histories
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env ruby

# This script regenerates the workflow history files used in the example replay tests
# under examples/spec/replay/histories. It starts the necessary workflow, sends some
# signals, awaits workflow completion, then collects the history into JSON and protobuf
# binary file formats.
#
# To use this, start your Temporal server and bin/worker first. This script can then
# be run without any arguments. It will overwrite existing history files in the tree.
#
# NOTE: By default, collected history files contain the host names of the machines
# where the worker and this script are run because the default identity is pid@hostname.
# If you'd like, you can override this by setting an identity in the configuration in
# init.rb.

require_relative "../init"
require_relative "../workflows/signal_with_start_workflow"

workflow_id = SecureRandom.uuid
run_id = Temporal.start_workflow(
SignalWithStartWorkflow,
"hit",
options: {
workflow_id: workflow_id,
timeouts: {
execution: 30
},
signal_name: "miss",
signal_input: 1
}
)
Temporal.logger.info("Started workflow", {workflow_id: workflow_id, run_id: run_id})
sleep(1)
Temporal.signal_workflow(SignalWithStartWorkflow, "miss", workflow_id, run_id, 2)
sleep(1)
Temporal.signal_workflow(SignalWithStartWorkflow, "hit", workflow_id, run_id, 3)
Temporal.await_workflow_result(SignalWithStartWorkflow, workflow_id: workflow_id, run_id: run_id)

# Save in JSON, exactly like would be downloaded from Temporal UI
history_json = Temporal.get_workflow_history_json(workflow_id: workflow_id, run_id: run_id)
filename = File.expand_path("../spec/replay/histories/signal_with_start.json", File.dirname(__FILE__))
File.open(filename, "w") do |f|
f.write(history_json)
end

# Save in protobuf binary format
history_binary = Temporal.get_workflow_history_protobuf(workflow_id: workflow_id, run_id: run_id)
filename = File.expand_path("../spec/replay/histories/signal_with_start.protobin", File.dirname(__FILE__))
File.open(filename, "wb") do |f|
f.write(history_binary)
end
Binary file not shown.
Loading
Loading