-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 tests that expect DBMAsync to put thread to sleep in sync mode #17847
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
The |
3 similar comments
The |
The |
The |
0135858
to
5d61b1e
Compare
The |
sqlserver/tests/test_statements.py
Outdated
@@ -311,10 +314,12 @@ def test_statement_metrics_and_plans( | |||
# 2) load the test queries into the StatementMetrics state | |||
# 3) emit the query metrics based on the diff of current and last state | |||
dd_run_check(check) | |||
time.sleep(2) |
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.
tag sleep
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 do we need sleep here? I thought we need either sleep or a close to zero collection interval but not both
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.
I don't have an answer to this question yet.
What I know is that only in this test collection interval was set to 2s instead of 0.1 as in other tests.
link - https://github.com/DataDog/integrations-core/blob/13b7646c076108d76194c67e80c57515564fd489/sqlserver/tests/test_statements.py#L305
Also, if I reset my change in the base package and run this test with 0.1 collection interval it fails
branch - bk/test-sleep-DBMON-4188 . Which means that the sleep produced by DBMAsync was always needed for test to function.
I'll take a look at it when I have more time. Probably, tmrw morning. But I am confident that we can move forward with this change.
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.
if sleep
is needed regardless of the collection interval, can we just add sleep without setting the collection interval to 0.000001 to minimize the changes?
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.
Adding a bunch of sleeps all over the place seems like a recipe for disaster (how will people know to do this going forward??). It also feels like setting a very low collection interval is hacky / prone to future flakey-ness / not straightforward why we need it. I would just add a run_sync_blocking
function or something like that to the DBMAsync job, which has the old behavior and then update the tests to use that. This is a bit weird, because we are adding production code that will only be used by tests, but we do this in plenty of places in the backend and this seems like a fair trade off in order to have reliable tests going forward. We just need to make sure this function is documented well.
The |
postgres/tests/test_statements.py
Outdated
@@ -87,7 +88,7 @@ def test_statement_metrics_multiple_pgss_rows_single_query_signature( | |||
# don't need samples for this test | |||
dbm_instance['query_samples'] = {'enabled': False} | |||
dbm_instance['query_activity'] = {'enabled': False} | |||
dbm_instance['query_metrics'] = {'enabled': True, 'run_sync': True, 'incremental_query_metrics': True} | |||
dbm_instance['incremental_query_metrics'] = True |
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.
this looks wrong. why is incremental_query_metrics
moved to the top level?
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.
oh yeah should be
dbm_instance['query_metrics']['incremental_query_metrics'] = True
thx
sqlserver/tests/test_statements.py
Outdated
@@ -311,10 +314,12 @@ def test_statement_metrics_and_plans( | |||
# 2) load the test queries into the StatementMetrics state | |||
# 3) emit the query metrics based on the diff of current and last state | |||
dd_run_check(check) | |||
time.sleep(2) |
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 do we need sleep here? I thought we need either sleep or a close to zero collection interval but not both
@@ -30,15 +30,23 @@ | |||
# depend on a default schema being set on the connection | |||
DEFAULT_FQ_SUCCESS_QUERY = "SELECT * FROM information_schema.TABLES" | |||
|
|||
CLOSE_TO_ZERO_INTERVAL = 0.0000001 |
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.
Is there a difference between 0.0000001
and 0
? Why not just zero?
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.
0 doesn't work cause we divide by 0 when we pass this argument to DBMAsync.
So, in code there is a check that will revert 0 to default_collection_interval.
like https://github.com/DataDog/integrations-core/blob/13b7646c076108d76194c67e80c57515564fd489/sqlserver/datadog_checks/sqlserver/statements.py#L212 .
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.
Got it, thanks!
What does this PR do?
Fixes tests that relied on main thread being put to sleep by DBMAsync.
Tests started to fail after this PR - #17716 got submitted.
Review checklist (to be filled by reviewers)
qa/skip-qa
label if the PR doesn't need to be tested during QA.backport/<branch-name>
label to the PR and it will automatically open a backport PR once this one is merged