I am using Xapian through the Ruby bindings and am wondering the best way to use it in a unit test suite where we must start with an empty database every time (so records generated in one test don't interfere with another). I am currently deleting the database directory and regenerating it every time, but I find this to be very slow (nearly half a second). This results in even a small number of tests taking a long time to run. Is there some fast way to clear an existing database of all content (terms, values, spellings, etc.)? If not, what is the best practice for resetting a database for each test? Regards, Ryan
David P. Novakovic
2009-Nov-02 23:46 UTC
[Xapian-discuss] Fwd: Clearing Database For Tests
I forgot to cc the mailing list... ---------- Forwarded message ---------- From: David P. Novakovic <davidnovakovic at gmail.com> Date: Tue, Nov 3, 2009 at 9:45 AM Subject: Re: [Xapian-discuss] Clearing Database For Tests To: Ryan Bates <ryan at railscasts.com> i know this doesn't answer your question, but it is definitely worth mentioning: I've found that I actually don't need that many tests for interface code to xapian. Once you have tests that prove your base wrapper functions work as expected wouldn't you just want to test your code not xapian? Use mocks and dep injection to avoid actually touching the xapian code... I've forgotten the technical term for it, but you want to avoid testing code that is outside of the scope of what you are trying to test. On Tue, Nov 3, 2009 at 9:36 AM, Ryan Bates <ryan at railscasts.com> wrote:> I am using Xapian through the Ruby bindings and am wondering the best > way to use it in a unit test suite where we must start with an empty > database every time (so records generated in one test don't interfere > with another). I am currently deleting the database directory and > regenerating it every time, but I find this to be very slow (nearly > half a second). This results in even a small number of tests taking a > long time to run. > > Is there some fast way to clear an existing database of all content > (terms, values, spellings, etc.)? If not, what is the best practice > for resetting a database for each test? > > Regards, > > Ryan > > _______________________________________________ > Xapian-discuss mailing list > Xapian-discuss at lists.xapian.org > http://lists.xapian.org/mailman/listinfo/xapian-discuss >
On Mon, Nov 02, 2009 at 03:36:01PM -0800, Ryan Bates wrote:> I am currently deleting the database directory and > regenerating it every time, but I find this to be very slow (nearly > half a second). This results in even a small number of tests taking a > long time to run.I just tried this, and it's more like 0.05 seconds elapsed time on average for me (including the overhead of running simpleindex). I tested with: rm -rf tmp.db time examples/simpleindex tmp.db < /dev/null I tested with trunk on Ubuntu karmic with ext3 as the FS. Half a second seems unreasonably slow, but you're going to have to profile it to show us why it is so much slower for you. Cheers, Olly