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
9cb7001a
Commit
9cb7001a
authored
Mar 04, 2016
by
John McCutchan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ServiceProtocolDiscovery
parent
96a0e7cb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
133 additions
and
0 deletions
+133
-0
service_protocol.dart
packages/flutter_tools/lib/src/service_protocol.dart
+52
-0
service_protocol_test.dart
packages/flutter_tools/test/service_protocol_test.dart
+47
-0
mocks.dart
packages/flutter_tools/test/src/mocks.dart
+34
-0
No files found.
packages/flutter_tools/lib/src/service_protocol.dart
0 → 100644
View file @
9cb7001a
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'device.dart'
;
/// Discover service protocol ports on devices.
class
ServiceProtocolDiscovery
{
/// [logReader] A [DeviceLogReader] to look for Observatory messages in.
ServiceProtocolDiscovery
(
DeviceLogReader
logReader
)
:
_logReader
=
logReader
{
assert
(
_logReader
!=
null
);
if
(!
_logReader
.
isReading
)
_logReader
.
start
();
_logReader
.
lines
.
listen
(
_onLine
);
}
final
DeviceLogReader
_logReader
;
Completer
_completer
=
new
Completer
();
/// The [Future] returned by this function will complete when the next
/// service protocol port is found.
Future
<
int
>
nextPort
()
{
return
_completer
.
future
;
}
void
_onLine
(
String
line
)
{
int
portNumber
=
0
;
if
(
line
.
startsWith
(
'Observatory listening on http://'
))
{
try
{
RegExp
portExp
=
new
RegExp
(
r"\d+.\d+.\d+.\d+:(\d+)"
);
var
port
=
portExp
.
firstMatch
(
line
).
group
(
1
);
portNumber
=
int
.
parse
(
port
);
}
catch
(
_
)
{
// Ignore errors.
}
}
if
(
portNumber
!=
0
)
{
_located
(
portNumber
);
}
}
void
_located
(
int
port
)
{
assert
(
_completer
!=
null
);
assert
(!
_completer
.
isCompleted
);
_completer
.
complete
(
port
);
_completer
=
new
Completer
();
}
}
packages/flutter_tools/test/service_protocol_test.dart
0 → 100644
View file @
9cb7001a
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'package:test/test.dart'
;
import
'package:flutter_tools/src/service_protocol.dart'
;
import
'src/mocks.dart'
;
main
()
=>
defineTests
();
defineTests
()
{
group
(
'service_protocol'
,
()
{
test
(
'Discovery Heartbeat'
,
()
async
{
MockDeviceLogReader
logReader
=
new
MockDeviceLogReader
();
ServiceProtocolDiscovery
discoverer
=
new
ServiceProtocolDiscovery
(
logReader
);
// Get next port future.
Future
nextPort
=
discoverer
.
nextPort
();
expect
(
nextPort
,
isNotNull
);
// Inject some lines.
logReader
.
addLine
(
'HELLO WORLD'
);
logReader
.
addLine
(
'Observatory listening on http://127.0.0.1:9999'
);
// Await the port.
expect
(
await
nextPort
,
9999
);
// Get next port future.
nextPort
=
discoverer
.
nextPort
();
logReader
.
addLine
(
'Observatory listening on http://127.0.0.1:3333'
);
expect
(
await
nextPort
,
3333
);
// Get next port future.
nextPort
=
discoverer
.
nextPort
();
// Inject some bad lines.
logReader
.
addLine
(
'Observatory listening on http://127.0.0.1'
);
logReader
.
addLine
(
'Observatory listening on http://127.0.0.1:'
);
logReader
.
addLine
(
'Observatory listening on http://127.0.0.1:apple'
);
int
port
=
await
nextPort
.
timeout
(
const
Duration
(
milliseconds:
100
),
onTimeout:
()
=>
77
);
// Expect the timeout port.
expect
(
port
,
77
);
});
});
}
packages/flutter_tools/test/src/mocks.dart
View file @
9cb7001a
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// found in the LICENSE file.
import
'dart:async'
;
import
'package:flutter_tools/src/android/android_device.dart'
;
import
'package:flutter_tools/src/android/android_device.dart'
;
import
'package:flutter_tools/src/application_package.dart'
;
import
'package:flutter_tools/src/application_package.dart'
;
import
'package:flutter_tools/src/build_configuration.dart'
;
import
'package:flutter_tools/src/build_configuration.dart'
;
...
@@ -51,6 +52,39 @@ class MockDeviceStore extends DeviceStore {
...
@@ -51,6 +52,39 @@ class MockDeviceStore extends DeviceStore {
iOSSimulator:
new
MockIOSSimulator
());
iOSSimulator:
new
MockIOSSimulator
());
}
}
class
MockDeviceLogReader
extends
DeviceLogReader
{
String
get
name
=>
'MockLogReader'
;
final
StreamController
<
String
>
_linesStreamController
=
new
StreamController
<
String
>.
broadcast
();
final
Completer
_finishedCompleter
=
new
Completer
();
Stream
<
String
>
get
lines
=>
_linesStreamController
.
stream
;
void
addLine
(
String
line
)
{
_linesStreamController
.
add
(
line
);
}
bool
_started
=
false
;
Future
start
()
{
assert
(!
_started
);
_started
=
true
;
return
new
Future
.
value
(
this
);
}
bool
get
isReading
=>
_started
;
Future
stop
()
{
assert
(
_started
);
_started
=
false
;
return
new
Future
.
value
(
this
);
}
Future
get
finished
=>
_finishedCompleter
.
future
;
}
void
applyMocksToCommand
(
FlutterCommand
command
)
{
void
applyMocksToCommand
(
FlutterCommand
command
)
{
command
command
..
applicationPackages
=
new
MockApplicationPackageStore
()
..
applicationPackages
=
new
MockApplicationPackageStore
()
...
...
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