|
6 | 6 | import logging
|
7 | 7 | import os
|
8 | 8 | import socket
|
9 |
| -import time |
10 | 9 | import unittest
|
11 | 10 | import unittest.mock
|
12 | 11 |
|
@@ -86,19 +85,32 @@ def test_dns_record_abc(self):
|
86 | 85 | record.write(None) # type: ignore[arg-type]
|
87 | 86 |
|
88 | 87 | def test_dns_record_reset_ttl(self):
|
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) |
| 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 | + ) |
92 | 96 | now = r.current_time_millis()
|
93 | 97 |
|
94 | 98 | assert record.created != record2.created
|
95 | 99 | 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 |
96 | 103 |
|
97 | 104 | record.reset_ttl(record2)
|
98 | 105 |
|
99 | 106 | assert record.ttl == record2.ttl
|
100 | 107 | assert record.created == record2.created
|
101 | 108 | 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 |
102 | 114 |
|
103 | 115 | def test_service_info_dunder(self):
|
104 | 116 | type_ = "_test-srvc-type._tcp.local."
|
|
0 commit comments