Skip to content
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

Increase test scope of MariaDB + PostgreSQL tests #87019

Merged
merged 13 commits into from
Feb 13, 2023

Conversation

emontnemery
Copy link
Contributor

@emontnemery emontnemery commented Jan 31, 2023

Proposed change

Increase test scope of the MariaDB CI job

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant home-assistant bot added cla-signed small-pr PRs with less than 30 lines. labels Jan 31, 2023
@bdraco bdraco requested a review from a team as a code owner January 31, 2023 19:23
@bdraco
Copy link
Member

bdraco commented Jan 31, 2023

Cherry-picked the test fixes from #86436

This should pass now

@bdraco bdraco closed this Jan 31, 2023
@bdraco bdraco reopened this Jan 31, 2023
@bdraco
Copy link
Member

bdraco commented Jan 31, 2023

Looks like everything is good except for FAILED tests/components/logbook/test_websocket_api.py::test_recorder_is_far_behind - AssertionError: assert [{'domain': '...97063.376577}] == []

This appears to be a race order issue (not a production problem) in the test

@emontnemery emontnemery closed this Feb 9, 2023
@emontnemery emontnemery reopened this Feb 9, 2023
@frenck frenck marked this pull request as draft February 9, 2023 07:41
@emontnemery emontnemery changed the title Increase test scope of mariadb tests Increase test scope of MariaDB + PostgreSQL tests Feb 9, 2023
@emontnemery emontnemery marked this pull request as ready for review February 9, 2023 07:45
@epenet
Copy link
Contributor

epenet commented Feb 9, 2023

Should we adjust .core_files.yaml to match? #87764

@bdraco bdraco marked this pull request as draft February 9, 2023 09:28
@bdraco
Copy link
Member

bdraco commented Feb 9, 2023

There are still a few postgresql history/stats tests that need the same fixes as the recorder versions of them

Copy link
Contributor

@epenet epenet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just marking this as requested changes - we don't want to forget to adjust .core_files.yaml and end up with unexpected issues in CI.

@bdraco
Copy link
Member

bdraco commented Feb 10, 2023

Was going to work on this today but ended up doing another pass on statistics since I thought I couldn't optimize it anymore and than I came up with an idea... #87859 so I'll pick this up this weekend instead

@bdraco
Copy link
Member

bdraco commented Feb 13, 2023

postgres has two issues

  1. delete duplicate stats is taking too long
  2. the stats history is returning integer values (cannot replicate locally though)
hass=# select * from states limit 5;
 state_id |        entity_id        | state  | attributes | event_id | last_changed | last_updated | old_state_id | attributes_id |         context_id         | context_user_id | context_parent_id | origin_idx |  last_updated_ts  | last_changed_ts 
----------+-------------------------+--------+------------+----------+--------------+--------------+--------------+---------------+----------------------------+-----------------+-------------------+------------+-------------------+-----------------
   464804 | sensor.power_sensor_899 | 241565 |            |          |              |              |       463803 |           904 | 01GQXC3CGBWVJB9NS0KB494KTN |                 |                   |          0 | 1674949276.171689 |                
   464805 | sensor.power_sensor_900 | 394504 |            |          |              |              |       463804 |           905 | 01GQXC3CGB52ACC4FKWF0XARD4 |                 |                   |          0 | 1674949276.171708 |               

@bdraco
Copy link
Member

bdraco commented Feb 13, 2023

Its definitely creating the columns correctly

     1230 | lock.downstairs_guest_sliding_door                                          | locked                           |            |          |              |  1676306942.78344 |              | 1676306946.984045 |         1105 |          1097 | 01GS5TW6X8NVNW11GRPEKDCV5W |                 |                   |          0
     1231 | lock.garage_den_door                                                        | locked                           |            |          |              | 1676306942.783529 |              | 1676306949.177022 |         1109 |          1098 | 01GS5TW91S8REPEA0E00Y5D68W |                 |                   |          0
     1232 | lock.den_door                                                               | unlocked                         |            |          |              | 1676306942.783509 |              | 1676306952.221956 |         1108 |          1146 | 01GS5TWC0X19ADB35KPJK1J12C |                 |                   |          0
     1233 | lock.garage_main_entry_door                                                 | locked                           |            |          |              | 1676306942.783467 |              | 1676306952.468899 |         1106 |          1147 | 01GS5TWC8MSP

@bdraco
Copy link
Member

bdraco commented Feb 13, 2023

but the raw data all comes back with .0

[('sensor.test1', '-10', None, 1630472405.0, None, '{"device_class":null,"state_class":"measurement","unit_of_measurement":"%"}'),
 ('sensor.test1', '15', None, 1630472455.0, None, '{"device_class":null,"state_class":"measurement","unit_of_measurement":"%"}'),
 ('sensor.test1', '30', None, 1630472655.0, None, '{"device_class":null,"state_class":"measurement","unit_of_measurement":"%"}'),
 ('sensor.test1', '-10', None, 1630472705.0, None, '{"device_class":null,"state_class":"measurement","unit_of_measurement":"%"}'),
 ('sensor.test1', '15', None, 1630472755.0, None, '{"device_class":null,"state_class":"measurement","unit_of_measurement":"%"}'),
 ('sensor.test1', '30', None, 1630472955.0, None, '{"device_class":null,"state_class":"measurement","unit_of_measurement":"%"}'),
 ('sensor.test1', '-10', None, 1630473005.0, None, '{"device_class":null,"state_class":"measurement","unit_of_measurement":"%"}'),
 ('sensor.test1', '15', None, 1630473055.0, None, '{"device_class":null,"state_class":"measurement","unit_of_measurement":"%"}'),
 ('sensor.test1', '30', None, 1630473255.0, None, '{"device_class":null,"state_class":"measurement","unit_of_measurement":"%"}'),

@bdraco
Copy link
Member

bdraco commented Feb 13, 2023

CREATE TABLE states (
	state_id INTEGER GENERATED BY DEFAULT AS IDENTITY, 
	entity_id VARCHAR(255), 
	state VARCHAR(255), 
	attributes TEXT, 
	event_id INTEGER, 
	last_changed TIMESTAMP WITH TIME ZONE, 
	last_changed_ts DOUBLE PRECISION, 
	last_updated TIMESTAMP WITH TIME ZONE, 
	last_updated_ts DOUBLE PRECISION, 
	old_state_id INTEGER, 
	attributes_id INTEGER, 
	context_id VARCHAR(36), 
	context_user_id VARCHAR(36), 
	context_parent_id VARCHAR(36), 
	origin_idx SMALLINT, 
	PRIMARY KEY (state_id), 
	FOREIGN KEY(event_id) REFERENCES events (event_id) ON DELETE CASCADE, 
	FOREIGN KEY(old_state_id) REFERENCES states (state_id), 
	FOREIGN KEY(attributes_id) REFERENCES state_attributes (attributes_id)
)

Its being created correctly

@bdraco
Copy link
Member

bdraco commented Feb 13, 2023

 ('sensor.test4', '22.75', None, 1630479060.0, None, '{"device_class":null,"state_class":"total","unit_of_measurement":"EUR"}'),
 ('sensor.test4', '22.5', None, 1630479060.0, None, '{"device_class":null,"state_class":"total","unit_of_measurement":"EUR"}'),
 ('sensor.test4', '23', None, 1630479300.0, None, '{"device_class":null,"state_class":"total","unit_of_measurement":"EUR"}'),
 ('sensor.test4', '23.75', None, 1630479360.0, None, '{"device_class":null,"state_class":"total","unit_of_measurement":"EUR"}'),
 ('sensor.test4', '23.5', None, 1630479360.0, None, '{"device_class":null,"state_class":"total","unit_of_measurement":"EUR"}')]

some other data it out of order as well for postgresql.

but only sensor.test4

@bdraco
Copy link
Member

bdraco commented Feb 13, 2023

they are being recorded at the same time

 ('sensor.test4', '23.75', None, 1630479360.0, None, '{"device_class":null,"state_class":"total","unit_of_measurement":"EUR"}'),
 ('sensor.test4', '23.5', None, 1630479360.0, None, '{"device_class":null,"state_class":"total","unit_of_measurement":"EUR"}')]

@bdraco
Copy link
Member

bdraco commented Feb 13, 2023

DEBUG:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=sensor.test4, old_state=<state sensor.test4=0; device_class=None, state_class=total, unit_of_measurement=EUR @ 2021-08-31T23:00:00-06:00>, new_state=<state sensor.test4=0.5; device_class=None, state_class=total, unit_of_measurement=EUR @ 2021-08-31T23:01:00-06:00>>
DEBUG:homeassistant.core:Bus:Handling <Event state_changed[L]: entity_id=sensor.test4, old_state=<state sensor.test4=0.5; device_class=None, state_class=total, unit_of_measurement=EUR @ 2021-08-31T23:01:00-06:00>, new_state=<state sensor.test4=0.75; device_class=None, state_class=total, unit_of_measurement=EUR @ 2021-08-31T23:01:00-06:00>>

So not the database

@@ -3094,7 +3094,7 @@ def _sum(seq, last_state, last_sum):
sum_attributes,
seq[j : j + 1],
)
start_meter = start + timedelta(minutes=1)
start_meter += timedelta(minutes=1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug in the test, it was inserting rows with the same timestamp down to the microsecond so selecting them back resulted in an indeterminate order

@bdraco
Copy link
Member

bdraco commented Feb 13, 2023

There were no functional changes here. So it looks like our code is good, we just needed to fix some tests 👍

@bdraco bdraco marked this pull request as ready for review February 13, 2023 17:33
@bdraco bdraco requested a review from epenet February 13, 2023 17:37
Copy link
Contributor

@epenet epenet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@bdraco bdraco merged commit 4ca0a24 into dev Feb 13, 2023
@bdraco bdraco deleted the mariadb_tests_increase_scope branch February 13, 2023 21:58
@bdraco
Copy link
Member

bdraco commented Feb 13, 2023

Thanks

@github-actions github-actions bot locked and limited conversation to collaborators Feb 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants