1+ import 'package:logging/logging.dart' ;
12import 'package:network_tools/network_tools.dart' ;
23import 'package:flutter_test/flutter_test.dart' ;
34import 'package:network_tools_flutter/network_tools_flutter.dart' ;
45import 'package:universal_io/io.dart' ;
56
67void main () {
8+ final log = Logger ("host_scan_test" );
79 TestWidgetsFlutterBinding .ensureInitialized ();
810 int port = 0 ;
9- int hostId = 0 ;
11+ int firstHostId = 0 ;
12+ int lastHostId = 0 ;
1013 String myOwnHost = "0.0.0.0" ;
1114 String interfaceIp = myOwnHost.substring (0 , myOwnHost.lastIndexOf ('.' ));
1215 late ServerSocket server;
@@ -28,8 +31,15 @@ void main() {
2831 .address; //gives IP address of GHA local machine.
2932 myOwnHost = address;
3033 interfaceIp = address.substring (0 , address.lastIndexOf ('.' ));
31- hostId = int .parse (
32- address.substring (address.lastIndexOf ('.' ) + 1 , address.length));
34+ final hostId = int .parse (
35+ address.substring (address.lastIndexOf ('.' ) + 1 , address.length),
36+ );
37+ // Better to restrict to scan from hostId - 1 to hostId + 1 to prevent GHA timeouts
38+ firstHostId = hostId <= 1 ? hostId : hostId - 1 ;
39+ lastHostId = hostId >= 254 ? hostId : hostId + 1 ;
40+ log.fine (
41+ 'Fetched own host as $myOwnHost and interface address as $interfaceIp ' ,
42+ );
3343 }
3444 }
3545 });
@@ -40,9 +50,8 @@ void main() {
4050 //There should be at least one device pingable in network
4151 HostScannerFlutter .getAllPingableDevices (
4252 interfaceIp,
43- // Better to restrict to scan from hostId - 1 to hostId + 1 to prevent GHA timeouts
44- firstHostId: hostId - 1 ,
45- lastHostId: hostId + 1 ,
53+ firstHostId: firstHostId,
54+ lastHostId: lastHostId,
4655 ),
4756 emits (isA <ActiveHost >()),
4857 );
@@ -52,9 +61,8 @@ void main() {
5261 //Should emit at least our own local machine when pinging all hosts.
5362 HostScannerFlutter .getAllPingableDevices (
5463 interfaceIp,
55- // Better to restrict to scan from hostId - 1 to hostId + 1 to prevent GHA timeouts
56- firstHostId: hostId - 1 ,
57- lastHostId: hostId + 1 ,
64+ firstHostId: firstHostId,
65+ lastHostId: lastHostId,
5866 ),
5967 emitsThrough (ActiveHost (internetAddress: InternetAddress (myOwnHost))),
6068 );
0 commit comments