Skip to content

Commit 407578e

Browse files
authored
Fixed the workflow redis key format used in Client#next_free_workflow_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.
1 parent bf3cc61 commit 407578e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/gush/client.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def next_free_workflow_id
7272
id = nil
7373
loop do
7474
id = SecureRandom.uuid
75-
available = !redis.exists?("gush.workflow.#{id}")
75+
available = !redis.exists?("gush.workflows.#{id}")
7676

7777
break if available
7878
end

spec/gush/client_spec.rb

+31
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,37 @@
9797
end
9898
end
9999

100+
describe "#next_free_job_id" do
101+
it "returns an id" do
102+
expect(client.next_free_job_id('123', Prepare.to_s)).to match(/^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/)
103+
end
104+
105+
it "returns an id that doesn't match an existing job id" do
106+
workflow = TestWorkflow.create
107+
job = workflow.jobs.first
108+
109+
second_try_id = '1234'
110+
allow(SecureRandom).to receive(:uuid).and_return(job.id, second_try_id)
111+
112+
expect(client.next_free_job_id(workflow.id, job.class.to_s)).to eq(second_try_id)
113+
end
114+
end
115+
116+
describe "#next_free_workflow_id" do
117+
it "returns an id" do
118+
expect(client.next_free_workflow_id).to match(/^\h{8}-\h{4}-(\h{4})-\h{4}-\h{12}$/)
119+
end
120+
121+
it "returns an id that doesn't match an existing workflow id" do
122+
workflow = TestWorkflow.create
123+
124+
second_try_id = '1234'
125+
allow(SecureRandom).to receive(:uuid).and_return(workflow.id, second_try_id)
126+
127+
expect(client.next_free_workflow_id).to eq(second_try_id)
128+
end
129+
end
130+
100131
describe "#persist_workflow" do
101132
it "persists JSON dump of the Workflow and its jobs" do
102133
job = double("job", to_json: 'json')

0 commit comments

Comments
 (0)