Skip to content

Commit

Permalink
FIx tests after change to making idempotency_key in the job internal
Browse files Browse the repository at this point in the history
  • Loading branch information
fractaledmind committed Nov 1, 2024
1 parent 08514c6 commit 8608bbc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lib/acidic_job/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ module Workflow
def execute_workflow(unique_by:, &block)
serialized_job = serialize

AcidicJob.instrument(:define_workflow, **serialized_job) do
raise RedefiningWorkflowError if defined? @builder
workflow_definition = AcidicJob.instrument(:define_workflow, **serialized_job) do
raise RedefiningWorkflowError if defined? @_builder

@builder = Builder.new
@_builder = Builder.new

raise UndefinedWorkflowBlockError unless block_given?
raise InvalidWorkflowBlockError if block.arity != 1

block.call @builder
block.call @_builder

raise MissingStepsError if @builder.steps.empty?
raise MissingStepsError if @_builder.steps.empty?

# convert the array of steps into a hash of recovery_points and next steps
workflow_definition = @builder.define_workflow
@_builder.define_workflow
end

AcidicJob.instrument(:initialize_workflow, "definition" => workflow_definition) do
Expand Down
2 changes: 1 addition & 1 deletion test/acidic_job/basics_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def step_3; Performance.performed!; end

assert_equal [self.class.name, "Job10"].join("::"), execution.serialized_job["job_class"]
assert_equal "FINISHED", execution.recover_to
assert_equal "a615eeaee21de5179de080de8c3052c8da901138406ba71c38c032845f7d54f4", execution.idempotency_key
assert_equal "0ce3d65c09b390b8a53060eb6184a30d4a7025ca403b9f5aeda769932a9e2c86", execution.idempotency_key

assert_equal 6, AcidicJob::Entry.count
assert_equal(
Expand Down
16 changes: 12 additions & 4 deletions test/acidic_job/idempotency_key_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def step_1; nil; end
job = AcidicByArguments.new
job.perform_now

assert_equal "4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945", job.idempotency_key
execution = AcidicJob::Execution.first

assert_equal "bab619c21aa975baef217fbd5c6e01a7674d9d8ee3fa1c4e2a178e41d7952b23", execution.idempotency_key
end

test "idempotency_key when unique_by is arguments and arguments are a static string" do
Expand All @@ -63,7 +65,9 @@ def step_1; nil; end
job = AcidicByBlockWithString.new("a")
job.perform_now

assert_equal "0eb5b8d6f81bc677da8a08567cc4fa9a06a57e9ec8da85ed73a7f62727996002", job.idempotency_key
execution = AcidicJob::Execution.first

assert_equal "11460654191869f08d979326233f4d4b1287b77ed069c53ac79036d96d54dd3e", execution.idempotency_key
end

test "idempotency_key when unique_by is arguments and arguments are an array of strings" do
Expand All @@ -80,7 +84,9 @@ def step_1; nil; end
job = AcidicByBlockWithArrayOfStrings.new("a", "b")
job.perform_now

assert_equal "0473ef2dc0d324ab659d3580c1134e9d812035905c4781fdd6d529b0c6860e13", job.idempotency_key
execution = AcidicJob::Execution.first

assert_equal "76564b0604a5dfd81d1f637416e664352eda527e2cd78a806e91ad6ccd609eb3", execution.idempotency_key
end

test "idempotency_key when unique_by is arguments and arguments are an array of different values" do
Expand All @@ -97,6 +103,8 @@ def step_1; nil; end
job = AcidicByBlockWithArgValue.new([1, "string", { a: 1, b: 2 }, [3, 4, 5]])
job.perform_now

assert_equal "e493eb3be3e78cb3f40d40402c532efad9cf240d2dd6af839d37ef51a6f71aba", job.idempotency_key
execution = AcidicJob::Execution.first

assert_equal "a7c36d24b42051092df5547146952d4707bf6e04b84774576bad6a37937d018a", execution.idempotency_key
end
end

0 comments on commit 8608bbc

Please sign in to comment.