Skip to content

Commit de95727

Browse files
committed
kill off parallelism for sqlite and test rails 5 with foreign keys
1 parent 73cad41 commit de95727

File tree

7 files changed

+39
-56
lines changed

7 files changed

+39
-56
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ rvm:
1111
gemfile:
1212
- gemfiles/activerecord_4.1.gemfile
1313
- gemfiles/activerecord_4.2.gemfile
14+
- gemfiles/activerecord_5.0_foreigner.gemfile
1415
- gemfiles/activerecord_5.0.gemfile
1516
- gemfiles/activerecord_edge.gemfile
1617

Appraisals

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
appraise 'activerecord-4.1' do
22
gem 'activerecord', '~> 4.1.0'
3-
gem 'foreigner', :git => 'https://github.com/matthuhiggins/foreigner.git'
3+
gem 'foreigner'
44
platforms :ruby, :rbx do
55
gem 'mysql2', '~> 0.3.20'
66
end
@@ -14,6 +14,11 @@ appraise 'activerecord-4.2' do
1414
end
1515
end
1616

17+
appraise 'activerecord-5.0-foreigner' do
18+
gem 'activerecord', '~> 5.0.0'
19+
gem 'foreigner'
20+
end
21+
1722
appraise 'activerecord-5.0' do
1823
gem 'activerecord', '~> 5.0.0'
1924
end

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ bundle install
527527

528528
### Object destroy fails with MySQL 5.7+
529529

530-
A bug was introduced in the query optimizer. [See the workaround here](https://github.com/mceachen/closure_tree/issues/206).
530+
A bug was introduced in MySQL's query optimizer. [See the workaround here](https://github.com/mceachen/closure_tree/issues/206).
531531

532532
## Testing with Closure Tree
533533

gemfiles/activerecord_4.1.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source "https://rubygems.org"
44

55
gem "activerecord", "~> 4.1.0"
6-
gem "foreigner", :git => "https://github.com/matthuhiggins/foreigner.git"
6+
gem "foreigner"
77

88
platforms :ruby, :rbx do
99
gem "mysql2", "~> 0.3.20"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file was generated by Appraisal
2+
3+
source "https://rubygems.org"
4+
5+
gem "activerecord", "~> 5.0.0"
6+
gem "foreigner"
7+
8+
platforms :ruby, :rbx do
9+
gem "mysql2"
10+
gem "pg"
11+
gem "sqlite3"
12+
end
13+
14+
platforms :jruby do
15+
gem "activerecord-jdbcmysql-adapter"
16+
gem "activerecord-jdbcpostgresql-adapter"
17+
gem "activerecord-jdbcsqlite3-adapter"
18+
end
19+
20+
gemspec :path => "../"

spec/parallel_spec.rb

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
require 'spec_helper'
22

33
# We don't need to run the expensive parallel tests for every combination of prefix/suffix.
4-
# Those affect SQL generation, not parallelism
4+
# Those affect SQL generation, not parallelism.
5+
# SQLite doesn't support concurrency reliably, either.
56
def run_parallel_tests?
6-
ActiveRecord::Base.table_name_prefix.empty? &&
7+
!sqlite? &&
8+
ActiveRecord::Base.table_name_prefix.empty? &&
79
ActiveRecord::Base.table_name_suffix.empty?
810
end
911

1012
def max_threads
1113
5
1214
end
1315

14-
1516
class WorkerBase
1617
extend Forwardable
1718
attr_reader :name
@@ -106,7 +107,7 @@ def run_workers(worker_class = FindOrCreateWorker)
106107
run_workers
107108
# duplication from at least one iteration:
108109
expect(Tag.where(name: @names).size).to be > @iterations
109-
end unless sqlite? # sqlite throws errors from concurrent access
110+
end
110111

111112
class SiblingPrependerWorker < WorkerBase
112113
def before_work
@@ -119,50 +120,6 @@ def work
119120
end
120121
end
121122

122-
# TODO: this test should be rewritten to be proper producer-consumer code
123-
xit 'fails to deadlock from parallel sibling churn' do
124-
# target should be non-trivially long to maximize time spent in hierarchy maintenance
125-
target = Tag.find_or_create_by_path(('a'..'z').to_a + ('A'..'Z').to_a)
126-
expected_children = (1..100).to_a.map { |ea| "root ##{ea}" }
127-
children_to_add = expected_children.dup
128-
added_children = []
129-
children_to_delete = []
130-
deleted_children = []
131-
creator_threads = @workers.times.map do
132-
Thread.new do
133-
while children_to_add.present?
134-
name = children_to_add.shift
135-
unless name.nil?
136-
Tag.transaction { target.find_or_create_by_path(name) }
137-
children_to_delete << name
138-
added_children << name
139-
end
140-
end
141-
end
142-
end
143-
run_destruction = true
144-
destroyer_threads = @workers.times.map do
145-
Thread.new do
146-
begin
147-
victim_name = children_to_delete.shift
148-
if victim_name
149-
Tag.transaction do
150-
victim = target.children.where(name: victim_name).first
151-
victim.destroy
152-
deleted_children << victim_name
153-
end
154-
else
155-
sleep rand # wait for more victims
156-
end
157-
end while run_destruction || !children_to_delete.empty?
158-
end
159-
end
160-
creator_threads.each(&:join)
161-
destroyer_threads.each(&:join)
162-
expect(added_children).to match(expected_children)
163-
expect(deleted_children).to match(expected_children)
164-
end
165-
166123
it 'fails to deadlock while simultaneously deleting items from the same hierarchy' do
167124
target = User.find_or_create_by_path((1..200).to_a.map { |ea| ea.to_s })
168125
emails = target.self_and_ancestors.to_a.map(&:email).shuffle
@@ -176,7 +133,7 @@ def work
176133
end
177134
User.connection.reconnect!
178135
expect(User.all).to be_empty
179-
end unless sqlite? # sqlite throws errors from concurrent access
136+
end
180137

181138
class SiblingPrependerWorker < WorkerBase
182139
def before_work
@@ -198,6 +155,5 @@ def work
198155

199156
# The only non-root node should be "root":
200157
expect(Label.all.select { |ea| ea.root? }).to eq([@target.parent])
201-
end unless sqlite? # sqlite throws errors from concurrent access
202-
158+
end
203159
end if run_parallel_tests?

tests.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/bin/sh -ex
22

3-
for RMI in 2.2.3 #jruby-1.6.13 :P
3+
for RMI in 2.3.1 #jruby-1.6.13 :P
44
do
55
rbenv local $RMI
6-
for DB in postgresql mysql sqlite
6+
appraisal bundle install
7+
for DB in mysql sqlite postgresql
78
do
89
appraisal rake spec:all WITH_ADVISORY_LOCK_PREFIX=$(date +%s) DB=$DB
910
done

0 commit comments

Comments
 (0)