Commit fcf41fc7 authored by Dan Rubel's avatar Dan Rubel Committed by GitHub
parent f36b218e
...@@ -259,15 +259,14 @@ class AndroidDevice extends Device { ...@@ -259,15 +259,14 @@ class AndroidDevice extends Device {
return true; return true;
} }
Future<Uri> _forwardUriToNewPort(String service, Uri deviceUri, int port) async { Future<int> _forwardPort(String service, int devicePort, int port) async {
try { try {
// Set up port forwarding for observatory. // Set up port forwarding for observatory.
port = await portForwarder.forward(deviceUri.port, hostPort: port); port = await portForwarder.forward(devicePort, hostPort: port);
Uri localUri = deviceUri.replace(port: port); printTrace('$service listening on http://127.0.0.1:$port');
printTrace('$service listening on $localUri'); return port;
return localUri;
} catch (e) { } catch (e) {
printError('Unable to forward device port ${deviceUri.port} to $port: $e'); printError('Unable to forward port $port: $e');
} }
return null; return null;
} }
...@@ -356,35 +355,35 @@ class AndroidDevice extends Device { ...@@ -356,35 +355,35 @@ class AndroidDevice extends Device {
printTrace('Waiting for observatory port to be available...'); printTrace('Waiting for observatory port to be available...');
try { try {
Uri observatoryDeviceUri, diagnosticDeviceUri; int observatoryDevicePort, diagnosticDevicePort;
if (debuggingOptions.buildMode == BuildMode.debug) { if (debuggingOptions.buildMode == BuildMode.debug) {
Future<List<Uri>> scrapeServiceUris = Future.wait( Future<List<int>> scrapeServicePorts = Future.wait(
<Future<Uri>>[observatoryDiscovery.nextUri(), diagnosticDiscovery.nextUri()] <Future<int>>[observatoryDiscovery.nextPort(), diagnosticDiscovery.nextPort()]
); );
List<Uri> deviceUris = await scrapeServiceUris.timeout(new Duration(seconds: 20)); List<int> devicePorts = await scrapeServicePorts.timeout(new Duration(seconds: 20));
observatoryDeviceUri = deviceUris[0]; observatoryDevicePort = devicePorts[0];
diagnosticDeviceUri = deviceUris[1]; diagnosticDevicePort = devicePorts[1];
} else { } else {
observatoryDeviceUri = await observatoryDiscovery.nextUri().timeout(new Duration(seconds: 20)); observatoryDevicePort = await observatoryDiscovery.nextPort().timeout(new Duration(seconds: 20));
} }
printTrace('Observatory Uri on device: $observatoryDeviceUri'); printTrace('observatory port on device: $observatoryDevicePort');
int observatoryLocalPort = await debuggingOptions.findBestObservatoryPort(); int observatoryLocalPort = await debuggingOptions.findBestObservatoryPort();
// TODO(devoncarew): Remember the forwarding information (so we can later remove the // TODO(devoncarew): Remember the forwarding information (so we can later remove the
// port forwarding). // port forwarding).
Uri observatoryLocalUri = await _forwardUriToNewPort(ProtocolDiscovery.kObservatoryService, observatoryDeviceUri, observatoryLocalPort); observatoryLocalPort = await _forwardPort(ProtocolDiscovery.kObservatoryService, observatoryDevicePort, observatoryLocalPort);
Uri diagnosticLocalUri; int diagnosticLocalPort;
if (diagnosticDeviceUri != null) { if (diagnosticDevicePort != null) {
printTrace('Diagnostic Server Uri on device: $diagnosticDeviceUri'); printTrace('diagnostic port on device: $diagnosticDevicePort');
int diagnosticLocalPort = await debuggingOptions.findBestDiagnosticPort(); diagnosticLocalPort = await debuggingOptions.findBestDiagnosticPort();
diagnosticLocalUri = await _forwardUriToNewPort(ProtocolDiscovery.kDiagnosticService, diagnosticDeviceUri, diagnosticLocalPort); diagnosticLocalPort = await _forwardPort(ProtocolDiscovery.kDiagnosticService, diagnosticDevicePort, diagnosticLocalPort);
} }
return new LaunchResult.succeeded( return new LaunchResult.succeeded(
observatoryUri: observatoryLocalUri, observatoryPort: observatoryLocalPort,
diagnosticUri: diagnosticLocalUri, diagnosticPort: diagnosticLocalPort
); );
} catch (error) { } catch (error) {
if (error is TimeoutException) if (error is TimeoutException)
......
...@@ -359,8 +359,8 @@ class AppDomain extends Domain { ...@@ -359,8 +359,8 @@ class AppDomain extends Domain {
connectionInfoCompleter = new Completer<DebugConnectionInfo>(); connectionInfoCompleter = new Completer<DebugConnectionInfo>();
connectionInfoCompleter.future.then((DebugConnectionInfo info) { connectionInfoCompleter.future.then((DebugConnectionInfo info) {
Map<String, dynamic> params = <String, dynamic>{ Map<String, dynamic> params = <String, dynamic>{
'port': info.httpUri.port, 'port': info.port,
'wsUri': info.wsUri.toString(), 'wsUri': info.wsUri
}; };
if (info.baseUri != null) if (info.baseUri != null)
params['baseUri'] = info.baseUri; params['baseUri'] = info.baseUri;
......
...@@ -55,14 +55,10 @@ class TraceCommand extends FlutterCommand { ...@@ -55,14 +55,10 @@ class TraceCommand extends FlutterCommand {
Future<Null> runCommand() async { Future<Null> runCommand() async {
int observatoryPort = int.parse(argResults['debug-port']); int observatoryPort = int.parse(argResults['debug-port']);
// TODO(danrubel): this will break if we move to the new observatory URL
// See https://github.com/flutter/flutter/issues/7038
Uri observatoryUri = Uri.parse('http://127.0.0.1:$observatoryPort');
Tracing tracing; Tracing tracing;
try { try {
tracing = await Tracing.connect(observatoryUri); tracing = await Tracing.connect(observatoryPort);
} catch (error) { } catch (error) {
throwToolExit('Error connecting to observatory: $error'); throwToolExit('Error connecting to observatory: $error');
} }
...@@ -104,8 +100,8 @@ class TraceCommand extends FlutterCommand { ...@@ -104,8 +100,8 @@ class TraceCommand extends FlutterCommand {
class Tracing { class Tracing {
Tracing(this.vmService); Tracing(this.vmService);
static Future<Tracing> connect(Uri uri) { static Future<Tracing> connect(int port) {
return VMService.connect(uri).then((VMService observatory) => new Tracing(observatory)); return VMService.connect(port).then((VMService observatory) => new Tracing(observatory));
} }
final VMService vmService; final VMService vmService;
......
...@@ -296,22 +296,22 @@ class DebuggingOptions { ...@@ -296,22 +296,22 @@ class DebuggingOptions {
} }
class LaunchResult { class LaunchResult {
LaunchResult.succeeded({ this.observatoryUri, this.diagnosticUri }) : started = true; LaunchResult.succeeded({ this.observatoryPort, this.diagnosticPort }) : started = true;
LaunchResult.failed() : started = false, observatoryUri = null, diagnosticUri = null; LaunchResult.failed() : started = false, observatoryPort = null, diagnosticPort = null;
bool get hasObservatory => observatoryUri != null; bool get hasObservatory => observatoryPort != null;
final bool started; final bool started;
final Uri observatoryUri; final int observatoryPort;
final Uri diagnosticUri; final int diagnosticPort;
@override @override
String toString() { String toString() {
StringBuffer buf = new StringBuffer('started=$started'); StringBuffer buf = new StringBuffer('started=$started');
if (observatoryUri != null) if (observatoryPort != null)
buf.write(', observatory=$observatoryUri'); buf.write(', observatory=$observatoryPort');
if (diagnosticUri != null) if (diagnosticPort != null)
buf.write(', diagnostic=$diagnosticUri'); buf.write(', diagnostic=$diagnosticPort');
return buf.toString(); return buf.toString();
} }
} }
......
...@@ -108,7 +108,7 @@ class HotRunner extends ResidentRunner { ...@@ -108,7 +108,7 @@ class HotRunner extends ResidentRunner {
final String applicationBinary; final String applicationBinary;
bool get prebuiltMode => applicationBinary != null; bool get prebuiltMode => applicationBinary != null;
Set<String> _dartDependencies; Set<String> _dartDependencies;
Uri _observatoryUri; int _observatoryPort;
AssetBundle _bundle; AssetBundle _bundle;
AssetBundle get bundle => _bundle; AssetBundle get bundle => _bundle;
final bool benchmarkMode; final bool benchmarkMode;
...@@ -216,9 +216,9 @@ class HotRunner extends ResidentRunner { ...@@ -216,9 +216,9 @@ class HotRunner extends ResidentRunner {
return 2; return 2;
} }
_observatoryUri = result.observatoryUri; _observatoryPort = result.observatoryPort;
try { try {
await connectToServiceProtocol(_observatoryUri); await connectToServiceProtocol(_observatoryPort);
} catch (error) { } catch (error) {
printError('Error connecting to the service protocol: $error'); printError('Error connecting to the service protocol: $error');
return 2; return 2;
...@@ -230,8 +230,8 @@ class HotRunner extends ResidentRunner { ...@@ -230,8 +230,8 @@ class HotRunner extends ResidentRunner {
if (connectionInfoCompleter != null) { if (connectionInfoCompleter != null) {
connectionInfoCompleter.complete( connectionInfoCompleter.complete(
new DebugConnectionInfo( new DebugConnectionInfo(
httpUri: _observatoryUri, port: _observatoryPort,
wsUri: vmService.wsAddress, wsUri: 'ws://localhost:$_observatoryPort/ws',
baseUri: baseUri.toString() baseUri: baseUri.toString()
) )
); );
...@@ -533,7 +533,7 @@ class HotRunner extends ResidentRunner { ...@@ -533,7 +533,7 @@ class HotRunner extends ResidentRunner {
ansiAlternative: '$red$fire$bold To hot reload your app on the fly, ' ansiAlternative: '$red$fire$bold To hot reload your app on the fly, '
'press "r" or F5. To restart the app entirely, press "R".$reset' 'press "r" or F5. To restart the app entirely, press "R".$reset'
); );
printStatus('The Observatory debugger and profiler is available at: $_observatoryUri'); printStatus('The Observatory debugger and profiler is available at: http://127.0.0.1:$_observatoryPort/');
if (details) { if (details) {
printHelpDetails(); printHelpDetails();
printStatus('To repeat this help message, press "h" or F1. To quit, press "q", F10, or Ctrl-C.'); printStatus('To repeat this help message, press "h" or F1. To quit, press "q", F10, or Ctrl-C.');
......
...@@ -244,8 +244,8 @@ class IOSDevice extends Device { ...@@ -244,8 +244,8 @@ class IOSDevice extends Device {
} }
int installationResult = -1; int installationResult = -1;
Uri localObsUri; int localObsPort;
Uri localDiagUri; int localDiagPort;
if (!debuggingOptions.debuggingEnabled) { if (!debuggingOptions.debuggingEnabled) {
// If debugging is not enabled, just launch the application and continue. // If debugging is not enabled, just launch the application and continue.
...@@ -256,34 +256,30 @@ class IOSDevice extends Device { ...@@ -256,34 +256,30 @@ class IOSDevice extends Device {
// ports post launch. // ports post launch.
printTrace("Debugging is enabled, connecting to observatory and the diagnostic server"); printTrace("Debugging is enabled, connecting to observatory and the diagnostic server");
Future<Uri> forwardObsUri = _acquireAndForwardUriToNewPort( Future<int> forwardObsPort = _acquireAndForwardPort(app,
app, ProtocolDiscovery.kObservatoryService,
ProtocolDiscovery.kObservatoryService, debuggingOptions.observatoryPort);
debuggingOptions.observatoryPort, Future<int> forwardDiagPort;
);
Future<Uri> forwardDiagUri;
if (debuggingOptions.buildMode == BuildMode.debug) { if (debuggingOptions.buildMode == BuildMode.debug) {
forwardDiagUri = _acquireAndForwardUriToNewPort( forwardDiagPort = _acquireAndForwardPort(app,
app, ProtocolDiscovery.kDiagnosticService,
ProtocolDiscovery.kDiagnosticService, debuggingOptions.diagnosticPort);
debuggingOptions.diagnosticPort,
);
} else { } else {
forwardDiagUri = new Future<Uri>.value(null); forwardDiagPort = new Future<int>.value(null);
} }
Future<int> launch = runCommandAndStreamOutput(launchCommand, trace: true); Future<int> launch = runCommandAndStreamOutput(launchCommand, trace: true);
List<Uri> uris = await launch.then((int result) async { List<int> ports = await launch.then((int result) async {
installationResult = result; installationResult = result;
if (result != 0) { if (result != 0) {
printTrace("Failed to launch the application on device."); printTrace("Failed to launch the application on device.");
return <Uri>[null, null]; return <int>[null, null];
} }
printTrace("Application launched on the device. Attempting to forward ports."); printTrace("Application launched on the device. Attempting to forward ports.");
return await Future.wait(<Future<Uri>>[forwardObsUri, forwardDiagUri]) return await Future.wait(<Future<int>>[forwardObsPort, forwardDiagPort])
.timeout( .timeout(
kPortForwardTimeout, kPortForwardTimeout,
onTimeout: () { onTimeout: () {
...@@ -292,11 +288,11 @@ class IOSDevice extends Device { ...@@ -292,11 +288,11 @@ class IOSDevice extends Device {
); );
}); });
printTrace("Observatory Uri on device: ${uris[0]}"); printTrace("Local Observatory Port: ${ports[0]}");
printTrace("Diagnostic Server Uri on device: ${uris[1]}"); printTrace("Local Diagnostic Server Port: ${ports[1]}");
localObsUri = uris[0]; localObsPort = ports[0];
localDiagUri = uris[1]; localDiagPort = ports[1];
} }
if (installationResult != 0) { if (installationResult != 0) {
...@@ -307,25 +303,25 @@ class IOSDevice extends Device { ...@@ -307,25 +303,25 @@ class IOSDevice extends Device {
return new LaunchResult.failed(); return new LaunchResult.failed();
} }
return new LaunchResult.succeeded(observatoryUri: localObsUri, diagnosticUri: localDiagUri); return new LaunchResult.succeeded(observatoryPort: localObsPort, diagnosticPort: localDiagPort);
} }
Future<Uri> _acquireAndForwardUriToNewPort( Future<int> _acquireAndForwardPort(
ApplicationPackage app, ApplicationPackage app,
String serviceName, String serviceName,
int localPort) async { int localPort) async {
Duration stepTimeout = const Duration(seconds: 60); Duration stepTimeout = const Duration(seconds: 60);
Future<Uri> remote = new ProtocolDiscovery(getLogReader(app: app), serviceName).nextUri(); Future<int> remote = new ProtocolDiscovery(getLogReader(app: app), serviceName).nextPort();
Uri remoteUri = await remote.timeout(stepTimeout, int remotePort = await remote.timeout(stepTimeout,
onTimeout: () { onTimeout: () {
printTrace("Timeout while attempting to retrieve remote Uri for $serviceName"); printTrace("Timeout while attempting to retrieve remote port for $serviceName");
return null; return null;
}); });
if (remoteUri == null) { if (remotePort == null) {
printTrace("Could not read Uri on device for $serviceName"); printTrace("Could not read port on device for $serviceName");
return null; return null;
} }
...@@ -334,22 +330,19 @@ class IOSDevice extends Device { ...@@ -334,22 +330,19 @@ class IOSDevice extends Device {
printTrace("Auto selected local port to $localPort"); printTrace("Auto selected local port to $localPort");
} }
int forwardResult = await portForwarder int forwardResult = await portForwarder.forward(remotePort,
.forward(remoteUri.port, hostPort: localPort) hostPort: localPort).timeout(stepTimeout, onTimeout: () {
.timeout(stepTimeout, onTimeout: () { printTrace("Timeout while atempting to foward port for $serviceName");
printTrace("Timeout while atempting to foward port for $serviceName"); return null;
return null; });
});
if (forwardResult == null) { if (forwardResult == null) {
printTrace("Could not foward remote $serviceName port $remoteUri to local port $localPort"); printTrace("Could not foward remote $serviceName port $remotePort to local port $localPort");
return null; return null;
} }
Uri forwardUri = remoteUri.replace(port: forwardResult); printStatus('$serviceName listening on http://127.0.0.1:$localPort');
return localPort;
printStatus('$serviceName listening on $forwardUri');
return forwardUri;
} }
@override @override
......
...@@ -474,12 +474,12 @@ class IOSSimulator extends Device { ...@@ -474,12 +474,12 @@ class IOSSimulator extends Device {
printTrace('Waiting for observatory port to be available...'); printTrace('Waiting for observatory port to be available...');
try { try {
Uri deviceUri = await observatoryDiscovery int devicePort = await observatoryDiscovery
.nextUri() .nextPort()
.timeout(new Duration(seconds: 20)); .timeout(new Duration(seconds: 20));
printTrace('Observatory Uri on simulator: $deviceUri'); printTrace('service protocol port = $devicePort');
printStatus('Observatory listening on $deviceUri'); printStatus('Observatory listening on http://127.0.0.1:$devicePort');
return new LaunchResult.succeeded(observatoryUri: deviceUri); return new LaunchResult.succeeded(observatoryPort: devicePort);
} catch (error) { } catch (error) {
if (error is TimeoutException) if (error is TimeoutException)
printError('Timed out while waiting for a debug connection.'); printError('Timed out while waiting for a debug connection.');
......
...@@ -21,38 +21,37 @@ class ProtocolDiscovery { ...@@ -21,38 +21,37 @@ class ProtocolDiscovery {
final DeviceLogReader _logReader; final DeviceLogReader _logReader;
final String _serviceName; final String _serviceName;
Completer<Uri> _completer = new Completer<Uri>(); Completer<int> _completer = new Completer<int>();
StreamSubscription<String> _subscription; StreamSubscription<String> _subscription;
/// The [Future] returned by this function will complete when the next service /// The [Future] returned by this function will complete when the next service
/// Uri is found. /// protocol port is found.
Future<Uri> nextUri() => _completer.future; Future<int> nextPort() => _completer.future;
void cancel() { void cancel() {
_subscription.cancel(); _subscription.cancel();
} }
void _onLine(String line) { void _onLine(String line) {
Uri uri; int portNumber = 0;
if (line.contains('$_serviceName listening on http://')) { if (line.contains('$_serviceName listening on http://')) {
RegExp portExp = new RegExp(r"http://\d+.\d+.\d+.\d+:\d+\S*");
try { try {
String match = portExp.stringMatch(line); RegExp portExp = new RegExp(r"\d+.\d+.\d+.\d+:(\d+)");
if (match != null) String port = portExp.firstMatch(line).group(1);
uri = Uri.parse(match); portNumber = int.parse(port);
} catch (_) { } catch (_) {
// Ignore errors. // Ignore errors.
} }
} }
if (uri != null) if (portNumber != 0)
_located(uri); _located(portNumber);
} }
void _located(Uri uri) { void _located(int port) {
assert(_completer != null); assert(_completer != null);
assert(!_completer.isCompleted); assert(!_completer.isCompleted);
_completer.complete(uri); _completer.complete(port);
_completer = new Completer<Uri>(); _completer = new Completer<int>();
} }
} }
...@@ -119,12 +119,12 @@ abstract class ResidentRunner { ...@@ -119,12 +119,12 @@ abstract class ResidentRunner {
_loggingSubscription = null; _loggingSubscription = null;
} }
Future<Null> connectToServiceProtocol(Uri uri) async { Future<Null> connectToServiceProtocol(int port) async {
if (!debuggingOptions.debuggingEnabled) { if (!debuggingOptions.debuggingEnabled) {
return new Future<Null>.error('Error the service protocol is not enabled.'); return new Future<Null>.error('Error the service protocol is not enabled.');
} }
vmService = await VMService.connect(uri); vmService = await VMService.connect(port);
printTrace('Connected to service protocol: $uri'); printTrace('Connected to service protocol on port $port');
await vmService.getVM(); await vmService.getVM();
// Refresh the view list. // Refresh the view list.
...@@ -287,9 +287,9 @@ String getMissingPackageHintForPlatform(TargetPlatform platform) { ...@@ -287,9 +287,9 @@ String getMissingPackageHintForPlatform(TargetPlatform platform) {
} }
class DebugConnectionInfo { class DebugConnectionInfo {
DebugConnectionInfo({ this.httpUri, this.wsUri, this.baseUri }); DebugConnectionInfo({ this.port, this.wsUri, this.baseUri });
final Uri httpUri; final int port;
final Uri wsUri; final String wsUri;
final String baseUri; final String baseUri;
} }
...@@ -119,18 +119,19 @@ class RunAndStayResident extends ResidentRunner { ...@@ -119,18 +119,19 @@ class RunAndStayResident extends ResidentRunner {
startTime.stop(); startTime.stop();
// Connect to observatory.
if (debuggingOptions.debuggingEnabled) {
await connectToServiceProtocol(_result.observatoryUri);
}
if (_result.hasObservatory) { if (_result.hasObservatory) {
int port = _result.observatoryPort;
connectionInfoCompleter?.complete(new DebugConnectionInfo( connectionInfoCompleter?.complete(new DebugConnectionInfo(
httpUri: _result.observatoryUri, port: port,
wsUri: vmService.wsAddress, wsUri: 'ws://localhost:$port/ws'
)); ));
} }
// Connect to observatory.
if (debuggingOptions.debuggingEnabled) {
await connectToServiceProtocol(_result.observatoryPort);
}
printTrace('Application running.'); printTrace('Application running.');
if (vmService != null) { if (vmService != null) {
...@@ -175,7 +176,7 @@ class RunAndStayResident extends ResidentRunner { ...@@ -175,7 +176,7 @@ class RunAndStayResident extends ResidentRunner {
void printHelp({ @required bool details }) { void printHelp({ @required bool details }) {
bool haveDetails = false; bool haveDetails = false;
if (_result.hasObservatory) if (_result.hasObservatory)
printStatus('The Observatory debugger and profiler is available at: ${_result.observatoryUri}'); printStatus('The Observatory debugger and profiler is available at: http://127.0.0.1:${_result.observatoryPort}/');
if (supportsServiceProtocol) { if (supportsServiceProtocol) {
haveDetails = true; haveDetails = true;
if (details) if (details)
......
...@@ -14,7 +14,7 @@ import 'globals.dart'; ...@@ -14,7 +14,7 @@ import 'globals.dart';
/// A connection to the Dart VM Service. /// A connection to the Dart VM Service.
class VMService { class VMService {
VMService._(this.peer, this.httpAddress, this.wsAddress) { VMService._(this.peer, this.port, this.httpAddress) {
_vm = new VM._empty(this); _vm = new VM._empty(this);
peer.registerMethod('streamNotify', (rpc.Parameters event) { peer.registerMethod('streamNotify', (rpc.Parameters event) {
...@@ -23,24 +23,21 @@ class VMService { ...@@ -23,24 +23,21 @@ class VMService {
} }
/// Connect to '127.0.0.1' at [port]. /// Connect to '127.0.0.1' at [port].
static Future<VMService> connect(Uri httpUri) async { static Future<VMService> connect(int port) async {
String wsPath = httpUri.path; Uri uri = new Uri(scheme: 'ws', host: '127.0.0.1', port: port, path: 'ws');
if (!wsPath.endsWith('/'))
wsPath += '/';
wsPath += 'ws';
Uri wsUri = httpUri.replace(scheme: 'ws', path: wsPath);
WebSocket ws; WebSocket ws;
try { try {
ws = await WebSocket.connect(wsUri.toString()); ws = await WebSocket.connect(uri.toString());
} catch (e) { } catch (e) {
return new Future<VMService>.error('Failed to connect to $wsUri\n $e'); return new Future<VMService>.error('Failed to connect to $uri\n $e');
} }
rpc.Peer peer = new rpc.Peer(new IOWebSocketChannel(ws).cast()); rpc.Peer peer = new rpc.Peer(new IOWebSocketChannel(ws).cast());
peer.listen(); peer.listen();
return new VMService._(peer, httpUri, wsUri); Uri httpAddress = new Uri(scheme: 'http', host: '127.0.0.1', port: port);
return new VMService._(peer, port, httpAddress);
} }
final Uri httpAddress; final Uri httpAddress;
final Uri wsAddress; final int port;
final rpc.Peer peer; final rpc.Peer peer;
VM _vm; VM _vm;
......
...@@ -17,48 +17,35 @@ void main() { ...@@ -17,48 +17,35 @@ void main() {
new ProtocolDiscovery(logReader, ProtocolDiscovery.kObservatoryService); new ProtocolDiscovery(logReader, ProtocolDiscovery.kObservatoryService);
// Get next port future. // Get next port future.
Future<Uri> nextUri = discoverer.nextUri(); Future<int> nextPort = discoverer.nextPort();
expect(nextUri, isNotNull); expect(nextPort, isNotNull);
// Inject some lines. // Inject some lines.
logReader.addLine('HELLO WORLD'); logReader.addLine('HELLO WORLD');
logReader.addLine('Observatory listening on http://127.0.0.1:9999'); logReader.addLine('Observatory listening on http://127.0.0.1:9999');
// Await the port. // Await the port.
Uri uri = await nextUri; expect(await nextPort, 9999);
expect(uri.port, 9999);
expect('$uri', 'http://127.0.0.1:9999');
// Get next port future. // Get next port future.
nextUri = discoverer.nextUri(); nextPort = discoverer.nextPort();
logReader.addLine('Observatory listening on http://127.0.0.1:3333'); logReader.addLine('Observatory listening on http://127.0.0.1:3333');
uri = await nextUri; expect(await nextPort, 3333);
expect(uri.port, 3333);
expect('$uri', 'http://127.0.0.1:3333');
// Get next port future. // Get next port future.
nextUri = discoverer.nextUri(); nextPort = discoverer.nextPort();
// Inject some bad lines. // Inject some bad lines.
logReader.addLine('Observatory listening on http://127.0.0.1'); logReader.addLine('Observatory listening on http://127.0.0.1');
logReader.addLine('Observatory listening on http://127.0.0.1:'); logReader.addLine('Observatory listening on http://127.0.0.1:');
logReader.addLine('Observatory listening on http://127.0.0.1:apple'); logReader.addLine('Observatory listening on http://127.0.0.1:apple');
Uri timeoutUri = Uri.parse('http://timeout'); int port = await nextPort.timeout(
Uri actualUri = await nextUri.timeout( const Duration(milliseconds: 100), onTimeout: () => 77);
const Duration(milliseconds: 100), onTimeout: () => timeoutUri); // Expect the timeout port.
expect(actualUri, timeoutUri); expect(port, 77);
// Get next port future. // Get next port future.
nextUri = discoverer.nextUri(); nextPort = discoverer.nextPort();
logReader.addLine('I/flutter : Observatory listening on http://127.0.0.1:52584'); logReader.addLine('I/flutter : Observatory listening on http://127.0.0.1:52584');
uri = await nextUri; expect(await nextPort, 52584);
expect(uri.port, 52584);
expect('$uri', 'http://127.0.0.1:52584');
// Get next port future.
nextUri = discoverer.nextUri();
logReader.addLine('I/flutter : Observatory listening on http://127.0.0.1:54804/PTwjm8Ii8qg=/');
uri = await nextUri;
expect(uri.port, 54804);
expect('$uri', 'http://127.0.0.1:54804/PTwjm8Ii8qg=/');
discoverer.cancel(); discoverer.cancel();
logReader.dispose(); logReader.dispose();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment