-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes #1705 by locking node while Assigning rel #1706
Closed
Closed
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e060bc2
rel concurrency issue proving test cases
mrhardikjoshi 772525b
fixes #1705
mrhardikjoshi d885f66
removing the specs
mrhardikjoshi c3f6a8f
adding tests back
mrhardikjoshi 4191932
enhanced locking logic
mrhardikjoshi a958dab
Cleanup
mrhardikjoshi ea53581
Review feedback
mrhardikjoshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,58 @@ def self.count | |
expect(from_node.reload.to_classes).to be_empty | ||
end | ||
|
||
context 'concurrent update' do | ||
before do | ||
allow(ActiveGraph::Base).to receive(:lock_node).and_wrap_original do |original, *args| | ||
$concurrency_queue << 'ready' | ||
Thread.stop | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the right thing would be to stop at |
||
original.call(*args) | ||
$concurrency_queue << Thread.current | ||
Thread.stop | ||
end | ||
end | ||
after { $concurrency_queue = nil } | ||
let!(:from_node) { FromClass.create(name: 'foo') } | ||
let!(:to_node) { ToClass.create(name: 'bar') } | ||
let(:from_node_two) { FromClass.create(name: 'foo-2') } | ||
|
||
it 'does not create duplicate has_one relationship' do | ||
$concurrency_queue = Thread::Queue.new | ||
t1 = Thread.new { to_node.update(from_class: from_node) } | ||
t2 = Thread.new { to_node.update(from_class: from_node) } | ||
sleep(0.1) until $concurrency_queue.size == 2 | ||
$concurrency_queue.clear | ||
[t1, t2].each(&:run) | ||
sleep(0.1) until $concurrency_queue.size == 1 && t1.status == 'sleep' && t2.status == 'sleep' | ||
$concurrency_queue.pop.run | ||
sleep(0.1) until !(t1.status && t2.status) | ||
|
||
expect(ActiveGraph::Base.query("MATCH (node2:`ToClass`)<-[rel1:`HAS_REL`]-(from_class:`FromClass`) return from_class").to_a.size).to eq(1) | ||
(t1.status == 'sleep' ? t1.run : t2.run).join | ||
expect(ActiveGraph::Base.query("MATCH (node2:`ToClass`)<-[rel1:`HAS_REL`]-(from_class:`FromClass`) return from_class").to_a.size).to eq(1) | ||
end | ||
|
||
it 'does not create two rels with different nodes in has_one relationship' do | ||
$concurrency_queue = Thread::Queue.new | ||
t1 = Thread.new { to_node.update(from_class: from_node) } | ||
t2 = Thread.new { to_node.update(from_class: from_node_two) } | ||
sleep(0.1) until $concurrency_queue.size == 2 | ||
$concurrency_queue.clear | ||
[t1, t2].each(&:run) | ||
sleep(0.1) until $concurrency_queue.size == 1 && t1.status == 'sleep' && t2.status == 'sleep' | ||
$concurrency_queue.pop.run | ||
sleep(0.1) until !(t1.status && t2.status) | ||
|
||
first_assigned_from_class, second_assigned_from_class = t1.status == 'sleep' ? [from_node_two, from_node] : [from_node, from_node_two] | ||
|
||
expect(ToClass.find(to_node.id).from_class.id).to eq(first_assigned_from_class.id) | ||
(t1.status == 'sleep' ? t1.run : t2.run).join | ||
|
||
expect(to_node.reload.from_class.id).to eq(second_assigned_from_class.id) | ||
expect(ActiveGraph::Base.query("MATCH (node2:`ToClass`)<-[rel1:`HAS_REL`]-(from_class:`FromClass`) return from_class").to_a.size).to eq(1) | ||
end | ||
end | ||
|
||
it 'delets has_one rel from from_node when new relation is created' do | ||
to_node_two = ToClass.new(name: 'bar-2') | ||
Rel2Class.new(from_node: from_node, to_node: to_node, score: 10).save | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using
-
is faster compared to usingselect
loop and then checking withinclude?
again