Fix concurrent modification error (#48916)

This commit is contained in:
Christopher Fujino 2020-01-23 18:23:03 -08:00 committed by Flutter GitHub Bot
parent da369e9df2
commit 0c2f51fca7
2 changed files with 20 additions and 1 deletions

View File

@ -809,7 +809,8 @@ class _IOSSimulatorDevicePortForwarder extends DevicePortForwarder {
@override
Future<void> dispose() async {
for (final ForwardedPort port in _ports) {
final List<ForwardedPort> portsCopy = List<ForwardedPort>.from(_ports);
for (final ForwardedPort port in portsCopy) {
await unforward(port);
}
}

View File

@ -44,6 +44,24 @@ void main() {
osx.operatingSystem = 'macos';
});
group('_IOSSimulatorDevicePortForwarder', () {
testUsingContext('dispose() does not throw an exception', () async {
final IOSSimulator simulator = IOSSimulator('123');
final DevicePortForwarder portForwarder = simulator.portForwarder;
await portForwarder.forward(123);
await portForwarder.forward(124);
expect(portForwarder.forwardedPorts.length, 2);
try {
await portForwarder.dispose();
} catch (e) {
fail('Encountered exception: $e');
}
expect(portForwarder.forwardedPorts.length, 0);
}, overrides: <Type, Generator>{
Platform: () => osx,
}, testOn: 'posix');
});
group('logFilePath', () {
testUsingContext('defaults to rooted from HOME', () {
osx.environment['HOME'] = '/foo/bar';