Skip to content

Commit 5d12aa3

Browse files
authored
Replay testing (#300)
* Specialize workflow event targets * Methods for downloading histories * Replay tester * Basic replay tester unit tests * Add example replay test with history file * Add workflow stack trace to replay error * Dynamically load replay state in workflow logger * Log when replaying in replay tests * Use binpb extension for protobuf biniaries * Better comments about logging during replay * Simplify file -> bytes read calls * Fix comment typos * More ergonomic replaying callback * Improve ReplayTesterError, rubyfmt spec * Remove extra commands check * Don't default to logging in replay tests * Check history starts correctly * Remove correct_event_types * Refactor to more composable API * Use real namespace from configuration * rubyfmt * Fix test name typo
1 parent 3fbc675 commit 5d12aa3

19 files changed

+915
-33
lines changed
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env ruby
2+
3+
# This script regenerates the workflow history files used in the example replay tests
4+
# under examples/spec/replay/histories. It starts the necessary workflow, sends some
5+
# signals, awaits workflow completion, then collects the history into JSON and protobuf
6+
# binary file formats.
7+
#
8+
# To use this, start your Temporal server and bin/worker first. This script can then
9+
# be run without any arguments. It will overwrite existing history files in the tree.
10+
#
11+
# NOTE: By default, collected history files contain the host names of the machines
12+
# where the worker and this script are run because the default identity is pid@hostname.
13+
# If you'd like, you can override this by setting an identity in the configuration in
14+
# init.rb.
15+
16+
require_relative "../init"
17+
require_relative "../workflows/signal_with_start_workflow"
18+
19+
workflow_id = SecureRandom.uuid
20+
run_id = Temporal.start_workflow(
21+
SignalWithStartWorkflow,
22+
"hit",
23+
options: {
24+
workflow_id: workflow_id,
25+
timeouts: {
26+
execution: 30
27+
},
28+
signal_name: "miss",
29+
signal_input: 1
30+
}
31+
)
32+
Temporal.logger.info("Started workflow", {workflow_id: workflow_id, run_id: run_id})
33+
sleep(1)
34+
Temporal.signal_workflow(SignalWithStartWorkflow, "miss", workflow_id, run_id, 2)
35+
sleep(1)
36+
Temporal.signal_workflow(SignalWithStartWorkflow, "hit", workflow_id, run_id, 3)
37+
Temporal.await_workflow_result(SignalWithStartWorkflow, workflow_id: workflow_id, run_id: run_id)
38+
39+
# Save in JSON, exactly like would be downloaded from Temporal UI
40+
history_json = Temporal.get_workflow_history_json(workflow_id: workflow_id, run_id: run_id)
41+
filename = File.expand_path("../spec/replay/histories/signal_with_start.json", File.dirname(__FILE__))
42+
File.open(filename, "w") do |f|
43+
f.write(history_json)
44+
end
45+
46+
# Save in protobuf binary format
47+
history_binary = Temporal.get_workflow_history_protobuf(workflow_id: workflow_id, run_id: run_id)
48+
filename = File.expand_path("../spec/replay/histories/signal_with_start.protobin", File.dirname(__FILE__))
49+
File.open(filename, "wb") do |f|
50+
f.write(history_binary)
51+
end
Binary file not shown.

0 commit comments

Comments
 (0)