Skip to content

Commit f6be4b0

Browse files
committed
retry ping test if packet loss is < 10%
1 parent 3cc7a76 commit f6be4b0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/pro_preflight.rb

+13-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ def network_check
7878
ip = ssdp_result[:address]
7979
@runner.update_status port, Rainbow("Ethernet connected with IP #{ip}. Running ping test...").aqua
8080

81-
# ping test
82-
ping = `ping #{ip} -i 0.5 -c 15 -q`
83-
packet_loss = ping.match(/(\d+\.\d+)% packet loss/)[1].to_i
81+
packet_loss = ping_test(ip)
82+
if packet_loss > 0 && packet_loss < 10
83+
@runner.update_status port, Rainbow("RETRY: Packet loss #{packet_loss}% Trying again...").yellow
84+
packet_loss = ping_test(ip)
85+
end
8486
if packet_loss > 0
8587
@runner.update_status port, Rainbow("FAILED: Packet loss #{packet_loss}%").red
8688
return false
@@ -117,4 +119,12 @@ def generate_label
117119
@label = label
118120
end
119121

122+
private
123+
124+
def ping_test(ip)
125+
ping = `ping #{ip} -i 0.5 -c 15 -q`
126+
packet_loss = ping.match(/(\d+\.\d+)% packet loss/)[1].to_i
127+
return packet_loss
128+
end
129+
120130
end

0 commit comments

Comments
 (0)