-
Notifications
You must be signed in to change notification settings - Fork 1k
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 mango tests using custom db name #5341
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 |
---|---|---|
|
@@ -80,10 +80,7 @@ def join(self): | |
|
||
|
||
class Database(object): | ||
def __init__( | ||
self, | ||
dbname, | ||
): | ||
def __init__(self, dbname): | ||
self.dbname = dbname | ||
self.sess = requests.session() | ||
self.sess.auth = (COUCH_USER, COUCH_PASS) | ||
|
@@ -107,24 +104,19 @@ def create(self, q=1, n=1, partitioned=False): | |
|
||
def delete(self): | ||
r = self.sess.delete(self.url) | ||
r.raise_for_status() | ||
|
||
def recreate(self): | ||
NUM_TRIES = 10 | ||
|
||
for k in range(NUM_TRIES): | ||
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. Tried many times, |
||
r = self.sess.get(self.url) | ||
if r.status_code == 200: | ||
db_info = r.json() | ||
docs = db_info["doc_count"] + db_info["doc_del_count"] | ||
if docs == 0: | ||
# db exists and it is empty -- exit condition is met | ||
return | ||
self.delete() | ||
self.create() | ||
time.sleep(k * 0.1) | ||
raise Exception( | ||
"Failed to recreate the database after {} tries".format(NUM_TRIES) | ||
) | ||
r = self.sess.get(self.url) | ||
if r.status_code == 200: | ||
db_info = r.json() | ||
docs = db_info["doc_count"] + db_info["doc_del_count"] | ||
if docs == 0: | ||
# db is not in use, no need to recreate | ||
return | ||
self.delete() | ||
self.create() | ||
self.recreate() | ||
|
||
def save_doc(self, doc): | ||
self.save_docs([doc]) | ||
|
@@ -356,8 +348,21 @@ def tearDownClass(klass): | |
if clean_up_dbs(): | ||
klass.db.delete() | ||
|
||
def setUp(self): | ||
self.db = self.__class__.db | ||
def setUp(self, db_per_test=False, partitioned=False): | ||
if db_per_test: | ||
self.db = Database(random_db_name()) | ||
self.db.create(q=1, n=1, partitioned=partitioned) | ||
self.db_per_test = db_per_test | ||
else: | ||
self.db = self.__class__.db | ||
|
||
def tearDown(self): | ||
if ( | ||
hasattr(self, "db_per_test") | ||
and self.__getattribute__("db_per_test") | ||
and clean_up_dbs() | ||
): | ||
self.db.delete() | ||
|
||
|
||
class UserDocsTests(DbPerClass): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What does
-F
buy for us? The Mango tests are quick to run, and sometimes perhaps it is good to see if there are other errors besides the one that failed the whole run.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.
While working on this, I even changed
unittest.cfg
to run16-index-selectors-test.py
only. Because I keep getting 500 errors due to this test file. Different combinations of test cases will result in the same failure message but fail on different test cases. 0.85 sec vs 50 sec to run the entire test suite.-F, --failfast
allows us to identify the issue quickly, speed up the feedback loop, and make debugging easier.