|
1 | 1 | """Benchmark for DNSOutgoing.""" |
2 | 2 |
|
3 | | -import socket |
4 | | - |
5 | 3 | from pytest_codspeed import BenchmarkFixture |
6 | 4 |
|
7 | | -from zeroconf import DNSAddress, DNSOutgoing, DNSService, DNSText, const |
8 | 5 | from zeroconf._protocol.outgoing import State |
9 | 6 |
|
10 | | - |
11 | | -def generate_packets() -> DNSOutgoing: |
12 | | - out = DNSOutgoing(const._FLAGS_QR_RESPONSE | const._FLAGS_AA) |
13 | | - address = socket.inet_pton(socket.AF_INET, "192.168.208.5") |
14 | | - |
15 | | - additionals = [ |
16 | | - { |
17 | | - "name": "HASS Bridge ZJWH FF5137._hap._tcp.local.", |
18 | | - "address": address, |
19 | | - "port": 51832, |
20 | | - "text": b"\x13md=HASS Bridge" |
21 | | - b" ZJWH\x06pv=1.0\x14id=01:6B:30:FF:51:37\x05c#=12\x04s#=1\x04ff=0\x04" |
22 | | - b"ci=2\x04sf=0\x0bsh=L0m/aQ==", |
23 | | - }, |
24 | | - { |
25 | | - "name": "HASS Bridge 3K9A C2582A._hap._tcp.local.", |
26 | | - "address": address, |
27 | | - "port": 51834, |
28 | | - "text": b"\x13md=HASS Bridge" |
29 | | - b" 3K9A\x06pv=1.0\x14id=E2:AA:5B:C2:58:2A\x05c#=12\x04s#=1\x04ff=0\x04" |
30 | | - b"ci=2\x04sf=0\x0bsh=b2CnzQ==", |
31 | | - }, |
32 | | - { |
33 | | - "name": "Master Bed TV CEDB27._hap._tcp.local.", |
34 | | - "address": address, |
35 | | - "port": 51830, |
36 | | - "text": b"\x10md=Master Bed" |
37 | | - b" TV\x06pv=1.0\x14id=9E:B7:44:CE:DB:27\x05c#=18\x04s#=1\x04ff=0\x05" |
38 | | - b"ci=31\x04sf=0\x0bsh=CVj1kw==", |
39 | | - }, |
40 | | - { |
41 | | - "name": "Living Room TV 921B77._hap._tcp.local.", |
42 | | - "address": address, |
43 | | - "port": 51833, |
44 | | - "text": b"\x11md=Living Room" |
45 | | - b" TV\x06pv=1.0\x14id=11:61:E7:92:1B:77\x05c#=17\x04s#=1\x04ff=0\x05" |
46 | | - b"ci=31\x04sf=0\x0bsh=qU77SQ==", |
47 | | - }, |
48 | | - { |
49 | | - "name": "HASS Bridge ZC8X FF413D._hap._tcp.local.", |
50 | | - "address": address, |
51 | | - "port": 51829, |
52 | | - "text": b"\x13md=HASS Bridge" |
53 | | - b" ZC8X\x06pv=1.0\x14id=96:14:45:FF:41:3D\x05c#=12\x04s#=1\x04ff=0\x04" |
54 | | - b"ci=2\x04sf=0\x0bsh=b0QZlg==", |
55 | | - }, |
56 | | - { |
57 | | - "name": "HASS Bridge WLTF 4BE61F._hap._tcp.local.", |
58 | | - "address": address, |
59 | | - "port": 51837, |
60 | | - "text": b"\x13md=HASS Bridge" |
61 | | - b" WLTF\x06pv=1.0\x14id=E0:E7:98:4B:E6:1F\x04c#=2\x04s#=1\x04ff=0\x04" |
62 | | - b"ci=2\x04sf=0\x0bsh=ahAISA==", |
63 | | - }, |
64 | | - { |
65 | | - "name": "FrontdoorCamera 8941D1._hap._tcp.local.", |
66 | | - "address": address, |
67 | | - "port": 54898, |
68 | | - "text": b"\x12md=FrontdoorCamera\x06pv=1.0\x14id=9F:B7:DC:89:41:D1\x04c#=2\x04" |
69 | | - b"s#=1\x04ff=0\x04ci=2\x04sf=0\x0bsh=0+MXmA==", |
70 | | - }, |
71 | | - { |
72 | | - "name": "HASS Bridge W9DN 5B5CC5._hap._tcp.local.", |
73 | | - "address": address, |
74 | | - "port": 51836, |
75 | | - "text": b"\x13md=HASS Bridge" |
76 | | - b" W9DN\x06pv=1.0\x14id=11:8E:DB:5B:5C:C5\x05c#=12\x04s#=1\x04ff=0\x04" |
77 | | - b"ci=2\x04sf=0\x0bsh=6fLM5A==", |
78 | | - }, |
79 | | - { |
80 | | - "name": "HASS Bridge Y9OO EFF0A7._hap._tcp.local.", |
81 | | - "address": address, |
82 | | - "port": 51838, |
83 | | - "text": b"\x13md=HASS Bridge" |
84 | | - b" Y9OO\x06pv=1.0\x14id=D3:FE:98:EF:F0:A7\x04c#=2\x04s#=1\x04ff=0\x04" |
85 | | - b"ci=2\x04sf=0\x0bsh=u3bdfw==", |
86 | | - }, |
87 | | - { |
88 | | - "name": "Snooze Room TV 6B89B0._hap._tcp.local.", |
89 | | - "address": address, |
90 | | - "port": 51835, |
91 | | - "text": b"\x11md=Snooze Room" |
92 | | - b" TV\x06pv=1.0\x14id=5F:D5:70:6B:89:B0\x05c#=17\x04s#=1\x04ff=0\x05" |
93 | | - b"ci=31\x04sf=0\x0bsh=xNTqsg==", |
94 | | - }, |
95 | | - { |
96 | | - "name": "AlexanderHomeAssistant 74651D._hap._tcp.local.", |
97 | | - "address": address, |
98 | | - "port": 54811, |
99 | | - "text": b"\x19md=AlexanderHomeAssistant\x06pv=1.0\x14id=59:8A:0B:74:65:1D\x05" |
100 | | - b"c#=14\x04s#=1\x04ff=0\x04ci=2\x04sf=0\x0bsh=ccZLPA==", |
101 | | - }, |
102 | | - { |
103 | | - "name": "HASS Bridge OS95 39C053._hap._tcp.local.", |
104 | | - "address": address, |
105 | | - "port": 51831, |
106 | | - "text": b"\x13md=HASS Bridge" |
107 | | - b" OS95\x06pv=1.0\x14id=7E:8C:E6:39:C0:53\x05c#=12\x04s#=1\x04ff=0\x04ci=2" |
108 | | - b"\x04sf=0\x0bsh=Xfe5LQ==", |
109 | | - }, |
110 | | - ] |
111 | | - |
112 | | - out.add_answer_at_time( |
113 | | - DNSText( |
114 | | - "HASS Bridge W9DN 5B5CC5._hap._tcp.local.", |
115 | | - const._TYPE_TXT, |
116 | | - const._CLASS_IN | const._CLASS_UNIQUE, |
117 | | - const._DNS_OTHER_TTL, |
118 | | - b"\x13md=HASS Bridge W9DN\x06pv=1.0\x14id=11:8E:DB:5B:5C:C5\x05c#=12\x04s#=1" |
119 | | - b"\x04ff=0\x04ci=2\x04sf=0\x0bsh=6fLM5A==", |
120 | | - ), |
121 | | - 0, |
122 | | - ) |
123 | | - |
124 | | - for record in additionals: |
125 | | - out.add_additional_answer( |
126 | | - DNSService( |
127 | | - record["name"], # type: ignore |
128 | | - const._TYPE_SRV, |
129 | | - const._CLASS_IN | const._CLASS_UNIQUE, |
130 | | - const._DNS_HOST_TTL, |
131 | | - 0, |
132 | | - 0, |
133 | | - record["port"], # type: ignore |
134 | | - record["name"], # type: ignore |
135 | | - ) |
136 | | - ) |
137 | | - out.add_additional_answer( |
138 | | - DNSText( |
139 | | - record["name"], # type: ignore |
140 | | - const._TYPE_TXT, |
141 | | - const._CLASS_IN | const._CLASS_UNIQUE, |
142 | | - const._DNS_OTHER_TTL, |
143 | | - record["text"], # type: ignore |
144 | | - ) |
145 | | - ) |
146 | | - out.add_additional_answer( |
147 | | - DNSAddress( |
148 | | - record["name"], # type: ignore |
149 | | - const._TYPE_A, |
150 | | - const._CLASS_IN | const._CLASS_UNIQUE, |
151 | | - const._DNS_HOST_TTL, |
152 | | - record["address"], # type: ignore |
153 | | - ) |
154 | | - ) |
155 | | - |
156 | | - return out |
157 | | - |
158 | | - |
159 | | -out = generate_packets() |
| 7 | +from .helpers import generate_packets |
160 | 8 |
|
161 | 9 |
|
162 | 10 | def test_parse_outgoing_message(benchmark: BenchmarkFixture) -> None: |
| 11 | + out = generate_packets() |
| 12 | + |
163 | 13 | @benchmark |
164 | 14 | def make_outgoing_message() -> None: |
165 | 15 | out.packets() |
|
0 commit comments