-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix deadlock when connection fails #97
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,16 @@ def test_directory_notfound(self): | |
with self.assertRaises(RuntimeError): | ||
SqliteDict(filename=os.path.join(folder, 'nonexistent')) | ||
|
||
def test_failed_connection(self): | ||
""" Verify error when connecting does not deadlock """ | ||
# given: a non-existent directory, | ||
folder = tempfile.mkdtemp(prefix='sqlitedict-test') | ||
# os.rmdir(folder) | ||
# exercise, | ||
with self.assertRaises(RuntimeError): | ||
SqliteDict(filename=folder) | ||
os.rmdir(folder) | ||
|
||
def test_commit_nonblocking(self): | ||
"""Coverage for non-blocking commit.""" | ||
# given, | ||
|
@@ -133,8 +143,8 @@ def attempt_clear(): | |
def attempt_terminate(): | ||
readonly_db.terminate() | ||
|
||
attempt_funcs = [attempt_write, | ||
attempt_update, | ||
attempt_funcs = [attempt_write, | ||
attempt_update, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hanging indent please (not vertical). |
||
attempt_delete, | ||
attempt_clear, | ||
attempt_terminate] | ||
|
@@ -159,7 +169,7 @@ def test_irregular_tablenames(self): | |
|
||
with self.assertRaisesRegexp(ValueError, r'^Invalid tablename '): | ||
SqliteDict(':memory:', '"') | ||
|
||
def test_overwrite_using_flag_w(self): | ||
"""Re-opening of a database with flag='w' destroys only the target table.""" | ||
# given, | ||
|
@@ -277,6 +287,6 @@ def test_tablenames(self): | |
self.assertEqual(SqliteDict.get_tablenames(fname), ['table1']) | ||
with SqliteDict(fname,tablename='table2') as db2: | ||
self.assertEqual(SqliteDict.get_tablenames(fname), ['table1','table2']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mpenkov can we set up an automated git hook to check for these things? Code with trailing whitespace should never have been merged. |
||
|
||
tablenames = SqliteDict.get_tablenames('tests/db/tablenames-test-2.sqlite') | ||
self.assertEqual(tablenames, ['table1','table2']) | ||
self.assertEqual(tablenames, ['table1','table2']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it better to raise RuntimeError than sqlite3.OperationalError here?
In my opinion, it's not a good idea because it hides useful information from the user.