pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 469 forks source link

`ThinkingSphinx::Test.clean` raises error `Errno::ENOTEMPTY: Directory not empty` when deleting indices location #1259

Open pdany1116 opened 4 months ago

pdany1116 commented 4 months ago

Hello, our tests fail randomly at clean up phase for ThinkingSphinx. It seems it can not delete the indices directory (db/sphinx/test).

image

Here is our test setup for ThinkingSphinx in Minitest: sphinx_helper.rb

# frozen_string_literal: true

module SphinxHelper
  extend ActiveSupport::Concern
  include Minitest::Hooks

  included do
    after(:all) do
      ThinkingSphinx::Test.stop
    end

    setup do
      S3Stub.stub_all
      ThinkingSphinx::Test.start_with_autostop
    end

    teardown do
      ThinkingSphinx::Test.clear
    end

    around do |&block|
      DatabaseCleaner.strategy = DatabaseCleaner::ActiveRecord::Deletion.new(
        except: %w[roles]
      )
      DatabaseCleaner.cleaning(&block)
    end
  end

  def index_sphinx(indices = nil)
    indices ? ThinkingSphinx::Test.index(indices) : ThinkingSphinx::Test.index

    sleep 0.01 until SphinxHelper.index_finished?
  end

  def self.index_finished?
    Dir[Rails.root.join(ThinkingSphinx::Test.config.indices_location, '*.{new,tmp}*')].empty?
  end
end

test_helper.rb

# ...
ThinkingSphinx::Test.init
ThinkingSphinx::Test.config
# ...

In test we just include SphinxHelper module and use index_sphinx method after creating the test data with Faker.


Is it safe to remove manually the indices directory? For example:

    # ...
    teardown do
      FileUtils.rm_rf('db/sphinx/test')
      ThinkingSphinx::Test.clear
    end
    # ...

Gems: Ruby 3.0.6 Rails 7.0.8.1 ThinkingSphinx 5.5.1

pat commented 1 month ago

A very belated response, but: I've just released v5.6.0 which uses rm_rf instead of just rm_r. Hopefully this resolves the issue for you! Do let me know if that's not the case though.