开发者

SQLite/Fluent NHibernate integration test harness initialization not repeatable after large data session

开发者 https://www.devze.com 2023-01-03 19:06 出处:网络
In one of my main data integration test harnesses I create and use Fluent NHibernate\'s SingleConnectionSessionSourceForSQLiteInMemoryTesting, to get a fresh session for each test.After each test, I c

In one of my main data integration test harnesses I create and use Fluent NHibernate's SingleConnectionSessionSourceForSQLiteInMemoryTesting, to get a fresh session for each test. After each test, I close the connection, session, and session factory, and throw out the nested StructureMap container they came from. This works for almost any simple data integration test I can think of, including ones that utilize Fluent NHib's PersistenceSpecification object.

The trouble starts when I test the application's lengthy database bootstrapping process, which creates and saves thousands of domain objects. It's not that the first setup and tear-down of the test harness fails, in fact, the test harness successfully bootstraps the in-memory database as the application would bootstrap the real database in the production environment. The problem occurs when the database is bootstrapped a second time on a new in-memory database, with a new session and session factory.

The error is:

NHibernate.StaleStateException : Unexpected row count: 0; expected: 1

The row count is indeed Unexpected, the row that the application under test is looking for should be in the session. You see, it's not that any data from the last 开发者_如何学Pythonintegration test is sticking around, it's that for some reason the session just stops working mid-database-boostrap. And I've looked everywhere for a place I might be holding on to an old session and I can't find one.

I've searched through the code for static singleton objects, but there are none anywhere near the code in question. I have a couple StructureMap InstanceScope singleton's but they are getting thrown out with each nested container that is lost after every test teardown.

I've tried every possible variation on disposing and closing every object involved with each test teardown and it still fails on this lengthy database bootstrap. I've even messed around with current_session_context_class to no avail. But non-bootstrap related database tests appear to work fine. I'm starting to run out of options and I may have to surrender lengthy database integration tests in favor of WatiN-based acceptance tests.

Can anyone give me any clue about how I can figure out why some of my SingleConnectionSessionSourceForSQLiteInMemoryTesting aren't repeatable?

Any advice at all, about how to make an NHibernate SqlLite database integration test harness repeatable for large data sessions?


Here is how we do it http://www.gears4.net/blog/archive/14/nhibernate-integration-testing Hope it helps


I was able to solve this problem by not using an in memory database, and instead saving a hard copy file after initialization, once per test suite run. Then instead of reinitializing the database after each test, the file-based SqlLite database is copied and that new copy is used for testing.

Essentially, I only setup the initial database data once and save that database off to the side and it is copied for each test. There is a definite possibility that the problem could be on my end, but I suspect that there is an issue with large in-memory SqlLite databases. So I recommend using the file-mode of the database, if you are running into trouble with a large in-memory sqllite database.

0

精彩评论

暂无评论...
验证码 换一张
取 消