Opened 3 years ago

Closed 3 years ago

#32445 closed Cleanup/optimization (fixed)

LiveServerThreadTest.test_closes_connections() doesn't pass with non-in-memory SQLite

Reported by: Chris Jerdonek Owned by: Chris Jerdonek
Component: Testing framework Version: 3.1
Severity: Normal Keywords: SQLite, is_usable, LiveServerThread
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I noticed that LiveServerThreadTest.test_closes_connections() doesn't seem to pass when using non-in-memory SQLite. It's only configured to be skipped for in-memory SQLite. It doesn't pass because the test has the following line:

self.assertFalse(conn.is_usable())

But SQLite's is_usable() has a hard-coded return value of True:
https://github.com/django/django/blob/3fa1ed53be370f4b1a94d78b56ff30d23b131623/django/db/backends/sqlite3/base.py#L387-L388

I guess this means that Django's CI doesn't check non-in-memory SQLite. If it's true that Django doesn't check this case, I'm not sure if that means it doesn't need to be fixed.

Change History (10)

comment:1 Changed 3 years ago by Mariusz Felisiak

Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

I guess this means that Django's CI doesn't check non-in-memory SQLite.

That's True, but I think it's still worth fixing. There is an interesting discussion about this test in the original PR. I think we should remove test_closes_connections() from django_test_skips() and use @skipUnlessDBFeature('test_db_allows_multiple_connections') instead.

comment:2 Changed 3 years ago by Chris Jerdonek

Just to be totally clear, would @skipUnlessDBFeature('test_db_allows_multiple_connections') mean that the test is or isn't skipped with non-in-memory SQLite?

comment:3 in reply to:  2 Changed 3 years ago by Mariusz Felisiak

Replying to Chris Jerdonek:

Just to be totally clear, would @skipUnlessDBFeature('test_db_allows_multiple_connections') mean that the test is or isn't skipped with non-in-memory SQLite?

It will always be skipped on SQLite, so also with non-in-memory database.

comment:4 Changed 3 years ago by Chris Jerdonek

It will always be skipped on SQLite, so also with non-in-memory database.

Okay, that's what I thought. Why do you think the test should always be skipped on SQLite as opposed to making the test work also for non-in-memory SQLite? It seems like making it work would be the better outcome since it would cover more scenarios where the test makes sense.

comment:5 in reply to:  4 Changed 3 years ago by Mariusz Felisiak

Replying to Chris Jerdonek:

Okay, that's what I thought. Why do you think the test should always be skipped on SQLite as opposed to making the test work also for non-in-memory SQLite? It seems like making it work would be the better outcome since it would cover more scenarios where the test makes sense.

Agreed, making the test work would be better, but I'm sure how to do this. I would be happy to review a patch, if you have an idea.

comment:6 Changed 3 years ago by Chris Jerdonek

Agreed, thank you. I have some ideas, but not 100% sure it will work out.

comment:7 Changed 3 years ago by Chris Jerdonek

Okay, I came up with a solution for getting the test to work with non-in-memory SQLite. The main idea is to use TransactionTestCase instead of TestCase.

comment:8 Changed 3 years ago by Chris Jerdonek

Has patch: set

comment:9 Changed 3 years ago by Mariusz Felisiak

Owner: changed from nobody to Chris Jerdonek
Status: newassigned
Triage Stage: AcceptedReady for checkin

comment:10 Changed 3 years ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 5c4c3e2d:

Fixed #32445 -- Fixed LiveServerThreadTest.test_closes_connections() for non-in-memory database on SQLite.

Note: See TracTickets for help on using tickets.
Back to Top