-
-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test parallel push doesn't lead mismatched sha
transactional_test is set to false because general test flow doesn't clear records created in Thread.new which use different db connection.
- Loading branch information
1 parent
7e14b94
commit 0af0f29
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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,46 @@ | ||
require 'test_helper' | ||
require 'concurrent/atomics' | ||
|
||
class ParallelPusherTest < ActiveSupport::TestCase | ||
self.use_transactional_tests = false | ||
|
||
context "when pushing gems in parallel" do | ||
setup do | ||
@fs = RubygemFs.mock! | ||
@user = create(:user, email: "user@example.com") | ||
end | ||
|
||
teardown do | ||
@user.destroy | ||
@rubygem = Rubygem.find_by(name: 'hola') | ||
@rubygem.versions.destroy_all | ||
@rubygem.destroy | ||
Delayed::Job.delete_all | ||
GemDownload.delete_all | ||
end | ||
|
||
should "not lead to sha mismatch between gem file and db" do | ||
@gem1 = gem_file("hola-0.0.0.gem") | ||
@gem2 = gem_file("hola/hola-0.0.0.gem") | ||
@cutter1 = Pusher.new(@user, @gem1) | ||
@cutter2 = Pusher.new(@user, @gem2) | ||
latch = Concurrent::CountDownLatch.new(2) | ||
|
||
Thread.new do | ||
@cutter1.process | ||
ActiveRecord::Base.connection.close | ||
latch.count_down | ||
end | ||
|
||
Thread.new do | ||
@cutter2.process | ||
ActiveRecord::Base.connection.close | ||
latch.count_down | ||
end | ||
|
||
latch.wait | ||
expected_sha = Digest::SHA2.base64digest(@fs.get('gems/hola-0.0.0.gem')) | ||
assert_equal expected_sha, Version.last.sha256 | ||
end | ||
end | ||
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