Conversation
pensivebrian
left a comment
There was a problem hiding this comment.
Couple of changes related to retry logic.
pensivebrian
left a comment
There was a problem hiding this comment.
Approved with a suggestion to move the master check to the calling function
|
@pensivebrian I've made the suggested changes, please let me know your thoughts. We still need to fix the known issue in the Special module but I can submit that in a separate PR. |
pensivebrian
left a comment
There was a problem hiding this comment.
We need to be able to run against on-premise databases as well as azure.
pensivebrian
left a comment
There was a problem hiding this comment.
We should fail the test with a clear error that database creation failed.
| shutdown(client) | ||
|
|
||
| # cleanup db just in case, then raise exception | ||
| clean_up_test_db(test_db_name) |
There was a problem hiding this comment.
clean_up_test_db [](start = 4, length = 16)
This will most likely fail, so let's wrap in a try catch
|
|
||
| # cleanup db just in case, then raise exception | ||
| clean_up_test_db(test_db_name) | ||
| raise AssertionError("DB creation failed.") |
There was a problem hiding this comment.
Can we put the failing exception in the assert message - this way we don't have look at logs
| if is_create_error or create_db_status == 'FAILED': | ||
| # log warning to console and cleanup db | ||
| warnings.warn('Test DB create failed with error: {0}'.format(status)) | ||
| clean_up_test_db(test_db_name) |
There was a problem hiding this comment.
clean_up_test_db [](start = 16, length = 16)
I don't think we should we should try an cleanup here. Let's let the caller perform the cleanup.
| shutdown(client) | ||
| return test_db_name | ||
|
|
||
| shutdown(client) |
There was a problem hiding this comment.
Can we put one shutdown call in a finally block?
pensivebrian
left a comment
There was a problem hiding this comment.
Why are we refactoring the globalization tests?
| u'ꇽꇾꇿꈀꈁꈂꈃꈄꈅꈆꈇꈈꈉ' | ||
| ), | ||
| 'zang': ( | ||
| # zang |
There was a problem hiding this comment.
We remove the language key? With the key, you could narrow down the failure by logging the language
There was a problem hiding this comment.
That's a good point, I can use a tuple here for the test data.
| self.run_charset_validation('zang') | ||
|
|
||
| def run_charset_validation(self, charset): | ||
| @pytest.mark.parametrize("charset", test_charset_data) |
There was a problem hiding this comment.
Using pytest, you no longer get integrated tests in vscode. Is there a reason why we're change this?
There was a problem hiding this comment.
I don't believe that's true about Pytest anymore (source).
Pytest provides a lot of benefits over unittest, especially in readability of tests. In this particular instance we're using parametrized tests, enabling us to define one test method for multiple tests. This allowed us to remove redundant code.
There was a problem hiding this comment.
pytest doesn't work well with parameterized tests. Gene, the engineer before you, ported all pytests to be unittest tests due to this issue. I'd prefer we just leave them as is for now.
There was a problem hiding this comment.
That's very interesting—truthfully I've already ported parametrized tests for 4 other test files (interactive, non_interactive, mssqlclient, multiline). Also looks like our original merge uses parametrized tests for ctes and parseutils.
I'll defer to your judgement if you still prefer to remove this, but in my experience it works great.
There was a problem hiding this comment.
As long as it easy to debug a particular language, without having to others, I'm okay with it I guess. What's the command line to run pytest with a specific parameter set?
There was a problem hiding this comment.
Yes there's still the ability to log which language fails. I'm making a new commit to accommodate this.
I'm not positive on how to call a test from the command line with just a single parameter. This StackOverflow post may show it's possible. I usually comment out the other parameters and call pytest test_mod.py::TestClass::test_method.
There was a problem hiding this comment.
So that's what I want to avoid - having to comment out tests to run a test.
There was a problem hiding this comment.
I've validated you can test for a single parameter using the -k flag, followed by a string which matches the parameter to test.
|
I just added another commit to improve reliability of our tests:
|
|
Another change today to improve DB create reliability and code quality:
|
pensivebrian
left a comment
There was a problem hiding this comment.
I think the PR is becoming too complicated. I can tell what's stabilization and what is pytest migration. Can we just fix the create database issue, an address pytest some other time?
| """ | ||
| @staticmethod | ||
| @pytest.fixture(scope='module') | ||
| def test_db(): |
There was a problem hiding this comment.
creating an iterator for a single element to injecting the client seems overkill. Can we just have a setup method with creates the client?
There was a problem hiding this comment.
I'm confused, I don't believe this is an iterator.
We're using Pytest fixtures for tests which were already using this behavior, I was just trying to reduce redundant code.
| assert len(rows) >= min_rows_expected | ||
| assert len(col) == cols_expected | ||
|
|
||
| if __name__ == u'__main__': |
There was a problem hiding this comment.
These main's were useful to run files :(
There was a problem hiding this comment.
I can put this back!
I can simplify this a bit—unfortunately, most of the code changes were about ensuring tests can run off of the master DB (which because a requirement now that we call However, I did refactor things a little in |
bbcfc71 to
e347b5b
Compare
| warnings.warn('Test DB create failed with error: {0}'.format(status)) | ||
| count += 1 | ||
| shutdown(client) | ||
| if is_create_error: |
There was a problem hiding this comment.
This will prevent the retry logic from ever running.
| @@ -122,6 +118,10 @@ def create_test_db(): | |||
| raise AssertionError("Database creation failed: retry logic for SQL " \ | |||
There was a problem hiding this comment.
Can we surface the status error message in the failure here as well?
pensivebrian
left a comment
There was a problem hiding this comment.
One comment to update the assertion message.
|
@pensivebrian I made a small tweak to our helper method to return an error message with the state response in the form of a tuple. |
575e39b to
0ef1d8c
Compare
0ef1d8c to
616829c
Compare
Closes #280.
This PR introduces retry logic to check the status of a db creation using
sys.dm_operation_status.