Skip to first unread message

Jason Boccuti

unread,
Jul 9, 2014, 2:35:40 PM7/9/14
to d...@openmrs.org
I hate to post two questions in one day, but I just keep encountering strange testing bugs (or possible constraints).

When creating tests for a service method (created by me) that queries the database, in a module, using the hibernate createSQLQuery method, each test accesses the database once to provide a list of the results.  In total, I have about 30-some tests but it seems to hang on the 25th service call regardless of what test it's in - for example, I made the first test call the service method 26 times and it proceeded to hang on the 25th call.  Also, I tried moving some of the tests to another test class that would be run after the first test class of the module, but it again proceeded to hang on the 25th call.

When using the debugger in eclipse, I could narrow down to the line where the query.list() is called to actually execute the query, but when I attempt to step over the line, it just hangs.  This is only on the 25th time it's called.  I don't seem to be getting any errors or exceptions and the stack trace doesn't provide much utility as most of the code is being called from other classes in the core that are already compiled.  

By chance, does anyone know where this magic 25th constraint may be coming from?  If so, is there any workaround that anyone might know of?

Thanks,
Jason
Message has been deleted
Message has been deleted

Jason Boccuti

unread,
Jul 9, 2014, 4:29:14 PM7/9/14
to d...@openmrs.org
I realized that we weren't actually closing our hibernate session after we executed our query.  Essentially, it was creating a new session every time it accessed the database without closing the old one.  I'm assuming there is some sort of limit to how many sessions can be open and that's why it was hanging after about the 50th time (25 was actually in correct as each query was accessing the database twice with another query).

Problem solved!  For anyone who may look at this if they are experiencing similar problems: Make sure to close your session after you execute the hibernate query!

Darius Jazayeri

unread,
Jul 10, 2014, 1:08:57 AM7/10/14
to d...@openmrs.org

You shouldn't have to manually manage hibernate sessions in 95% of unit tests.

Take a look at existing unit tests in modules, which just extend BaseModuleContextSensitiveTest.

Also, you are doing session factory.getCurrentSession in your DAO code and not creating the session yourself.

-Darius

On Jul 9, 2014 11:29 PM, "Jason Boccuti" <stj...@moravian.edu> wrote:
I realized that we weren't actually closing our hibernate session after we executed our query.  Essentially, it was creating a new session every time it accessed the database without closing the old one.  I'm assuming there is some sort of limit to how many sessions can be open and that's why it was hanging after about the 50th time (25 was actually in correct as each query was accessing the database twice with another query).

Problem solved!  For anyone who may look at this if they are experiencing similar problems: Make sure to close your session after you execute the hibernate query!

--
OpenMRS Developers: http://go.openmrs.org/dev
Post: d...@openmrs.org | Unsubscribe: dev+uns...@openmrs.org
Manage your OpenMRS subscriptions at https://id.openmrs.org/
Reply all
Reply to author
Forward
0 new messages