This repository has been archived by the owner on Jan 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating a restart function for storage classes to fix broken or lost…
… database connections
- Loading branch information
rich-hart
committed
Feb 12, 2015
1 parent
737a36c
commit 3389885
Showing
6 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2799,6 +2799,33 @@ def test_user_contents_hide_documents_inside_binders(self): | |
}, | ||
}) | ||
|
||
def test_db_restart(self): | ||
''' | ||
Test to see if the database resets itself after a broken | ||
connection | ||
''' | ||
import psycopg2 | ||
from ..storage import storage | ||
|
||
self.addCleanup(setattr, storage, 'conn', | ||
psycopg2.connect(storage.conn.dsn)) | ||
|
||
storage.conn.close() | ||
|
||
response = self.testapp.post_json( | ||
'/users/contents', | ||
{'title': u'My document タイトル'}, | ||
status=503, | ||
expect_errors=True) | ||
self.assertEqual(response.status, '503 Service Unavailable') | ||
|
||
response = self.testapp.post_json( | ||
'/users/contents', | ||
{'title': u'My document タイトル'}, | ||
status=201, | ||
expect_errors=True) | ||
self.assertEqual(response.status, '201 Created') | ||
|
||
def test_service_unavailable_response(self): | ||
''' | ||
Test service unavailable response when a request is made during a | ||
|
@@ -2819,25 +2846,33 @@ def test_service_unavailable_response(self): | |
expect_errors=True) | ||
self.assertEqual(response.status, '503 Service Unavailable') | ||
|
||
storage.conn.close() | ||
|
||
response = self.testapp.get( | ||
'/resources/1234abcde', | ||
status=503, | ||
expect_errors=True) | ||
self.assertEqual(response.status, '503 Service Unavailable') | ||
|
||
storage.conn.close() | ||
|
||
response = self.testapp.put_json( | ||
'/contents/[email protected]', | ||
{}, | ||
status=503, | ||
expect_errors=True) | ||
self.assertEqual(response.status, '503 Service Unavailable') | ||
|
||
storage.conn.close() | ||
|
||
response = self.testapp.get( | ||
'/search', | ||
status=503, | ||
expect_errors=True) | ||
self.assertEqual(response.status, '503 Service Unavailable') | ||
|
||
storage.conn.close() | ||
|
||
response = self.testapp.delete( | ||
'/contents/{}@draft'.format(id), | ||
status=503, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters