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 { ...@@ -179,10 +179,10 @@ class Daemon {
void _send(Map<String, dynamic> map) => sendCommand(map); void _send(Map<String, dynamic> map) => sendCommand(map);
void shutdown({ dynamic error }) { Future<void> shutdown({ dynamic error }) async {
_commandSubscription?.cancel(); await _commandSubscription?.cancel();
for (final Domain domain in _domainMap.values) { for (final Domain domain in _domainMap.values) {
domain.dispose(); await domain.dispose();
} }
if (!_onExitCompleter.isCompleted) { if (!_onExitCompleter.isCompleted) {
if (error == null) { if (error == null) {
...@@ -273,7 +273,7 @@ abstract class Domain { ...@@ -273,7 +273,7 @@ abstract class Domain {
return val as int; return val as int;
} }
void dispose() { } Future<void> dispose() async { }
} }
/// This domain responds to methods like [version] and [shutdown]. /// This domain responds to methods like [version] and [shutdown].
...@@ -351,8 +351,8 @@ class DaemonDomain extends Domain { ...@@ -351,8 +351,8 @@ class DaemonDomain extends Domain {
} }
@override @override
void dispose() { Future<void> dispose() async {
_subscription?.cancel(); await _subscription?.cancel();
} }
/// Enumerates the platforms supported by the provided project. /// Enumerates the platforms supported by the provided project.
...@@ -828,9 +828,9 @@ class DeviceDomain extends Domain { ...@@ -828,9 +828,9 @@ class DeviceDomain extends Domain {
} }
@override @override
void dispose() { Future<void> dispose() async {
for (final PollingDeviceDiscovery discoverer in _discoverers) { for (final PollingDeviceDiscovery discoverer in _discoverers) {
discoverer.dispose(); await discoverer.dispose();
} }
} }
......
...@@ -352,7 +352,7 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery { ...@@ -352,7 +352,7 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
return deviceNotifier.onRemoved; return deviceNotifier.onRemoved;
} }
void dispose() => stopPolling(); Future<void> dispose() async => await stopPolling();
@override @override
String toString() => '$name device discovery'; String toString() => '$name device discovery';
......
...@@ -43,11 +43,6 @@ class IOSDevices extends PollingDeviceDiscovery { ...@@ -43,11 +43,6 @@ class IOSDevices extends PollingDeviceDiscovery {
_logger = logger ?? globals.logger, _logger = logger ?? globals.logger,
super('iOS devices'); super('iOS devices');
@override
void dispose() {
_observedDeviceEventsSubscription?.cancel();
}
final Platform _platform; final Platform _platform;
final XCDevice _xcdevice; final XCDevice _xcdevice;
final IOSWorkflow _iosWorkflow; final IOSWorkflow _iosWorkflow;
......
...@@ -482,6 +482,28 @@ void main() { ...@@ -482,6 +482,28 @@ void main() {
expect(rescheduledStream.hasListener, isFalse); 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]; final List<Platform> unsupportedPlatforms = <Platform>[linuxPlatform, windowsPlatform];
for (final Platform unsupportedPlatform in unsupportedPlatforms) { for (final Platform unsupportedPlatform in unsupportedPlatforms) {
testWithoutContext('pollingGetDevices throws Unsupported Operation exception on ${unsupportedPlatform.operatingSystem}', () async { 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