Skip to content

Commit 0e73ba2

Browse files
authored
Revert "chore: add get_percentage_remaining_ttl helper to DNSRecord (#1343)"
This reverts commit 7a24b88.
1 parent 7a24b88 commit 0e73ba2

File tree

3 files changed

+4
-23
lines changed

3 files changed

+4
-23
lines changed

src/zeroconf/_dns.pxd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ cdef class DNSRecord(DNSEntry):
5454

5555
cpdef get_remaining_ttl(self, double now)
5656

57-
cpdef unsigned int get_percentage_remaining_ttl(self, double now)
58-
5957
cpdef double get_expiration_time(self, cython.uint percent)
6058

6159
cpdef bint is_expired(self, double now)

src/zeroconf/_dns.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,6 @@ def get_expiration_time(self, percent: _int) -> float:
193193
by a certain percentage."""
194194
return self.created + (percent * self.ttl * 10)
195195

196-
def get_percentage_remaining_ttl(self, now: _float) -> _int:
197-
"""Returns the percentage remaining of the ttl between 0-100."""
198-
remain = (self.created + (_EXPIRE_FULL_TIME_MS * self.ttl) - now) / self.ttl / 10
199-
return 0 if remain <= 0 else round(remain)
200-
201196
# TODO: Switch to just int here
202197
def get_remaining_ttl(self, now: _float) -> Union[int, float]:
203198
"""Returns the remaining TTL in seconds."""

tests/test_dns.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
import os
88
import socket
9+
import time
910
import unittest
1011
import unittest.mock
1112

@@ -85,32 +86,19 @@ def test_dns_record_abc(self):
8586
record.write(None) # type: ignore[arg-type]
8687

8788
def test_dns_record_reset_ttl(self):
88-
start = r.current_time_millis()
89-
record = r.DNSRecord(
90-
'irrelevant', const._TYPE_SRV, const._CLASS_IN, const._DNS_HOST_TTL, created=start
91-
)
92-
later = start + 1000
93-
record2 = r.DNSRecord(
94-
'irrelevant', const._TYPE_SRV, const._CLASS_IN, const._DNS_HOST_TTL, created=later
95-
)
89+
record = r.DNSRecord('irrelevant', const._TYPE_SRV, const._CLASS_IN, const._DNS_HOST_TTL)
90+
time.sleep(1)
91+
record2 = r.DNSRecord('irrelevant', const._TYPE_SRV, const._CLASS_IN, const._DNS_HOST_TTL)
9692
now = r.current_time_millis()
9793

9894
assert record.created != record2.created
9995
assert record.get_remaining_ttl(now) != record2.get_remaining_ttl(now)
100-
assert record.get_percentage_remaining_ttl(now) != record2.get_percentage_remaining_ttl(now)
101-
assert record2.get_percentage_remaining_ttl(later) == 100
102-
assert record2.get_percentage_remaining_ttl(later + (const._DNS_HOST_TTL * 1000 / 2)) == 50
10396

10497
record.reset_ttl(record2)
10598

10699
assert record.ttl == record2.ttl
107100
assert record.created == record2.created
108101
assert record.get_remaining_ttl(now) == record2.get_remaining_ttl(now)
109-
assert record.get_percentage_remaining_ttl(now) == record2.get_percentage_remaining_ttl(now)
110-
assert record.get_percentage_remaining_ttl(later) == 100
111-
assert record2.get_percentage_remaining_ttl(later) == 100
112-
assert record.get_percentage_remaining_ttl(later + (const._DNS_HOST_TTL * 1000 / 2)) == 50
113-
assert record2.get_percentage_remaining_ttl(later + (const._DNS_HOST_TTL * 1000 / 2)) == 50
114102

115103
def test_service_info_dunder(self):
116104
type_ = "_test-srvc-type._tcp.local."

0 commit comments

Comments
 (0)