[flutter_tools] Generalize waitForExtension (#77220)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/devtools_launcher.dart';
|
||||
import 'package:flutter_tools/src/vmservice.dart';
|
||||
import 'package:vm_service/vm_service.dart' as vm_service;
|
||||
@@ -17,7 +18,7 @@ import 'package:test/fake.dart';
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
||||
final vm_service.Isolate isolate = vm_service.Isolate(
|
||||
final vm_service.Isolate isolate = vm_service.Isolate(
|
||||
id: '1',
|
||||
pauseEvent: vm_service.Event(
|
||||
kind: vm_service.EventKind.kResume,
|
||||
@@ -40,60 +41,17 @@ import '../src/context.dart';
|
||||
startTime: 0,
|
||||
isSystemIsolate: false,
|
||||
isolateFlags: <vm_service.IsolateFlag>[],
|
||||
extensionRPCs: <String>['foo']
|
||||
);
|
||||
|
||||
final vm_service.Isolate fakeUnpausedIsolate = vm_service.Isolate(
|
||||
id: '1',
|
||||
pauseEvent: vm_service.Event(
|
||||
kind: vm_service.EventKind.kResume,
|
||||
timestamp: 0
|
||||
),
|
||||
breakpoints: <vm_service.Breakpoint>[],
|
||||
exceptionPauseMode: null,
|
||||
extensionRPCs: <String>[],
|
||||
libraries: <vm_service.LibraryRef>[
|
||||
vm_service.LibraryRef(
|
||||
id: '1',
|
||||
uri: 'file:///hello_world/main.dart',
|
||||
name: '',
|
||||
),
|
||||
],
|
||||
livePorts: 0,
|
||||
name: 'test',
|
||||
number: '1',
|
||||
pauseOnExit: false,
|
||||
runnable: true,
|
||||
startTime: 0,
|
||||
isSystemIsolate: false,
|
||||
isolateFlags: <vm_service.IsolateFlag>[],
|
||||
);
|
||||
|
||||
final vm_service.VM fakeVM = vm_service.VM(
|
||||
isolates: <vm_service.IsolateRef>[fakeUnpausedIsolate],
|
||||
pid: 1,
|
||||
hostCPU: '',
|
||||
isolateGroups: <vm_service.IsolateGroupRef>[],
|
||||
targetCPU: '',
|
||||
startTime: 0,
|
||||
name: 'dart',
|
||||
architectureBits: 64,
|
||||
operatingSystem: '',
|
||||
version: '',
|
||||
systemIsolateGroups: <vm_service.IsolateGroupRef>[],
|
||||
systemIsolates: <vm_service.IsolateRef>[],
|
||||
);
|
||||
|
||||
final FlutterView fakeFlutterView = FlutterView(
|
||||
id: 'a',
|
||||
uiIsolate: fakeUnpausedIsolate,
|
||||
extensionRPCs: <String>['ext.flutter.connectedVmServiceUri'],
|
||||
);
|
||||
|
||||
final FakeVmServiceRequest listViews = FakeVmServiceRequest(
|
||||
method: kListViewsMethod,
|
||||
jsonResponse: <String, Object>{
|
||||
'views': <Object>[
|
||||
fakeFlutterView.toJson(),
|
||||
FlutterView(
|
||||
id: 'a',
|
||||
uiIsolate: isolate,
|
||||
).toJson()
|
||||
],
|
||||
},
|
||||
);
|
||||
@@ -173,10 +131,10 @@ void main() {
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Extension',
|
||||
'streamId': 'Isolate',
|
||||
}
|
||||
),
|
||||
FakeVmServiceRequest(method: 'getVM', jsonResponse: fakeVM.toJson()),
|
||||
listViews,
|
||||
FakeVmServiceRequest(
|
||||
method: 'getIsolate',
|
||||
jsonResponse: isolate.toJson(),
|
||||
@@ -184,13 +142,11 @@ void main() {
|
||||
'isolateId': '1',
|
||||
},
|
||||
),
|
||||
FakeVmServiceStreamResponse(
|
||||
streamId: 'Extension',
|
||||
event: vm_service.Event(
|
||||
timestamp: 0,
|
||||
extensionKind: 'Flutter.FrameworkInitialization',
|
||||
kind: 'test',
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamCancel',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
listViews,
|
||||
const FakeVmServiceRequest(
|
||||
@@ -218,15 +174,55 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('wait for extension handles an immediate extension', () {
|
||||
testWithoutContext('serveAndAnnounceDevTools with skips calling service extensions when VM service disappears', () async {
|
||||
final ResidentDevtoolsHandler handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher()..activeDevToolsServer = DevToolsServerAddress('localhost', 8080),
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
);
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Extension',
|
||||
}
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
FakeVmServiceRequest(method: 'getVM', jsonResponse: fakeVM.toJson()),
|
||||
const FakeVmServiceRequest(
|
||||
method: kListViewsMethod,
|
||||
errorCode: RPCErrorCodes.kServiceDisappeared,
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamCancel',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
errorCode: RPCErrorCodes.kServiceDisappeared,
|
||||
),
|
||||
], httpAddress: Uri.parse('http://localhost:1234'));
|
||||
|
||||
final FakeFlutterDevice device = FakeFlutterDevice()
|
||||
..vmService = fakeVmServiceHost.vmService;
|
||||
|
||||
await handler.serveAndAnnounceDevTools(
|
||||
flutterDevices: <FlutterDevice>[device],
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('serveAndAnnounceDevTools with multiple devices and VM service disappears on one', () async {
|
||||
final ResidentDevtoolsHandler handler = FlutterResidentDevtoolsHandler(
|
||||
FakeDevtoolsLauncher()..activeDevToolsServer = DevToolsServerAddress('localhost', 8080),
|
||||
FakeResidentRunner(),
|
||||
BufferLogger.test(),
|
||||
);
|
||||
|
||||
final FakeVmServiceHost vmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
listViews,
|
||||
FakeVmServiceRequest(
|
||||
method: 'getIsolate',
|
||||
jsonResponse: isolate.toJson(),
|
||||
@@ -234,46 +230,61 @@ void main() {
|
||||
'isolateId': '1',
|
||||
},
|
||||
),
|
||||
]);
|
||||
waitForExtension(fakeVmServiceHost.vmService.service, 'foo');
|
||||
});
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamCancel',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
listViews,
|
||||
const FakeVmServiceRequest(
|
||||
method: 'ext.flutter.activeDevToolsServerAddress',
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
'value': 'http://localhost:8080',
|
||||
},
|
||||
),
|
||||
listViews,
|
||||
const FakeVmServiceRequest(
|
||||
method: 'ext.flutter.connectedVmServiceUri',
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
'value': 'http://localhost:1234',
|
||||
},
|
||||
),
|
||||
], httpAddress: Uri.parse('http://localhost:1234'));
|
||||
|
||||
testWithoutContext('wait for extension handles no isolates', () {
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||
final FakeVmServiceHost vmServiceHostThatDisappears = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Extension',
|
||||
}
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
FakeVmServiceRequest(method: 'getVM', jsonResponse: vm_service.VM(
|
||||
isolates: <vm_service.IsolateRef>[],
|
||||
pid: 1,
|
||||
hostCPU: '',
|
||||
isolateGroups: <vm_service.IsolateGroupRef>[],
|
||||
targetCPU: '',
|
||||
startTime: 0,
|
||||
name: 'dart',
|
||||
architectureBits: 64,
|
||||
operatingSystem: '',
|
||||
version: '',
|
||||
systemIsolateGroups: <vm_service.IsolateGroupRef>[],
|
||||
systemIsolates: <vm_service.IsolateRef>[],
|
||||
).toJson()),
|
||||
FakeVmServiceStreamResponse(
|
||||
streamId: 'Extension',
|
||||
event: vm_service.Event(
|
||||
timestamp: 0,
|
||||
extensionKind: 'Flutter.FrameworkInitialization',
|
||||
kind: 'test',
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: kListViewsMethod,
|
||||
errorCode: RPCErrorCodes.kServiceDisappeared,
|
||||
),
|
||||
]);
|
||||
waitForExtension(fakeVmServiceHost.vmService.service, 'foo');
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamCancel',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
errorCode: RPCErrorCodes.kServiceDisappeared,
|
||||
),
|
||||
], httpAddress: Uri.parse('http://localhost:5678'));
|
||||
|
||||
await handler.serveAndAnnounceDevTools(
|
||||
flutterDevices: <FlutterDevice>[
|
||||
FakeFlutterDevice()
|
||||
..vmService = vmServiceHostThatDisappears.vmService,
|
||||
FakeFlutterDevice()
|
||||
..vmService = vmServiceHost.vmService,
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
class FakeDevtoolsLauncher extends Fake implements DevtoolsLauncher {
|
||||
@override
|
||||
DevToolsServerAddress activeDevToolsServer;
|
||||
@@ -296,6 +307,11 @@ class FakeResidentRunner extends Fake implements ResidentRunner {
|
||||
}
|
||||
|
||||
class FakeFlutterDevice extends Fake implements FlutterDevice {
|
||||
@override
|
||||
final Device device = FakeDevice();
|
||||
|
||||
@override
|
||||
FlutterVmService vmService;
|
||||
}
|
||||
|
||||
class FakeDevice extends Fake implements Device {}
|
||||
|
||||
@@ -45,52 +45,47 @@ final Map<String, Object> vm = <String, dynamic>{
|
||||
],
|
||||
};
|
||||
|
||||
final vm_service.Isolate isolate = vm_service.Isolate.parse(
|
||||
<String, dynamic>{
|
||||
'type': 'Isolate',
|
||||
'fixedId': true,
|
||||
'id': 'isolates/242098474',
|
||||
'name': 'main.dart:main()',
|
||||
'number': 242098474,
|
||||
'_originNumber': 242098474,
|
||||
'startTime': 1540488745340,
|
||||
'_heaps': <String, dynamic>{
|
||||
'new': <String, dynamic>{
|
||||
'used': 0,
|
||||
'capacity': 0,
|
||||
'external': 0,
|
||||
'collections': 0,
|
||||
'time': 0.0,
|
||||
'avgCollectionPeriodMillis': 0.0,
|
||||
},
|
||||
'old': <String, dynamic>{
|
||||
'used': 0,
|
||||
'capacity': 0,
|
||||
'external': 0,
|
||||
'collections': 0,
|
||||
'time': 0.0,
|
||||
'avgCollectionPeriodMillis': 0.0,
|
||||
},
|
||||
},
|
||||
}
|
||||
const String kExtensionName = 'ext.flutter.test.interestingExtension';
|
||||
|
||||
final vm_service.Isolate isolate = vm_service.Isolate(
|
||||
id: '1',
|
||||
pauseEvent: vm_service.Event(
|
||||
kind: vm_service.EventKind.kResume,
|
||||
timestamp: 0
|
||||
),
|
||||
breakpoints: <vm_service.Breakpoint>[],
|
||||
exceptionPauseMode: null,
|
||||
libraries: <vm_service.LibraryRef>[
|
||||
vm_service.LibraryRef(
|
||||
id: '1',
|
||||
uri: 'file:///hello_world/main.dart',
|
||||
name: '',
|
||||
),
|
||||
],
|
||||
livePorts: 0,
|
||||
name: 'test',
|
||||
number: '1',
|
||||
pauseOnExit: false,
|
||||
runnable: true,
|
||||
startTime: 0,
|
||||
isSystemIsolate: false,
|
||||
isolateFlags: <vm_service.IsolateFlag>[],
|
||||
extensionRPCs: <String>[kExtensionName],
|
||||
);
|
||||
|
||||
final Map<String, Object> listViews = <String, dynamic>{
|
||||
'type': 'FlutterViewList',
|
||||
'views': <dynamic>[
|
||||
<String, dynamic>{
|
||||
'type': 'FlutterView',
|
||||
'id': '_flutterView/0x4a4c1f8',
|
||||
'isolate': <String, dynamic>{
|
||||
'type': '@Isolate',
|
||||
'fixedId': true,
|
||||
'id': 'isolates/242098474',
|
||||
'name': 'main.dart:main()',
|
||||
'number': 242098474,
|
||||
},
|
||||
},
|
||||
]
|
||||
};
|
||||
final FlutterView fakeFlutterView = FlutterView(
|
||||
id: 'a',
|
||||
uiIsolate: isolate,
|
||||
);
|
||||
|
||||
final FakeVmServiceRequest listViewsRequest = FakeVmServiceRequest(
|
||||
method: kListViewsMethod,
|
||||
jsonResponse: <String, Object>{
|
||||
'views': <Object>[
|
||||
fakeFlutterView.toJson(),
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
typedef ServiceCallback = Future<Map<String, dynamic>> Function(Map<String, Object>);
|
||||
|
||||
@@ -408,17 +403,7 @@ void main() {
|
||||
'views': <Object>[],
|
||||
},
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: kListViewsMethod,
|
||||
jsonResponse: <String, Object>{
|
||||
'views': <Object>[
|
||||
<String, Object>{
|
||||
'id': 'a',
|
||||
'isolate': <String, Object>{},
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
listViewsRequest,
|
||||
]
|
||||
);
|
||||
|
||||
@@ -452,6 +437,187 @@ void main() {
|
||||
expect(fakeVmServiceHost.hasRemainingExpectations, false);
|
||||
});
|
||||
|
||||
group('findExtensionIsolate', () {
|
||||
|
||||
testWithoutContext('returns an isolate with the registered extensionRPC', () async {
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
listViewsRequest,
|
||||
FakeVmServiceRequest(
|
||||
method: 'getIsolate',
|
||||
jsonResponse: isolate.toJson(),
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
},
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamCancel',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
]);
|
||||
|
||||
final vm_service.IsolateRef isolateRef = await fakeVmServiceHost.vmService.findExtensionIsolate(kExtensionName);
|
||||
expect(isolateRef.id, '1');
|
||||
});
|
||||
|
||||
testWithoutContext('returns the isolate with the registered extensionRPC when there are multiple FlutterViews', () async {
|
||||
const String otherExtensionName = 'ext.flutter.test.otherExtension';
|
||||
|
||||
// Copy the other isolate and change a few fields.
|
||||
final vm_service.Isolate isolate2 = vm_service.Isolate.parse(
|
||||
isolate.toJson()
|
||||
..['id'] = '2'
|
||||
..['extensionRPCs'] = <String>[otherExtensionName],
|
||||
);
|
||||
|
||||
final FlutterView fakeFlutterView2 = FlutterView(
|
||||
id: '2',
|
||||
uiIsolate: isolate2,
|
||||
);
|
||||
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: kListViewsMethod,
|
||||
jsonResponse: <String, Object>{
|
||||
'views': <Object>[
|
||||
fakeFlutterView.toJson(),
|
||||
fakeFlutterView2.toJson(),
|
||||
],
|
||||
},
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getIsolate',
|
||||
jsonResponse: isolate.toJson(),
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
},
|
||||
),
|
||||
FakeVmServiceRequest(
|
||||
method: 'getIsolate',
|
||||
jsonResponse: isolate2.toJson(),
|
||||
args: <String, Object>{
|
||||
'isolateId': '2',
|
||||
},
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamCancel',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
]);
|
||||
|
||||
final vm_service.IsolateRef isolateRef = await fakeVmServiceHost.vmService.findExtensionIsolate(otherExtensionName);
|
||||
expect(isolateRef.id, '2');
|
||||
});
|
||||
|
||||
testWithoutContext('when the isolate stream is already subscribed, returns an isolate with the registered extensionRPC', () async {
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
// Stream already subscribed - https://github.com/dart-lang/sdk/blob/master/runtime/vm/service/service.md#streamlisten
|
||||
errorCode: 103,
|
||||
),
|
||||
listViewsRequest,
|
||||
FakeVmServiceRequest(
|
||||
method: 'getIsolate',
|
||||
jsonResponse: isolate.toJson()..['extensionRPCs'] = <String>[kExtensionName],
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
},
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamCancel',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
]);
|
||||
|
||||
final vm_service.IsolateRef isolateRef = await fakeVmServiceHost.vmService.findExtensionIsolate(kExtensionName);
|
||||
expect(isolateRef.id, '1');
|
||||
});
|
||||
|
||||
testWithoutContext('returns an isolate with a extensionRPC that is registered later', () async {
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
listViewsRequest,
|
||||
FakeVmServiceRequest(
|
||||
method: 'getIsolate',
|
||||
jsonResponse: isolate.toJson(),
|
||||
args: <String, Object>{
|
||||
'isolateId': '1',
|
||||
},
|
||||
),
|
||||
FakeVmServiceStreamResponse(
|
||||
streamId: 'Isolate',
|
||||
event: vm_service.Event(
|
||||
kind: vm_service.EventKind.kServiceExtensionAdded,
|
||||
extensionRPC: kExtensionName,
|
||||
timestamp: 1,
|
||||
),
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamCancel',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
]);
|
||||
|
||||
final vm_service.IsolateRef isolateRef = await fakeVmServiceHost.vmService.findExtensionIsolate(kExtensionName);
|
||||
expect(isolateRef.id, '1');
|
||||
});
|
||||
|
||||
testWithoutContext('throws when the service disappears', () async {
|
||||
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamListen',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: kListViewsMethod,
|
||||
errorCode: RPCErrorCodes.kServiceDisappeared,
|
||||
),
|
||||
const FakeVmServiceRequest(
|
||||
method: 'streamCancel',
|
||||
args: <String, Object>{
|
||||
'streamId': 'Isolate',
|
||||
},
|
||||
errorCode: RPCErrorCodes.kServiceDisappeared,
|
||||
),
|
||||
]);
|
||||
|
||||
expect(
|
||||
() => fakeVmServiceHost.vmService.findExtensionIsolate(kExtensionName),
|
||||
throwsA(isA<VmServiceDisappearedException>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testWithoutContext('Can process log events from the vm service', () {
|
||||
final vm_service.Event event = vm_service.Event(
|
||||
bytes: base64.encode(utf8.encode('Hello There\n')),
|
||||
|
||||
Reference in New Issue
Block a user