Skip to content

Commit cb10d5b

Browse files
committed
[MODEL] Prevent integration test failures due to uneven distributions of documents across shards
(Tests depend on order of docs in the results.)
1 parent fe393b0 commit cb10d5b

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

elasticsearch-model/test/integration/active_record_associations_test.rb

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,26 @@ module Searchable
4242

4343
# Set up the mapping
4444
#
45-
mapping do
46-
indexes :title, analyzer: 'snowball'
47-
indexes :created_at, type: 'date'
48-
49-
indexes :authors do
50-
indexes :first_name
51-
indexes :last_name
52-
indexes :full_name, type: 'multi_field' do
53-
indexes :full_name
54-
indexes :raw, analyzer: 'keyword'
45+
settings index: { number_of_shards: 1, number_of_replicas: 0 } do
46+
mapping do
47+
indexes :title, analyzer: 'snowball'
48+
indexes :created_at, type: 'date'
49+
50+
indexes :authors do
51+
indexes :first_name
52+
indexes :last_name
53+
indexes :full_name, type: 'multi_field' do
54+
indexes :full_name
55+
indexes :raw, analyzer: 'keyword'
56+
end
5557
end
56-
end
5758

58-
indexes :categories, analyzer: 'keyword'
59+
indexes :categories, analyzer: 'keyword'
5960

60-
indexes :comments, type: 'nested' do
61-
indexes :text
62-
indexes :author
61+
indexes :comments, type: 'nested' do
62+
indexes :text
63+
indexes :author
64+
end
6365
end
6466
end
6567

@@ -228,7 +230,7 @@ class ActiveRecordAssociationsIntegrationTest < Elasticsearch::Test::Integration
228230

229231
assert_equal 3, response.results.size
230232
assert_equal 3, response.records.size
231-
end
233+
end if ::ActiveRecord.respond_to?(:version) && ::ActiveRecord.version.to_s > '4'
232234

233235
should "reindex a document after comments are added" do
234236
# Create posts
@@ -270,7 +272,7 @@ class ActiveRecordAssociationsIntegrationTest < Elasticsearch::Test::Integration
270272
}
271273

272274
assert_equal 1, response.results.size
273-
end
275+
end if ::ActiveRecord.respond_to?(:version) && ::ActiveRecord.version.to_s > '4'
274276

275277
should "reindex a document after Post#touch" do
276278
# Create categories

elasticsearch-model/test/integration/active_record_basic_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ class ::Article < ActiveRecord::Base
1010
include Elasticsearch::Model
1111
include Elasticsearch::Model::Callbacks
1212

13-
mapping do
14-
indexes :title, type: 'string', analyzer: 'snowball'
15-
indexes :created_at, type: 'date'
13+
settings index: { number_of_shards: 1, number_of_replicas: 0 } do
14+
mapping do
15+
indexes :title, type: 'string', analyzer: 'snowball'
16+
indexes :created_at, type: 'date'
17+
end
1618
end
1719
end
1820

elasticsearch-model/test/integration/mongoid_basic_test.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ class ::MongoidArticle
3333
field :title, type: String
3434
attr_accessible :title if respond_to? :attr_accessible
3535

36-
mapping do
37-
indexes :title, type: 'string', analyzer: 'snowball'
38-
indexes :created_at, type: 'date'
36+
settings index: { number_of_shards: 1, number_of_replicas: 0 } do
37+
mapping do
38+
indexes :title, type: 'string', analyzer: 'snowball'
39+
indexes :created_at, type: 'date'
40+
end
3941
end
4042

4143
def as_indexed_json(options={})

0 commit comments

Comments
 (0)