File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,10 +131,11 @@ def tearDownClass(cls):
131131
132132 @classmethod
133133 def _connect_wifi (cls ):
134- """Connect ESP32 to WiFi"""
134+ """Connect ESP32 to WiFi and verify DNS works """
135135 code = f"""
136136import network
137137import time
138+ import socket
138139
139140wlan = network.WLAN(network.STA_IF)
140141wlan.active(True)
@@ -146,14 +147,31 @@ def _connect_wifi(cls):
146147 break
147148 time.sleep(0.5)
148149
149- if wlan.isconnected():
150- print('WIFI_OK:', wlan.ifconfig()[0])
151- else:
150+ if not wlan.isconnected():
152151 print('WIFI_FAIL')
152+ else:
153+ print('WIFI_OK:', wlan.ifconfig()[0])
154+ # Wait for network to stabilize and verify DNS
155+ time.sleep(2)
156+ dns_ok = False
157+ for attempt in range(5):
158+ try:
159+ socket.getaddrinfo('httpbin.org', 80)
160+ dns_ok = True
161+ break
162+ except OSError as e:
163+ print('DNS_RETRY:', attempt + 1, str(e))
164+ time.sleep(2)
165+ if dns_ok:
166+ print('DNS_OK')
167+ else:
168+ print('DNS_FAIL')
153169"""
154- result = cls .mpy .comm .exec (code , timeout = 20 )
170+ result = cls .mpy .comm .exec (code , timeout = 40 )
155171 if b'WIFI_FAIL' in result :
156172 raise RuntimeError ("WiFi connection failed" )
173+ if b'DNS_FAIL' in result :
174+ raise RuntimeError (f"DNS verification failed: { result .decode ('utf-8' )} " )
157175
158176 def run_on_device (self , code , timeout = 30 ):
159177 """Run code on device and return output"""
You can’t perform that action at this time.
0 commit comments