Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a40ab895
Unverified
Commit
a40ab895
authored
Aug 15, 2019
by
Zachary Anderson
Committed by
GitHub
Aug 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tool] Observatory connection error handling cleanup (#38353)
parent
f5dcbdab
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
267 additions
and
96 deletions
+267
-96
attach.dart
packages/flutter_tools/lib/src/commands/attach.dart
+2
-0
devices.dart
packages/flutter_tools/lib/src/ios/devices.dart
+54
-53
protocol_discovery.dart
packages/flutter_tools/lib/src/protocol_discovery.dart
+2
-2
attach_test.dart
...lutter_tools/test/general.shard/commands/attach_test.dart
+49
-9
devices_test.dart
...es/flutter_tools/test/general.shard/ios/devices_test.dart
+159
-28
mocks.dart
packages/flutter_tools/test/src/mocks.dart
+1
-4
No files found.
packages/flutter_tools/lib/src/commands/attach.dart
View file @
a40ab895
...
...
@@ -243,6 +243,8 @@ class AttachCommand extends FlutterCommand {
// Determine ipv6 status from the scanned logs.
usesIpv6
=
observatoryDiscovery
.
ipv6
;
printStatus
(
'Done.'
);
// FYI, this message is used as a sentinel in tests.
}
catch
(
error
)
{
throwToolExit
(
'Failed to establish a debug connection with
${device.name}
:
$error
'
);
}
finally
{
await
observatoryDiscovery
?.
cancel
();
}
...
...
packages/flutter_tools/lib/src/ios/devices.dart
View file @
a40ab895
...
...
@@ -152,9 +152,9 @@ class IOSDevice extends Device {
@override
final
String
name
;
Map
<
ApplicationPackage
,
_IOS
DeviceLogReader
>
_logReaders
;
Map
<
ApplicationPackage
,
DeviceLogReader
>
_logReaders
;
_IOS
DevicePortForwarder
_portForwarder
;
DevicePortForwarder
_portForwarder
;
@override
Future
<
bool
>
get
isLocalEmulator
async
=>
false
;
...
...
@@ -342,56 +342,30 @@ class IOSDevice extends Device {
if
(
platformArgs
[
'trace-startup'
]
??
false
)
launchArguments
.
add
(
'--trace-startup'
);
int
installationResult
=
-
1
;
Uri
localObservatoryUri
;
final
Status
installStatus
=
logger
.
startProgress
(
'Installing and launching...'
,
timeout:
timeoutConfiguration
.
slowOperation
);
if
(!
debuggingOptions
.
debuggingEnabled
)
{
// If debugging is not enabled, just launch the application and continue.
printTrace
(
'Debugging is not enabled'
);
installationResult
=
await
const
IOSDeploy
().
runApp
(
deviceId:
id
,
bundlePath:
bundle
.
path
,
launchArguments:
launchArguments
,
);
}
else
{
final
Status
installStatus
=
logger
.
startProgress
(
'Installing and launching...'
,
timeout:
timeoutConfiguration
.
slowOperation
);
try
{
ProtocolDiscovery
observatoryDiscovery
;
if
(
debuggingOptions
.
debuggingEnabled
)
{
// Debugging is enabled, look for the observatory server port post launch.
printTrace
(
'Debugging is enabled, connecting to observatory'
);
// TODO(danrubel): The Android device class does something similar to this code below.
// The various Device subclasses should be refactored and common code moved into the superclass.
final
ProtocolDiscovery
observatoryDiscovery
=
ProtocolDiscovery
.
observatory
(
observatoryDiscovery
=
ProtocolDiscovery
.
observatory
(
getLogReader
(
app:
package
),
portForwarder:
portForwarder
,
hostPort:
debuggingOptions
.
observatoryPort
,
ipv6:
ipv6
,
);
}
final
Future
<
Uri
>
forwardObservatoryUri
=
observatoryDiscovery
.
uri
;
final
Future
<
int
>
launch
=
const
IOSDeploy
().
runApp
(
final
int
installationResult
=
await
const
IOSDeploy
().
runApp
(
deviceId:
id
,
bundlePath:
bundle
.
path
,
launchArguments:
launchArguments
,
);
localObservatoryUri
=
await
launch
.
then
<
Uri
>((
int
result
)
async
{
installationResult
=
result
;
if
(
result
!=
0
)
{
printTrace
(
'Failed to launch the application on device.'
);
return
null
;
}
printTrace
(
'Application launched on the device. Waiting for observatory port.'
);
return
await
forwardObservatoryUri
;
}).
whenComplete
(()
{
observatoryDiscovery
.
cancel
();
});
}
installStatus
.
stop
();
if
(
installationResult
!=
0
)
{
printError
(
'Could not install
${bundle.path}
on
$id
.'
);
printError
(
'Try launching Xcode and selecting "Product > Run" to fix the problem:'
);
...
...
@@ -400,7 +374,23 @@ class IOSDevice extends Device {
return
LaunchResult
.
failed
();
}
return
LaunchResult
.
succeeded
(
observatoryUri:
localObservatoryUri
);
if
(!
debuggingOptions
.
debuggingEnabled
)
{
return
LaunchResult
.
succeeded
();
}
try
{
printTrace
(
'Application launched on the device. Waiting for observatory port.'
);
final
Uri
localUri
=
await
observatoryDiscovery
.
uri
;
return
LaunchResult
.
succeeded
(
observatoryUri:
localUri
);
}
catch
(
error
)
{
printError
(
'Failed to establish a debug connection with
$id
:
$error
'
);
return
LaunchResult
.
failed
();
}
finally
{
await
observatoryDiscovery
?.
cancel
();
}
}
finally
{
installStatus
.
stop
();
}
}
@override
...
...
@@ -417,13 +407,24 @@ class IOSDevice extends Device {
@override
DeviceLogReader
getLogReader
({
ApplicationPackage
app
})
{
_logReaders
??=
<
ApplicationPackage
,
_IOS
DeviceLogReader
>{};
_logReaders
??=
<
ApplicationPackage
,
DeviceLogReader
>{};
return
_logReaders
.
putIfAbsent
(
app
,
()
=>
_IOSDeviceLogReader
(
this
,
app
));
}
@visibleForTesting
void
setLogReader
(
ApplicationPackage
app
,
DeviceLogReader
logReader
)
{
_logReaders
??=
<
ApplicationPackage
,
DeviceLogReader
>{};
_logReaders
[
app
]
=
logReader
;
}
@override
DevicePortForwarder
get
portForwarder
=>
_portForwarder
??=
_IOSDevicePortForwarder
(
this
);
@visibleForTesting
set
portForwarder
(
DevicePortForwarder
forwarder
)
{
_portForwarder
=
forwarder
;
}
@override
void
clearLogs
()
{
}
...
...
packages/flutter_tools/lib/src/protocol_discovery.dart
View file @
a40ab895
...
...
@@ -65,9 +65,9 @@ class ProtocolDiscovery {
if
(
match
!=
null
)
{
try
{
uri
=
Uri
.
parse
(
match
[
1
]);
}
catch
(
error
)
{
}
catch
(
error
,
stackTrace
)
{
_stopScrapingLogs
();
_completer
.
completeError
(
error
);
_completer
.
completeError
(
error
,
stackTrace
);
}
}
...
...
packages/flutter_tools/test/general.shard/commands/attach_test.dart
View file @
a40ab895
...
...
@@ -52,15 +52,6 @@ void main() {
mockLogReader
=
MockDeviceLogReader
();
portForwarder
=
MockPortForwarder
();
device
=
MockAndroidDevice
();
when
(
device
.
getLogReader
()).
thenAnswer
((
_
)
{
// Now that the reader is used, start writing messages to it.
Timer
.
run
(()
{
mockLogReader
.
addLine
(
'Foo'
);
mockLogReader
.
addLine
(
'Observatory listening on http://127.0.0.1:
$devicePort
'
);
});
return
mockLogReader
;
});
when
(
device
.
portForwarder
)
.
thenReturn
(
portForwarder
);
when
(
portForwarder
.
forward
(
devicePort
,
hostPort:
anyNamed
(
'hostPort'
)))
...
...
@@ -82,6 +73,14 @@ void main() {
});
testUsingContext
(
'finds observatory port and forwards'
,
()
async
{
when
(
device
.
getLogReader
()).
thenAnswer
((
_
)
{
// Now that the reader is used, start writing messages to it.
Timer
.
run
(()
{
mockLogReader
.
addLine
(
'Foo'
);
mockLogReader
.
addLine
(
'Observatory listening on http://127.0.0.1:
$devicePort
'
);
});
return
mockLogReader
;
});
testDeviceManager
.
addDevice
(
device
);
final
Completer
<
void
>
completer
=
Completer
<
void
>();
final
StreamSubscription
<
String
>
loggerSubscription
=
logger
.
stream
.
listen
((
String
message
)
{
...
...
@@ -102,7 +101,32 @@ void main() {
Logger:
()
=>
logger
,
});
testUsingContext
(
'Fails with tool exit on bad Observatory uri'
,
()
async
{
when
(
device
.
getLogReader
()).
thenAnswer
((
_
)
{
// Now that the reader is used, start writing messages to it.
Timer
.
run
(()
{
mockLogReader
.
addLine
(
'Foo'
);
mockLogReader
.
addLine
(
'Observatory listening on http:/:/127.0.0.1:
$devicePort
'
);
});
return
mockLogReader
;
});
testDeviceManager
.
addDevice
(
device
);
expect
(
createTestCommandRunner
(
AttachCommand
()).
run
(<
String
>[
'attach'
]),
throwsA
(
isA
<
ToolExit
>()));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
testFileSystem
,
Logger:
()
=>
logger
,
});
testUsingContext
(
'accepts filesystem parameters'
,
()
async
{
when
(
device
.
getLogReader
()).
thenAnswer
((
_
)
{
// Now that the reader is used, start writing messages to it.
Timer
.
run
(()
{
mockLogReader
.
addLine
(
'Foo'
);
mockLogReader
.
addLine
(
'Observatory listening on http://127.0.0.1:
$devicePort
'
);
});
return
mockLogReader
;
});
testDeviceManager
.
addDevice
(
device
);
const
String
filesystemScheme
=
'foo'
;
...
...
@@ -175,6 +199,14 @@ void main() {
});
testUsingContext
(
'exits when ipv6 is specified and debug-port is not'
,
()
async
{
when
(
device
.
getLogReader
()).
thenAnswer
((
_
)
{
// Now that the reader is used, start writing messages to it.
Timer
.
run
(()
{
mockLogReader
.
addLine
(
'Foo'
);
mockLogReader
.
addLine
(
'Observatory listening on http://127.0.0.1:
$devicePort
'
);
});
return
mockLogReader
;
});
testDeviceManager
.
addDevice
(
device
);
final
AttachCommand
command
=
AttachCommand
();
...
...
@@ -190,6 +222,14 @@ void main() {
},);
testUsingContext
(
'exits when observatory-port is specified and debug-port is not'
,
()
async
{
when
(
device
.
getLogReader
()).
thenAnswer
((
_
)
{
// Now that the reader is used, start writing messages to it.
Timer
.
run
(()
{
mockLogReader
.
addLine
(
'Foo'
);
mockLogReader
.
addLine
(
'Observatory listening on http://127.0.0.1:
$devicePort
'
);
});
return
mockLogReader
;
});
testDeviceManager
.
addDevice
(
device
);
final
AttachCommand
command
=
AttachCommand
();
...
...
packages/flutter_tools/test/general.shard/ios/devices_test.dart
View file @
a40ab895
This diff is collapsed.
Click to expand it.
packages/flutter_tools/test/src/mocks.dart
View file @
a40ab895
...
...
@@ -153,7 +153,7 @@ ro.build.version.codename=REL
typedef
ProcessFactory
=
Process
Function
(
List
<
String
>
command
);
/// A ProcessManager that starts Processes by delegating to a ProcessFactory.
class
MockProcessManager
implements
ProcessManager
{
class
MockProcessManager
extends
Mock
implements
ProcessManager
{
ProcessFactory
processFactory
=
(
List
<
String
>
commands
)
=>
MockProcess
();
bool
canRunSucceeds
=
true
;
bool
runSucceeds
=
true
;
...
...
@@ -180,9 +180,6 @@ class MockProcessManager implements ProcessManager {
commands
=
command
;
return
Future
<
Process
>.
value
(
processFactory
(
command
));
}
@override
dynamic
noSuchMethod
(
Invocation
invocation
)
=>
null
;
}
/// A process that exits successfully with no output and ignores all input.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment