parent
6b087c74e2
commit
03a3e7b1e4
@ -660,15 +660,45 @@ class WebDevFS implements DevFS {
|
|||||||
|
|
||||||
Dwds get dwds => webAssetServer.dwds;
|
Dwds get dwds => webAssetServer.dwds;
|
||||||
|
|
||||||
@visibleForTesting
|
Future<DebugConnection> _cachedExtensionFuture;
|
||||||
Future<DebugConnection> cachedExtensionFuture;
|
StreamSubscription<void> _connectedApps;
|
||||||
|
|
||||||
@visibleForTesting
|
|
||||||
StreamSubscription<void> connectedApps;
|
|
||||||
|
|
||||||
/// Connect and retrieve the [DebugConnection] for the current application.
|
/// Connect and retrieve the [DebugConnection] for the current application.
|
||||||
|
///
|
||||||
|
/// Only calls [AppConnection.runMain] on the subsequent connections.
|
||||||
Future<ConnectionResult> connect(bool useDebugExtension) {
|
Future<ConnectionResult> connect(bool useDebugExtension) {
|
||||||
return connectToApplication(useDebugExtension, this, globals.logger, createVmServiceDelegate);
|
final Completer<ConnectionResult> firstConnection =
|
||||||
|
Completer<ConnectionResult>();
|
||||||
|
_connectedApps =
|
||||||
|
dwds.connectedApps.listen((AppConnection appConnection) async {
|
||||||
|
try {
|
||||||
|
final DebugConnection debugConnection = useDebugExtension
|
||||||
|
? await (_cachedExtensionFuture ??=
|
||||||
|
dwds.extensionDebugConnections.stream.first)
|
||||||
|
: await dwds.debugConnection(appConnection);
|
||||||
|
if (firstConnection.isCompleted) {
|
||||||
|
appConnection.runMain();
|
||||||
|
} else {
|
||||||
|
final vm_service.VmService vmService = await createVmServiceDelegate(
|
||||||
|
Uri.parse(debugConnection.uri),
|
||||||
|
logger: globals.logger,
|
||||||
|
);
|
||||||
|
firstConnection
|
||||||
|
.complete(ConnectionResult(appConnection, debugConnection, vmService));
|
||||||
|
}
|
||||||
|
} on Exception catch (error, stackTrace) {
|
||||||
|
if (!firstConnection.isCompleted) {
|
||||||
|
firstConnection.completeError(error, stackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, onError: (dynamic error, StackTrace stackTrace) {
|
||||||
|
globals.printError(
|
||||||
|
'Unknown error while waiting for debug connection:$error\n$stackTrace');
|
||||||
|
if (!firstConnection.isCompleted) {
|
||||||
|
firstConnection.completeError(error, stackTrace);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return firstConnection.future;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -723,7 +753,7 @@ class WebDevFS implements DevFS {
|
|||||||
@override
|
@override
|
||||||
Future<void> destroy() async {
|
Future<void> destroy() async {
|
||||||
await webAssetServer.dispose();
|
await webAssetServer.dispose();
|
||||||
await connectedApps?.cancel();
|
await _connectedApps?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -1038,35 +1068,3 @@ To serve from a subpath "foo" (i.e. http://localhost:8080/foo/ instead of http:/
|
|||||||
|
|
||||||
For more information, see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
For more information, see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
||||||
''';
|
''';
|
||||||
|
|
||||||
|
|
||||||
/// Connect and retrieve the [DebugConnection] for the current application.
|
|
||||||
@visibleForTesting
|
|
||||||
Future<ConnectionResult> connectToApplication(bool useDebugExtension, WebDevFS devFS, Logger logger, Future<vm_service.VmService> Function(Uri, {Logger logger}) createVmService) {
|
|
||||||
final Completer<ConnectionResult> firstConnection = Completer<ConnectionResult>();
|
|
||||||
devFS.connectedApps = devFS.dwds.connectedApps.listen((AppConnection appConnection) async {
|
|
||||||
try {
|
|
||||||
final DebugConnection debugConnection = useDebugExtension
|
|
||||||
? await (devFS.cachedExtensionFuture ??=
|
|
||||||
devFS.dwds.extensionDebugConnections.stream.first)
|
|
||||||
: await devFS.dwds.debugConnection(appConnection);
|
|
||||||
if (!firstConnection.isCompleted) {
|
|
||||||
final vm_service.VmService vmService = await createVmService(
|
|
||||||
Uri.parse(debugConnection.uri),
|
|
||||||
logger: logger,
|
|
||||||
);
|
|
||||||
firstConnection.complete(ConnectionResult(appConnection, debugConnection, vmService));
|
|
||||||
}
|
|
||||||
} on Exception catch (error, stackTrace) {
|
|
||||||
if (!firstConnection.isCompleted) {
|
|
||||||
firstConnection.completeError(error, stackTrace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, onError: (dynamic error, StackTrace stackTrace) {
|
|
||||||
logger.printError('Unknown error while waiting for debug connection:$error\n$stackTrace');
|
|
||||||
if (!firstConnection.isCompleted) {
|
|
||||||
firstConnection.completeError(error, stackTrace);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return firstConnection.future;
|
|
||||||
}
|
|
||||||
|
@ -4,14 +4,10 @@
|
|||||||
|
|
||||||
// @dart = 2.8
|
// @dart = 2.8
|
||||||
|
|
||||||
import 'dart:async';
|
|
||||||
import 'dart:io' hide Directory, File;
|
import 'dart:io' hide Directory, File;
|
||||||
|
|
||||||
import 'package:dwds/dwds.dart';
|
|
||||||
import 'package:flutter_tools/src/artifacts.dart';
|
import 'package:flutter_tools/src/artifacts.dart';
|
||||||
import 'package:flutter_tools/src/base/common.dart';
|
|
||||||
import 'package:flutter_tools/src/base/file_system.dart';
|
import 'package:flutter_tools/src/base/file_system.dart';
|
||||||
import 'package:flutter_tools/src/base/logger.dart';
|
|
||||||
import 'package:flutter_tools/src/base/platform.dart';
|
import 'package:flutter_tools/src/base/platform.dart';
|
||||||
import 'package:flutter_tools/src/build_info.dart';
|
import 'package:flutter_tools/src/build_info.dart';
|
||||||
import 'package:flutter_tools/src/build_system/targets/web.dart';
|
import 'package:flutter_tools/src/build_system/targets/web.dart';
|
||||||
@ -23,11 +19,8 @@ import 'package:flutter_tools/src/web/compile.dart';
|
|||||||
import 'package:package_config/package_config.dart';
|
import 'package:package_config/package_config.dart';
|
||||||
import 'package:shelf/shelf.dart';
|
import 'package:shelf/shelf.dart';
|
||||||
import 'package:test/fake.dart';
|
import 'package:test/fake.dart';
|
||||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
|
||||||
|
|
||||||
import '../../src/common.dart';
|
import '../../src/common.dart';
|
||||||
import '../../src/context.dart';
|
|
||||||
import '../../src/fake_vm_services.dart';
|
|
||||||
import '../../src/testbed.dart';
|
import '../../src/testbed.dart';
|
||||||
|
|
||||||
const List<int> kTransparentImage = <int>[
|
const List<int> kTransparentImage = <int>[
|
||||||
@ -1060,48 +1053,6 @@ void main() {
|
|||||||
}, overrides: <Type, Generator>{
|
}, overrides: <Type, Generator>{
|
||||||
Artifacts: () => Artifacts.test(),
|
Artifacts: () => Artifacts.test(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
testWithoutContext('connectToApplication completes the future', () async {
|
|
||||||
final FakeDwds dwds = FakeDwds();
|
|
||||||
final FakeDevFS devfs = FakeDevFS()..dwds = dwds;
|
|
||||||
final BufferLogger logger = BufferLogger.test();
|
|
||||||
|
|
||||||
final Future<void> result = connectToApplication(false, devfs, logger, (Uri uri, {Logger logger}) async {
|
|
||||||
return FakeVmService();
|
|
||||||
});
|
|
||||||
|
|
||||||
dwds.controller.add(FakeAppConnection());
|
|
||||||
|
|
||||||
await expectLater(result, completes);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWithoutContext('Multiple runs of connectToApplication does not complete the future more than once', () async {
|
|
||||||
final FakeDwds dwds = FakeDwds();
|
|
||||||
final FakeDevFS devfs = FakeDevFS()..dwds = dwds;
|
|
||||||
final BufferLogger logger = BufferLogger.test();
|
|
||||||
final Future<void> result = connectToApplication(false, devfs, logger, (Uri uri, {Logger logger}) async {
|
|
||||||
return FakeVmService();
|
|
||||||
});
|
|
||||||
|
|
||||||
dwds.controller.add(FakeAppConnection());
|
|
||||||
dwds.controller.add(FakeAppConnection());
|
|
||||||
unawaited(dwds.controller.close());
|
|
||||||
|
|
||||||
await expectLater(result, completes);
|
|
||||||
});
|
|
||||||
|
|
||||||
testWithoutContext('connectToApplication surfaces errors', () async {
|
|
||||||
final FakeDwds dwds = FakeDwds();
|
|
||||||
final FakeDevFS devfs = FakeDevFS()..dwds = dwds;
|
|
||||||
final BufferLogger logger = BufferLogger.test();
|
|
||||||
final Future<void> result = connectToApplication(false, devfs, logger, (Uri uri, {Logger logger}) async {
|
|
||||||
return FakeVmService();
|
|
||||||
});
|
|
||||||
|
|
||||||
dwds.controller.addError(Exception('test'));
|
|
||||||
|
|
||||||
await expectLater(() => result, throwsException);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FakeHttpServer extends Fake implements HttpServer {
|
class FakeHttpServer extends Fake implements HttpServer {
|
||||||
@ -1130,38 +1081,3 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FakeDevFS extends Fake implements WebDevFS {
|
|
||||||
@override
|
|
||||||
StreamSubscription<void> connectedApps;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<DebugConnection> cachedExtensionFuture;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Dwds dwds;
|
|
||||||
|
|
||||||
void dispose() {
|
|
||||||
connectedApps.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class FakeDwds extends Fake implements Dwds {
|
|
||||||
final StreamController<AppConnection> controller = StreamController<AppConnection>();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Stream<AppConnection> get connectedApps => controller.stream;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<DebugConnection> debugConnection(AppConnection appConnection) async {
|
|
||||||
return FakeDebugConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class FakeAppConnection extends Fake implements AppConnection {}
|
|
||||||
class FakeDebugConnection extends Fake implements DebugConnection {
|
|
||||||
@override
|
|
||||||
String get uri => '';
|
|
||||||
}
|
|
||||||
|
|
||||||
class FakeVmService extends Fake implements vm_service.VmService {}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user