Skip to content

Commit

Permalink
Fixed the workflow redis key format used in `Client#next_free_workflo…
Browse files Browse the repository at this point in the history
…w_id` (#120)

Previously, the wrong key prefix was used, which means that this method
was not actually checking whether a workflow id was already in use.
  • Loading branch information
noahfpf authored Aug 8, 2024
1 parent bf3cc61 commit 407578e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/gush/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def next_free_workflow_id
id = nil
loop do
id = SecureRandom.uuid
available = !redis.exists?("gush.workflow.#{id}")
available = !redis.exists?("gush.workflows.#{id}")

break if available
end
Expand Down
31 changes: 31 additions & 0 deletions spec/gush/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,37 @@
end
end

describe "#next_free_job_id" do
it "returns an id" do
expect(client.next_free_job_id('123', Prepare.to_s)).to match(/^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/)
end

it "returns an id that doesn't match an existing job id" do
workflow = TestWorkflow.create
job = workflow.jobs.first

second_try_id = '1234'
allow(SecureRandom).to receive(:uuid).and_return(job.id, second_try_id)

expect(client.next_free_job_id(workflow.id, job.class.to_s)).to eq(second_try_id)
end
end

describe "#next_free_workflow_id" do
it "returns an id" do
expect(client.next_free_workflow_id).to match(/^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/)
end

it "returns an id that doesn't match an existing workflow id" do
workflow = TestWorkflow.create

second_try_id = '1234'
allow(SecureRandom).to receive(:uuid).and_return(workflow.id, second_try_id)

expect(client.next_free_workflow_id).to eq(second_try_id)
end
end

describe "#persist_workflow" do
it "persists JSON dump of the Workflow and its jobs" do
job = double("job", to_json: 'json')
Expand Down

0 comments on commit 407578e

Please sign in to comment.