-
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(unlock): ensure callback and unlock (#771)
* chore(deps): update gems (solargraph is awesome) * fix(unlock): ensure unlock and callback runs * chore(lint): lint'em real good # Conflicts: # .github/workflows/rspec.yml # myapp/.tool-versions
- Loading branch information
Showing
10 changed files
with
80 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ def lock(&block) | |
def execute | ||
executed = locksmith.execute do | ||
yield | ||
ensure | ||
unlock_and_callback | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ruby 3.2.2 | ||
nodejs 19.1.0 | ||
yarn 1.22.19 | ||
direnv 2.32.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
spec/support/shared_examples/an_executing_lock_implementation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples "an executing lock implementation" do | ||
context "when job can't be locked" do | ||
before do | ||
allow(process_one.locksmith).to receive(:execute).and_return(nil) | ||
end | ||
|
||
it "does not execute" do | ||
unset = true | ||
process_one.execute { unset = false } | ||
expect(unset).to be(true) | ||
end | ||
end | ||
|
||
context "when process_one executes the job" do | ||
before { process_one.lock } | ||
|
||
it "keeps being locked while executing" do | ||
process_one.execute do | ||
expect(process_one).to be_locked | ||
end | ||
end | ||
|
||
it "keeps being locked when an error is raised" do | ||
allow(process_one.locksmith).to receive(:execute).and_raise(RuntimeError, "Hell") | ||
|
||
expect { process_one.execute { "hey ho" } }.to raise_error("Hell") | ||
|
||
expect(process_one).to be_locked | ||
end | ||
|
||
it "prevents process_two from locking" do | ||
process_one.execute do | ||
expect(process_two.lock).to be_nil | ||
expect(process_two).not_to be_locked | ||
end | ||
end | ||
|
||
it "prevents process_two from executing" do | ||
expect { process_two.execute { raise "Hell" } }.not_to raise_error | ||
end | ||
|
||
it "reflects execution_failed on failure" do | ||
allow(process_two).to receive(:reflect).and_call_original | ||
process_two.execute { puts "Failed to execute" } | ||
|
||
expect(process_two).to have_received(:reflect).with(:execution_failed, item_two) | ||
end | ||
|
||
it "yields without arguments" do | ||
process_one.lock | ||
process_one.execute {} | ||
blk = -> {} | ||
|
||
expect { process_one.execute(&blk) }.not_to raise_error | ||
end | ||
end | ||
end |