Unverified Commit f41f7956 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Clean up PollingDeviceDiscovery dispose (#59709)

parent 339f0363
......@@ -179,10 +179,10 @@ class Daemon {
void _send(Map<String, dynamic> map) => sendCommand(map);
void shutdown({ dynamic error }) {
_commandSubscription?.cancel();
Future<void> shutdown({ dynamic error }) async {
await _commandSubscription?.cancel();
for (final Domain domain in _domainMap.values) {
domain.dispose();
await domain.dispose();
}
if (!_onExitCompleter.isCompleted) {
if (error == null) {
......@@ -273,7 +273,7 @@ abstract class Domain {
return val as int;
}
void dispose() { }
Future<void> dispose() async { }
}
/// This domain responds to methods like [version] and [shutdown].
......@@ -351,8 +351,8 @@ class DaemonDomain extends Domain {
}
@override
void dispose() {
_subscription?.cancel();
Future<void> dispose() async {
await _subscription?.cancel();
}
/// Enumerates the platforms supported by the provided project.
......@@ -828,9 +828,9 @@ class DeviceDomain extends Domain {
}
@override
void dispose() {
Future<void> dispose() async {
for (final PollingDeviceDiscovery discoverer in _discoverers) {
discoverer.dispose();
await discoverer.dispose();
}
}
......
......@@ -352,7 +352,7 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
return deviceNotifier.onRemoved;
}
void dispose() => stopPolling();
Future<void> dispose() async => await stopPolling();
@override
String toString() => '$name device discovery';
......
......@@ -43,11 +43,6 @@ class IOSDevices extends PollingDeviceDiscovery {
_logger = logger ?? globals.logger,
super('iOS devices');
@override
void dispose() {
_observedDeviceEventsSubscription?.cancel();
}
final Platform _platform;
final XCDevice _xcdevice;
final IOSWorkflow _iosWorkflow;
......
......@@ -482,6 +482,28 @@ void main() {
expect(rescheduledStream.hasListener, isFalse);
});
testWithoutContext('dispose cancels polling subscription', () async {
final IOSDevices iosDevices = IOSDevices(
platform: macPlatform,
xcdevice: mockXcdevice,
iosWorkflow: mockIosWorkflow,
logger: logger,
);
when(mockXcdevice.isInstalled).thenReturn(true);
when(mockXcdevice.getAvailableIOSDevices())
.thenAnswer((Invocation invocation) => Future<List<IOSDevice>>.value(<IOSDevice>[]));
final StreamController<Map<XCDeviceEvent, String>> eventStream = StreamController<Map<XCDeviceEvent, String>>();
when(mockXcdevice.observedDeviceEvents()).thenAnswer((_) => eventStream.stream);
await iosDevices.startPolling();
expect(iosDevices.deviceNotifier.items, isEmpty);
expect(eventStream.hasListener, isTrue);
await iosDevices.dispose();
expect(eventStream.hasListener, isFalse);
});
final List<Platform> unsupportedPlatforms = <Platform>[linuxPlatform, windowsPlatform];
for (final Platform unsupportedPlatform in unsupportedPlatforms) {
testWithoutContext('pollingGetDevices throws Unsupported Operation exception on ${unsupportedPlatform.operatingSystem}', () async {
......
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