Skip to content

RecordUpdateListener now uses update_records instead of update_record#419

Merged
bdraco merged 1 commit into
python-zeroconf:masterfrom
bdraco:update_records
Jun 7, 2021
Merged

RecordUpdateListener now uses update_records instead of update_record#419
bdraco merged 1 commit into
python-zeroconf:masterfrom
bdraco:update_records

Conversation

@bdraco

@bdraco bdraco commented Jun 2, 2021

Copy link
Copy Markdown
Member

This allows the listener to receive all the records that have
been updated in a single transaction such as a packet or
cache expiry.

update_record has been deprecated in favor of update_records
A compatibility shim exists to ensure classes that use
RecordUpdateListener as a base class continue to have
update_record called, however they should be updated
as soon as possible.

A new method update_records_complete is now called on each
listener when all listeners have completed processing updates
and the cache has been updated. This allows ServiceBrowsers
to delay calling handlers until they are sure the cache
has been updated as its a common pattern to call for
ServiceInfo when a ServiceBrowser handler fires.

Fixes #416
Fixes #431
Closes #418
Fixes #456
Closes #457

@bdraco bdraco force-pushed the update_records branch 6 times, most recently from a16a69f to b635880 Compare June 2, 2021 19:36
@codecov-commenter

codecov-commenter commented Jun 2, 2021

Copy link
Copy Markdown

Codecov Report

Merging #419 (3371d8b) into master (b853413) will increase coverage by 0.20%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #419      +/-   ##
==========================================
+ Coverage   95.62%   95.83%   +0.20%     
==========================================
  Files           4        4              
  Lines        3338     3385      +47     
  Branches      402      407       +5     
==========================================
+ Hits         3192     3244      +52     
+ Misses         89       84       -5     
  Partials       57       57              
Impacted Files Coverage Δ
zeroconf/__init__.py 92.44% <100.00%> (+0.42%) ⬆️
zeroconf/test.py 98.90% <100.00%> (+0.01%) ⬆️
zeroconf/test_asyncio.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b853413...3371d8b. Read the comment docs.

@bdraco

bdraco commented Jun 2, 2021

Copy link
Copy Markdown
Member Author

There is still a race condition since we update the cache after we call update_records

We need a way to tell the ServiceBrowser to process pending events after the cache has been updated

@bdraco bdraco force-pushed the update_records branch 2 times, most recently from 049cb13 to 4a6d5de Compare June 2, 2021 20:50
Comment thread zeroconf/__init__.py Outdated
@bdraco bdraco force-pushed the update_records branch 6 times, most recently from 5203b2c to 562c6ad Compare June 2, 2021 21:22
@bdraco

bdraco commented Jun 2, 2021

Copy link
Copy Markdown
Member Author
  • add coverage to make sure the backwards compat works as expected for a sample ServiceListener

@bdraco bdraco force-pushed the update_records branch 8 times, most recently from 0bf5150 to 14b4e4d Compare June 2, 2021 23:26
@bdraco

bdraco commented Jun 3, 2021

Copy link
Copy Markdown
Member Author

This one needs another set of 👀

I'm going to try to break out the simpler changes into smaller chunks though first to reduce the size of the review

bdraco added a commit to bdraco/python-zeroconf that referenced this pull request Jun 4, 2021
- Prepares for the change from update_record to update_records in python-zeroconf#419
bdraco added a commit to bdraco/python-zeroconf that referenced this pull request Jun 5, 2021
bdraco added a commit that referenced this pull request Jun 5, 2021
@bdraco bdraco force-pushed the update_records branch 4 times, most recently from 4a9de0f to c7f919a Compare June 6, 2021 03:06
bdraco added a commit to bdraco/python-zeroconf that referenced this pull request Jun 6, 2021
- This change is not enough to remove the too-many-branches
  pylint disable, however when combined with python-zeroconf#419 it should
  no longer be needed
bdraco added a commit that referenced this pull request Jun 6, 2021
- Adds `add_records` and `remove_records` to `DNSCache` to
  permit multiple records to be added or removed in one call

- This change is not enough to remove the too-many-branches
  pylint disable, however when combined with #419 it should
  no longer be needed
@bdraco bdraco force-pushed the update_records branch 4 times, most recently from b6a07b3 to 3371d8b Compare June 6, 2021 09:30
@bdraco

bdraco commented Jun 6, 2021

Copy link
Copy Markdown
Member Author

May be possible to merge ServiceInfo changes separately and the one line back compat test since they should be forward/back compat

Comment thread zeroconf/__init__.py Outdated
@bdraco

bdraco commented Jun 6, 2021

Copy link
Copy Markdown
Member Author

I was initially worried about this change, but it turns out the problem is actually #476 so this should be good to go once the other issue is fixed.

This allows the listener to receive all the records that have
been updated in a single transaction such as a packet or
cache expiry.

`update_record` has been deprecated in favor of `update_records`
A compatibility shim exists to ensure classes that use
`RecordUpdateListener` as a base class continue to have
`update_record` called, however they should be updated
as soon as possible.

A new method `update_records_complete` is now called on each
listener when all listeners have completed processing updates
and the cache has been updated. This allows ServiceBrowsers
to delay calling handlers until they are sure the cache
has been updated as its a common pattern to call for
ServiceInfo when a ServiceBrowser handler fires.
@bdraco

bdraco commented Jun 7, 2021

Copy link
Copy Markdown
Member Author

I think we can turn on some more of the PyPy disabled tests as they should be less flakey after this and the other synchronization fixes that I just merged

@bdraco bdraco merged commit 0a69aa0 into python-zeroconf:master Jun 7, 2021
@bdraco bdraco deleted the update_records branch June 7, 2021 00:18
bdraco added a commit to bdraco/python-zeroconf that referenced this pull request Jun 7, 2021
- The root cause of the test failing should be fixed by python-zeroconf#419
  and python-zeroconf#477
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants