I've just made some tweaks to Thinking Sphinx to improve testing behaviour with
real-time indices.
Firstly, grab the latest from the develop branch:
gem 'thinking-sphinx', '~> 3.1.0',
git: 'git://github.com/pat/thinking-sphinx.git',
branch: 'develop',
ref: 'f07848df13'
And then, in my own testing I've put the following in the RSpec configuration
of spec_helper.rb, but it's applicable as setup/teardown code generally:
config.before(:each) do
if example.metadata[:search]
ThinkingSphinx::Test.init
ThinkingSphinx::Test.start index: false
end
ThinkingSphinx::Configuration.instance.settings['real_time_callbacks'] =
!!example.metadata[:search]
end
config.after(:each) do
if example.metadata[:search]
ThinkingSphinx::Test.stop
ThinkingSphinx::Test.clear
end
end
I guess a UnitTest equivalent would be to have this module that is included in
appropriate tests:
module SphinxHelper
def setup_sphinx
ThinkingSphinx::Test.init
ThinkingSphinx::Test.start index: false
ThinkingSphinx::Configuration.instance.settings['real_time_callbacks'] =
true
end
def setdown_sphinx
ThinkingSphinx::Test.stop
ThinkingSphinx::Test.clear
end
end
And call those two methods at the appropriate points.
Also, for all non-search tests, you'll likely want to disable real-time
callbacks:
ThinkingSphinx::Configuration.instance.settings['real_time_callbacks'] = false
On 7 Mar 2014, at 6:04 am, Davide Barison <[email protected]> wrote:
> Hi all,
>
> i've this strange problem
>
> thinking_sphinx.yml
>
> development:
> mysql41: 9301
> mem_limit: 1024M
> dict: keywords
> enable_star: true
> min_prefix_len: 3
> sql_range_step: 10000000
> test:
> mysql41: 9303
> mem_limit: 1024M
> dict: keywords
> enable_star: true
> min_prefix_len: 3
> sql_range_step: 10000000
>
>
> module SphinxHelper
> def init_thinking_sphinx
> ThinkingSphinx::Test.init
> ThinkingSphinx::Test.start_with_autostop
> index
> end
>
> def index
> ThinkingSphinx::Test.index
> sleep 0.25 until index_finished?
> end
>
> def index_finished?
> Dir[Rails.root.join(ThinkingSphinx::Test.config.indices_location,
> '*.{new,tmp}.*')].empty?
> end
> end
>
>
> class PostSphinxTest < ActiveSupport::TestCase
>
> def setup
> init_thinking_sphinx
> @user = create(:user)
> end
>
> test 'sphinx order by created_at desc' do
> search = PostSearch.new(@user, order: 'created_at', direction: 'desc')
> requests = Request.ts_search(search)
> requests.each_with_index do |r, i|
> rr = requests[i+1]
> if rr
> assert_operator r.created_at, :>=, rr.created_at
> end
> end
> end
>
>
> when i run this test i get this error
>
> ThinkingSphinx::Search::StaleIdsException: Record IDs found by Sphinx but not
> by ActiveRecord
>
> This error occurs even if i run only this specific test
>
> It seems indeces aren't syncronized with the test database
>
> Any suggestion or help?
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.