Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
4511e0c9
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4511e0c9
编写于
2月 09, 2016
作者:
J
John McCutchan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add heart beat integration tests for Observatory in sky_shell
上级
8a701198
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
274 addition
and
0 deletion
+274
-0
sky/shell/testing/observatory/empty_main.dart
sky/shell/testing/observatory/empty_main.dart
+6
-0
sky/shell/testing/observatory/launcher.dart
sky/shell/testing/observatory/launcher.dart
+65
-0
sky/shell/testing/observatory/service_client.dart
sky/shell/testing/observatory/service_client.dart
+63
-0
sky/shell/testing/observatory/test.dart
sky/shell/testing/observatory/test.dart
+131
-0
travis/test_observatory.sh
travis/test_observatory.sh
+9
-0
未找到文件。
sky/shell/testing/observatory/empty_main.dart
0 → 100644
浏览文件 @
4511e0c9
// 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.
main
()
{
}
sky/shell/testing/observatory/launcher.dart
0 → 100644
浏览文件 @
4511e0c9
// 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.
library
observatory_sky_shell_launcher
;
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:io'
;
class
ShellProcess
{
final
Completer
_observatoryUriCompleter
=
new
Completer
();
final
Process
_process
;
ShellProcess
(
this
.
_process
)
{
assert
(
_process
!=
null
);
// Scan stdout and scrape the Observatory Uri.
_process
.
stdout
.
transform
(
UTF8
.
decoder
)
.
transform
(
new
LineSplitter
()).
listen
((
line
)
{
const
String
observatoryUriPrefix
=
'Observatory listening on '
;
if
(
line
.
startsWith
(
observatoryUriPrefix
))
{
Uri
uri
=
Uri
.
parse
(
line
.
substring
(
observatoryUriPrefix
.
length
));
_observatoryUriCompleter
.
complete
(
uri
);
}
});
}
Future
kill
()
async
{
if
(
_process
==
null
)
{
return
false
;
}
return
_process
.
kill
();
}
Future
<
Uri
>
waitForObservatory
()
async
{
return
_observatoryUriCompleter
.
future
;
}
}
class
ShellLauncher
{
final
List
<
String
>
args
=
[
'--observatory-port=0'
,
];
final
String
shellExecutablePath
;
final
String
mainDartPath
;
ShellLauncher
(
this
.
shellExecutablePath
,
this
.
mainDartPath
,
List
<
String
>
extraArgs
)
{
if
(
extraArgs
is
List
)
{
args
.
addAll
(
extraArgs
);
}
args
.
add
(
mainDartPath
);
}
Future
<
ShellProcess
>
launch
()
async
{
try
{
var
process
=
await
Process
.
start
(
shellExecutablePath
,
args
);
return
new
ShellProcess
(
process
);
}
catch
(
e
)
{
print
(
'Error launching shell:
$e
'
);
}
return
null
;
}
}
sky/shell/testing/observatory/service_client.dart
0 → 100644
浏览文件 @
4511e0c9
// 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.
library
observatory_sky_shell_service_client
;
import
'dart:async'
;
import
'dart:convert'
;
class
ServiceClient
{
ServiceClient
(
this
.
client
)
{
client
.
listen
(
_onData
,
onError:
_onError
,
cancelOnError:
true
);
}
Future
<
Map
>
invokeRPC
(
String
method
,
[
Map
params
])
async
{
var
key
=
_createKey
();
var
request
=
JSON
.
encode
({
'jsonrpc'
:
'2.0'
,
'method'
:
method
,
'params'
:
params
==
null
?
{}
:
params
,
'id'
:
key
,
});
client
.
add
(
request
);
var
completer
=
new
Completer
();
_outstanding_requests
[
key
]
=
completer
;
print
(
'->
$key
(
$method
)'
);
return
completer
.
future
;
}
String
_createKey
()
{
var
key
=
'
$_id
'
;
_id
++;
return
key
;
}
void
_onData
(
String
message
)
{
var
response
=
JSON
.
decode
(
message
);
var
key
=
response
[
'id'
];
print
(
'<-
$key
'
);
var
completer
=
_outstanding_requests
.
remove
(
key
);
assert
(
completer
!=
null
);
var
result
=
response
[
'result'
];
var
error
=
response
[
'error'
];
if
(
error
!=
null
)
{
assert
(
result
==
null
);
completer
.
completeError
(
error
);
}
else
{
assert
(
result
!=
null
);
completer
.
complete
(
result
);
}
}
void
_onError
(
error
)
{
print
(
'WebSocket error:
$error
'
);
}
final
WebSocket
client
;
final
Map
<
String
,
Completer
>
_outstanding_requests
=
<
String
,
Completer
>{};
var
_id
=
1
;
}
sky/shell/testing/observatory/test.dart
0 → 100644
浏览文件 @
4511e0c9
// 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.
// This is a minimal dependency heart beat test for Observatory.
import
'dart:async'
;
import
'dart:convert'
;
import
'dart:io'
;
import
'launcher.dart'
;
import
'service_client.dart'
;
class
Expect
{
static
equals
(
dynamic
actual
,
dynamic
expected
)
{
if
(
actual
!=
expected
)
{
throw
'Expected
$actual
==
$expected
'
;
}
}
static
contains
(
String
needle
,
String
haystack
)
{
if
(!
haystack
.
contains
(
needle
))
{
throw
'Expected
$haystack
to contain
$needle
'
;
}
}
static
isTrue
(
bool
tf
)
{
if
(
tf
!=
true
)
{
throw
'Expected
$a
to be true'
;
}
}
static
isFalse
(
bool
tf
)
{
if
(
tf
!=
false
)
{
throw
'Expected
$a
to be false'
;
}
}
static
notExecuted
()
{
throw
'Should not have hit'
;
}
static
isNotNull
(
dynamic
a
)
{
if
(
a
==
null
)
{
throw
'Expected
$a
to not be null'
;
}
}
}
Future
<
String
>
readResponse
(
HttpClientResponse
response
)
{
var
completer
=
new
Completer
();
var
contents
=
new
StringBuffer
();
response
.
transform
(
UTF8
.
decoder
).
listen
((
String
data
)
{
contents
.
write
(
data
);
},
onDone:
()
=>
completer
.
complete
(
contents
.
toString
()));
return
completer
.
future
;
}
// Test accessing the service protocol over http.
Future
testHttpProtocolRequest
(
Uri
uri
)
async
{
uri
=
uri
.
replace
(
path:
'getVM'
);
HttpClient
client
=
new
HttpClient
();
HttpClientRequest
request
=
await
client
.
getUrl
(
uri
);
HttpClientResponse
response
=
await
request
.
close
();
Expect
.
equals
(
response
.
statusCode
,
200
);
Map
responseAsMap
=
JSON
.
decode
(
await
readResponse
(
response
));
Expect
.
equals
(
responseAsMap
[
'jsonrpc'
],
"2.0"
);
client
.
close
();
}
// Test accessing the service protocol over ws.
Future
testWebSocketProtocolRequest
(
Uri
uri
)
async
{
uri
=
uri
.
replace
(
scheme:
'ws'
,
path:
'ws'
);
WebSocket
webSocketClient
=
await
WebSocket
.
connect
(
uri
.
toString
());
ServiceClient
serviceClient
=
new
ServiceClient
(
webSocketClient
);
Map
response
=
await
serviceClient
.
invokeRPC
(
'getVM'
);
Expect
.
equals
(
response
[
'type'
],
'VM'
);
try
{
await
serviceClient
.
invokeRPC
(
'BART_SIMPSON'
);
Expect
.
notExecuted
();
}
catch
(
e
)
{
// Method not found.
Expect
.
equals
(
e
[
'code'
],
-
32601
);
}
}
// Test accessing an Observatory UI asset.
Future
testHttpAssetRequest
(
Uri
uri
)
async
{
uri
=
uri
.
replace
(
path:
'third_party/trace_viewer_full.html'
);
HttpClient
client
=
new
HttpClient
();
HttpClientRequest
request
=
await
client
.
getUrl
(
uri
);
HttpClientResponse
response
=
await
request
.
close
();
Expect
.
equals
(
response
.
statusCode
,
200
);
await
response
.
drain
();
client
.
close
();
}
typedef
Future
TestFunction
(
Uri
uri
);
final
List
<
TestFunction
>
tests
=
[
testHttpProtocolRequest
,
testWebSocketProtocolRequest
,
testHttpAssetRequest
];
main
(
List
<
String
>
args
)
async
{
if
(
args
.
length
<
2
)
{
print
(
'Usage: dart
${Platform.script}
'
'<sky_shell_executable> <main_dart> ...'
);
return
;
}
final
String
shellExecutablePath
=
args
[
0
];
final
String
mainDartPath
=
args
[
1
];
final
List
<
String
>
extraArgs
=
args
.
length
<=
2
?
[]
:
args
.
sublist
(
2
);
ShellLauncher
launcher
=
new
ShellLauncher
(
shellExecutablePath
,
mainDartPath
,
extraArgs
);
ShellProcess
process
=
await
launcher
.
launch
();
Uri
uri
=
await
process
.
waitForObservatory
();
try
{
for
(
var
i
=
0
;
i
<
tests
.
length
;
i
++)
{
print
(
'Executing test
${i+1}
/
${tests.length}
'
);
await
tests
[
i
](
uri
);
}
}
catch
(
e
)
{
print
(
'Observatory test failure:
$e
'
);
exitCode
=
-
1
;
}
await
process
.
kill
();
}
travis/test_observatory.sh
0 → 100644
浏览文件 @
4511e0c9
echo
"Testing sky_shell Observatory..."
PATH
=
"
$HOME
/depot_tools:
$PATH
"
SKY_SHELL_BIN
=
out/Debug/sky_shell
OBSERVATORY_TEST
=
sky/shell/testing/observatory/test.dart
EMPTY_MAIN
=
sky/shell/testing/observatory/empty_main.dart
dart
$OBSERVATORY_TEST
$SKY_SHELL_BIN
$EMPTY_MAIN
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录