To edit pages or tickets please login with username/password: aaf/aaf

Ticket #90 (reopened defect)

Opened 2 years ago

Last modified 1 year ago

Rails tests fail because ferret index is not updated when starting tests

Reported by: anonymous Assigned to: somebody
Priority: major Milestone:
Component: 0plugin Version:
Keywords: Cc:

Description

I think it will be quite a good idea to split index directories according to environment (dev,test,prod) and clear test index when starting a test sequence

Change History

03/06/07 11:23:11 changed by jk@jkraemer.net

that's exactly what aaf does - it creates it's index directories in RAILS_ROOT/index/RAILS_ENV/ by default. If this doesn't work for you I'd need some more information to find out why.

03/14/07 16:31:05 changed by jk@jkraemer.net

  • status changed from new to closed.
  • resolution set to worksforme.

closing

03/19/07 03:57:26 changed by Dav

  • status changed from closed to reopened.
  • resolution deleted.

It puts the indexes in RAILS_ROOT/index/RAILS_ENV/ but it does not clear the index before each test method.

I have two functional tests. One deletes a fixture, the other does a search which should return that fixture.

Running either test separately is fine, but if I run them together, with the search being the second one, it fails because the index was not reset between the two tests.

03/19/07 17:41:18 changed by jk@jkraemer.net

It would be hard to guess for aaf when to rebuild the index in such a scenario. Just put the appropriate rebuild_index calls in your test's setup method:

def setup
  Model.rebuild_index
end

Or you could even wipe out the whole index/test directory like that:

require 'fileutils'

def setup
  FileUtils.rm_f "#{RAILS_ROOT}/index/test/"
end

In either case the index will be rebuilt from your fixtures before each test method is run. Does that solve your problem?

03/20/07 06:00:04 changed by Dav

I tried FileUtils?.rm_rf. The strange thing there was the directory was removed, but it was never subsequently rebuilt upon the find_by_contents call, causing an error.

What I ended up doing was to add a class method I found elsewhere in a comment here to the model and call it before the search tests:

def self.zero_index

index = self.ferret_index index.size.times {|i| index.delete(i)}

end

Perhaps rebuild_index does the same thing?

04/28/07 20:15:02 changed by yoss

I am seeing the same behaviour during testing.

I have some functional test methods that are exercising an EventController?, but aaf is not re-indexing. The problem started happening when I introduced a test_destroy method (which tests deletion of an Event object from the db). Because tests seem to get run in alphabetical order, and test_show occurs after test_destroy, I get an exception during test_show because the index was not rebuilt:

Exception: cannot determine document number from primary key: 1

I think this happens because the "show" page in my app has a more_like_this method call which can't complete due to an indexing problem.

Putting Event.rebuild_index in setup doesn't help, I get:

Exception: File Not Found Error occured at <except.c>:117 in xpop_context
Error occured in fs_store.c:329 - fs_open_input
	tried to open "/home/yossa/workspace/railsapp/config/../index/test/event/_3_1.del" but it doesn't exist: <No such file or directory>

The FileUtils?.rm_f idea doesn't seem to be working either.

The quickest dumbest hack for now would be to rename test_show to something like test_a_show so that it executes before the test_destroy method.

I also tried introducing a zero_index method in Event, but that didn't seem to work for me.

05/23/07 05:49:46 changed by anonymous

I was having a similar problem. I have transactional fixtures turned off if that affects things. The errors I was seeing was because some objects weren't getting saved to the DB because the :ferret_create callback was failing. The exception that was raised was similar to the previous comment:

#<Ferret::FileNotFoundError: File Not Found Error occured at <except.c>:117 in xpop_context
Error occured in fs_store.c:329 - fs_open_input
        tried to open "...../index/test/model/_o.cfs" but it doesn't exist: <No such file or directory>

I tried this (reload fixtures drops all the data from all the fixture tables then reloads it, so you end up with records in test 2 having different ids than test 1):

def setup
  reload_fixtures
  Model.rebuild_index
end

but it didn't help. I still got the same exception. I then tried:

  def setup
    reload_fixtures
    FileUtils.rm_r("#{RAILS_ROOT}/index/#{RAILS_ENV}") if File.directory?("#{RAILS_ROOT}/index/#{RAILS_ENV}")
  end

and it appears to work.

Why wouldn't calling rebuild_index work?

05/23/07 06:00:03 changed by anonymous

I forgot to add to my last ticket that I stepped through the AAf ruby code until I got to:

/var/lib/gems/1.8/gems/ferret-0.11.4/lib/ferret/index.rb:285
@writer.delete(@key, id)

That's the line that raised the File Not Found error. Here's the stack trace from when I called 'save' on my model instance.

--> #0 /var/lib/gems/1.8/gems/ferret-0.11.4/lib/ferret/index.rb:267 in '<<'
    #1 /home/user/project/branches/branch/config/../vendor/plugins/acts_as_ferret/lib/local_index.rb:140 in '<<'
    #2 /home/user/project/branches/branch/config/../vendor/plugins/acts_as_ferret/lib/instance_methods.rb:73 in 'ferret_create'
    #3 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:333 in 'send'
    #4 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:333 in 'callback'
    #5 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:330 in 'callback'
    #6 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:255 in 'create_without_timestamps'
    #7 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/timestamp.rb:39 in 'create'
    #8 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/base.rb:1790 in 'create_or_update_without_callbacks'
    #9 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/callbacks.rb:242 in 'create_or_update'
    #10 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/base.rb:1546 in 'save_without_validation'
    #11 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/validations.rb:752 in 'save_without_transactions'
    #12 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/transactions.rb:129 in 'save'
    #13 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/transactions.rb:95 in '[]'
    #14 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/transactions.rb:121 in 'transaction'
    #15 /home/user/project/branches/branch/config/../vendor/rails/activerecord/lib/active_record/transactions.rb:129 in 'save'

06/19/07 08:24:27 changed by jk

Can anybody please provide a unit or functional test that reproduces this behaviour within aaf's demo project?

06/19/07 08:30:16 changed by jk

to resolve the errors when using rm_rf, close the ferret index before:

Model.aaf_index.close

To edit pages or tickets please login with username/password: aaf/aaf