mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] don't elapse real time during fallback test (#54717)
This commit is contained in:
parent
e6abda7f00
commit
4ee618bb72
@ -13,6 +13,8 @@ import '../mdns_discovery.dart';
|
|||||||
import '../protocol_discovery.dart';
|
import '../protocol_discovery.dart';
|
||||||
import '../reporting/reporting.dart';
|
import '../reporting/reporting.dart';
|
||||||
|
|
||||||
|
typedef VmServiceConnector = Future<VmService> Function(String, {Log log});
|
||||||
|
|
||||||
/// A protocol for discovery of a vmservice on an attached iOS device with
|
/// A protocol for discovery of a vmservice on an attached iOS device with
|
||||||
/// multiple fallbacks.
|
/// multiple fallbacks.
|
||||||
///
|
///
|
||||||
@ -42,14 +44,16 @@ class FallbackDiscovery {
|
|||||||
@required Logger logger,
|
@required Logger logger,
|
||||||
@required ProtocolDiscovery protocolDiscovery,
|
@required ProtocolDiscovery protocolDiscovery,
|
||||||
@required Usage flutterUsage,
|
@required Usage flutterUsage,
|
||||||
Future<VmService> Function(String wsUri, {Log log}) vmServiceConnectUri =
|
VmServiceConnector vmServiceConnectUri =
|
||||||
vm_service_io.vmServiceConnectUri,
|
vm_service_io.vmServiceConnectUri,
|
||||||
|
Duration pollingDelay = const Duration(seconds: 2),
|
||||||
}) : _logger = logger,
|
}) : _logger = logger,
|
||||||
_mDnsObservatoryDiscovery = mDnsObservatoryDiscovery,
|
_mDnsObservatoryDiscovery = mDnsObservatoryDiscovery,
|
||||||
_portForwarder = portForwarder,
|
_portForwarder = portForwarder,
|
||||||
_protocolDiscovery = protocolDiscovery,
|
_protocolDiscovery = protocolDiscovery,
|
||||||
_flutterUsage = flutterUsage,
|
_flutterUsage = flutterUsage,
|
||||||
_vmServiceConnectUri = vmServiceConnectUri;
|
_vmServiceConnectUri = vmServiceConnectUri,
|
||||||
|
_pollingDelay = pollingDelay;
|
||||||
|
|
||||||
static const String _kEventName = 'ios-handshake';
|
static const String _kEventName = 'ios-handshake';
|
||||||
|
|
||||||
@ -58,7 +62,8 @@ class FallbackDiscovery {
|
|||||||
final Logger _logger;
|
final Logger _logger;
|
||||||
final ProtocolDiscovery _protocolDiscovery;
|
final ProtocolDiscovery _protocolDiscovery;
|
||||||
final Usage _flutterUsage;
|
final Usage _flutterUsage;
|
||||||
final Future<VmService> Function(String wsUri, {Log log}) _vmServiceConnectUri;
|
final VmServiceConnector _vmServiceConnectUri;
|
||||||
|
final Duration _pollingDelay;
|
||||||
|
|
||||||
/// Attempt to discover the observatory port.
|
/// Attempt to discover the observatory port.
|
||||||
Future<Uri> discover({
|
Future<Uri> discover({
|
||||||
@ -152,7 +157,6 @@ class FallbackDiscovery {
|
|||||||
|
|
||||||
// Attempt to connect to the VM service 5 times.
|
// Attempt to connect to the VM service 5 times.
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
const int kDelaySeconds = 2;
|
|
||||||
Exception firstException;
|
Exception firstException;
|
||||||
while (attempts < 5) {
|
while (attempts < 5) {
|
||||||
try {
|
try {
|
||||||
@ -184,7 +188,7 @@ class FallbackDiscovery {
|
|||||||
// tool waits for a connection to be reasonable. If the vmservice cannot
|
// tool waits for a connection to be reasonable. If the vmservice cannot
|
||||||
// be connected to in this way, the mDNS discovery must be reached
|
// be connected to in this way, the mDNS discovery must be reached
|
||||||
// sooner rather than later.
|
// sooner rather than later.
|
||||||
await Future<void>.delayed(const Duration(seconds: kDelaySeconds));
|
await Future<void>.delayed(_pollingDelay);
|
||||||
attempts += 1;
|
attempts += 1;
|
||||||
}
|
}
|
||||||
_logger.printTrace('Failed to connect directly, falling back to mDNS');
|
_logger.printTrace('Failed to connect directly, falling back to mDNS');
|
||||||
|
@ -42,6 +42,7 @@ void main() {
|
|||||||
vmServiceConnectUri: (String uri, {Log log}) async {
|
vmServiceConnectUri: (String uri, {Log log}) async {
|
||||||
return mockVmService;
|
return mockVmService;
|
||||||
},
|
},
|
||||||
|
pollingDelay: Duration.zero,
|
||||||
);
|
);
|
||||||
when(mockPortForwarder.forward(23, hostPort: anyNamed('hostPort')))
|
when(mockPortForwarder.forward(23, hostPort: anyNamed('hostPort')))
|
||||||
.thenAnswer((Invocation invocation) async => 1);
|
.thenAnswer((Invocation invocation) async => 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user