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
bd430081
Unverified
Commit
bd430081
authored
May 14, 2020
by
Jenn Magder
Committed by
GitHub
May 14, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make initial daemon devices population fast (#56959)
parent
f66d3c5a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
10 deletions
+33
-10
device.dart
packages/flutter_tools/lib/src/device.dart
+6
-4
daemon_test.dart
...utter_tools/test/commands.shard/hermetic/daemon_test.dart
+2
-2
device_test.dart
packages/flutter_tools/test/general.shard/device_test.dart
+23
-2
mocks.dart
packages/flutter_tools/test/src/mocks.dart
+2
-2
No files found.
packages/flutter_tools/lib/src/device.dart
View file @
bd430081
...
...
@@ -297,19 +297,21 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
void
startPolling
()
{
if
(
_timer
==
null
)
{
_items
??=
ItemListNotifier
<
Device
>();
_timer
=
_initTimer
();
// Make initial population the default, fast polling timeout.
_timer
=
_initTimer
(
null
);
}
}
Timer
_initTimer
()
{
Timer
_initTimer
(
Duration
pollingTimeout
)
{
return
Timer
(
_pollingInterval
,
()
async
{
try
{
final
List
<
Device
>
devices
=
await
pollingGetDevices
(
timeout:
_
pollingTimeout
);
final
List
<
Device
>
devices
=
await
pollingGetDevices
(
timeout:
pollingTimeout
);
_items
.
updateWithNewList
(
devices
);
}
on
TimeoutException
{
globals
.
printTrace
(
'Device poll timed out. Will retry.'
);
}
_timer
=
_initTimer
();
// Subsequent timeouts after initial population should wait longer.
_timer
=
_initTimer
(
_pollingTimeout
);
});
}
...
...
packages/flutter_tools/test/commands.shard/hermetic/daemon_test.dart
View file @
bd430081
...
...
@@ -194,7 +194,7 @@ void main() {
responses
.
add
,
notifyingLogger:
notifyingLogger
,
);
final
MockPollingDeviceDiscovery
discoverer
=
Mock
PollingDeviceDiscovery
();
final
FakePollingDeviceDiscovery
discoverer
=
Fake
PollingDeviceDiscovery
();
daemon
.
deviceDomain
.
addDeviceDiscoverer
(
discoverer
);
discoverer
.
addDevice
(
MockAndroidDevice
());
commands
.
add
(<
String
,
dynamic
>{
'id'
:
0
,
'method'
:
'device.getDevices'
});
...
...
@@ -216,7 +216,7 @@ void main() {
notifyingLogger:
notifyingLogger
,
);
final
MockPollingDeviceDiscovery
discoverer
=
Mock
PollingDeviceDiscovery
();
final
FakePollingDeviceDiscovery
discoverer
=
Fake
PollingDeviceDiscovery
();
daemon
.
deviceDomain
.
addDeviceDiscoverer
(
discoverer
);
discoverer
.
addDevice
(
MockAndroidDevice
());
...
...
packages/flutter_tools/test/general.shard/device_test.dart
View file @
bd430081
...
...
@@ -9,6 +9,7 @@ import 'package:flutter_tools/src/device.dart';
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:quiver/testing/async.dart'
;
import
'../src/common.dart'
;
import
'../src/context.dart'
;
...
...
@@ -63,6 +64,26 @@ void main() {
});
});
group
(
'PollingDeviceDiscovery'
,
()
{
testUsingContext
(
'startPolling'
,
()
async
{
FakeAsync
().
run
((
FakeAsync
time
)
{
final
FakePollingDeviceDiscovery
pollingDeviceDiscovery
=
FakePollingDeviceDiscovery
();
pollingDeviceDiscovery
.
startPolling
();
time
.
elapse
(
const
Duration
(
milliseconds:
4001
));
time
.
flushMicrotasks
();
// First check should use the default polling timeout
// to quickly populate the list.
expect
(
pollingDeviceDiscovery
.
lastPollingTimeout
,
isNull
);
time
.
elapse
(
const
Duration
(
milliseconds:
4001
));
time
.
flushMicrotasks
();
// Subsequent polling should be much longer.
expect
(
pollingDeviceDiscovery
.
lastPollingTimeout
,
const
Duration
(
seconds:
30
));
pollingDeviceDiscovery
.
stopPolling
();
});
});
});
group
(
'Filter devices'
,
()
{
FakeDevice
ephemeral
;
FakeDevice
nonEphemeralOne
;
...
...
@@ -198,12 +219,12 @@ void main() {
class
TestDeviceManager
extends
DeviceManager
{
TestDeviceManager
(
List
<
Device
>
allDevices
)
{
_deviceDiscoverer
=
Mock
PollingDeviceDiscovery
();
_deviceDiscoverer
=
Fake
PollingDeviceDiscovery
();
resetDevices
(
allDevices
);
}
@override
List
<
DeviceDiscovery
>
get
deviceDiscoverers
=>
<
DeviceDiscovery
>[
_deviceDiscoverer
];
Mock
PollingDeviceDiscovery
_deviceDiscoverer
;
Fake
PollingDeviceDiscovery
_deviceDiscoverer
;
void
resetDevices
(
List
<
Device
>
allDevices
)
{
_deviceDiscoverer
.
setDevices
(
allDevices
);
...
...
packages/flutter_tools/test/src/mocks.dart
View file @
bd430081
...
...
@@ -482,8 +482,8 @@ class MockStdio extends Stdio {
List
<
String
>
get
writtenToStderr
=>
_stderr
.
writes
.
map
<
String
>(
_stderr
.
encoding
.
decode
).
toList
();
}
class
Mock
PollingDeviceDiscovery
extends
PollingDeviceDiscovery
{
Mock
PollingDeviceDiscovery
()
:
super
(
'mock'
);
class
Fake
PollingDeviceDiscovery
extends
PollingDeviceDiscovery
{
Fake
PollingDeviceDiscovery
()
:
super
(
'mock'
);
final
List
<
Device
>
_devices
=
<
Device
>[];
final
StreamController
<
Device
>
_onAddedController
=
StreamController
<
Device
>.
broadcast
();
...
...
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