Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
fc7f5753
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fc7f5753
编写于
9月 27, 2019
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ipc - add tests for channel proxy
上级
fa9c39ae
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
123 addition
and
8 deletion
+123
-8
src/vs/base/parts/ipc/test/node/ipc.test.ts
src/vs/base/parts/ipc/test/node/ipc.test.ts
+123
-8
未找到文件。
src/vs/base/parts/ipc/test/node/ipc.test.ts
浏览文件 @
fc7f5753
...
...
@@ -10,6 +10,9 @@ import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cance
import
{
canceled
}
from
'
vs/base/common/errors
'
;
import
{
timeout
}
from
'
vs/base/common/async
'
;
import
{
VSBuffer
}
from
'
vs/base/common/buffer
'
;
import
{
createChannelSender
,
createChannelReceiver
}
from
'
vs/base/parts/ipc/node/ipcChannelCreator
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
isEqual
}
from
'
vs/base/common/resources
'
;
class
QueueProtocol
implements
IMessagePassingProtocol
{
...
...
@@ -101,14 +104,16 @@ interface ITestService {
neverComplete
():
Promise
<
void
>
;
neverCompleteCT
(
cancellationToken
:
CancellationToken
):
Promise
<
void
>
;
buffersLength
(
buffers
:
Buffer
[]):
Promise
<
number
>
;
marshall
(
uri
:
URI
):
Promise
<
URI
>
;
context
():
Promise
<
unknown
>
;
p
ong
:
Event
<
string
>
;
onP
ong
:
Event
<
string
>
;
}
class
TestService
implements
ITestService
{
private
readonly
_
p
ong
=
new
Emitter
<
string
>
();
readonly
pong
=
this
.
_p
ong
.
event
;
private
readonly
_
onP
ong
=
new
Emitter
<
string
>
();
readonly
onPong
=
this
.
_onP
ong
.
event
;
marco
():
Promise
<
string
>
{
return
Promise
.
resolve
(
'
polo
'
);
...
...
@@ -135,7 +140,15 @@ class TestService implements ITestService {
}
ping
(
msg
:
string
):
void
{
this
.
_pong
.
fire
(
msg
);
this
.
_onPong
.
fire
(
msg
);
}
marshall
(
uri
:
URI
):
Promise
<
URI
>
{
return
Promise
.
resolve
(
uri
);
}
context
(
context
?:
unknown
):
Promise
<
unknown
>
{
return
Promise
.
resolve
(
context
);
}
}
...
...
@@ -156,7 +169,7 @@ class TestChannel implements IServerChannel {
listen
(
_
:
unknown
,
event
:
string
,
arg
?:
any
):
Event
<
any
>
{
switch
(
event
)
{
case
'
pong
'
:
return
this
.
service
.
p
ong
;
case
'
onPong
'
:
return
this
.
service
.
onP
ong
;
default
:
throw
new
Error
(
'
not implemented
'
);
}
}
...
...
@@ -164,8 +177,8 @@ class TestChannel implements IServerChannel {
class
TestChannelClient
implements
ITestService
{
get
p
ong
():
Event
<
string
>
{
return
this
.
channel
.
listen
(
'
p
ong
'
);
get
onP
ong
():
Event
<
string
>
{
return
this
.
channel
.
listen
(
'
onP
ong
'
);
}
constructor
(
private
channel
:
IChannel
)
{
}
...
...
@@ -189,6 +202,14 @@ class TestChannelClient implements ITestService {
buffersLength
(
buffers
:
Buffer
[]):
Promise
<
number
>
{
return
this
.
channel
.
call
(
'
buffersLength
'
,
buffers
);
}
marshall
(
uri
:
URI
):
Promise
<
URI
>
{
return
this
.
channel
.
call
(
'
marshall
'
,
uri
);
}
context
():
Promise
<
unknown
>
{
return
this
.
channel
.
call
(
'
context
'
);
}
}
suite
(
'
Base IPC
'
,
function
()
{
...
...
@@ -281,7 +302,7 @@ suite('Base IPC', function () {
test
(
'
listen to events
'
,
async
function
()
{
const
messages
:
string
[]
=
[];
ipcService
.
p
ong
(
msg
=>
messages
.
push
(
msg
));
ipcService
.
onP
ong
(
msg
=>
messages
.
push
(
msg
));
await
timeout
(
0
);
assert
.
deepEqual
(
messages
,
[]);
...
...
@@ -300,4 +321,98 @@ suite('Base IPC', function () {
return
assert
.
equal
(
r
,
5
);
});
});
suite
(
'
one to one (proxy)
'
,
function
()
{
let
server
:
IPCServer
;
let
client
:
IPCClient
;
let
service
:
TestService
;
let
ipcService
:
ITestService
;
setup
(
function
()
{
service
=
new
TestService
();
const
testServer
=
new
TestIPCServer
();
server
=
testServer
;
server
.
registerChannel
(
TestChannelId
,
createChannelReceiver
(
service
));
client
=
testServer
.
createConnection
(
'
client1
'
);
ipcService
=
createChannelSender
(
client
.
getChannel
(
TestChannelId
));
});
teardown
(
function
()
{
client
.
dispose
();
server
.
dispose
();
});
test
(
'
call success
'
,
async
function
()
{
const
r
=
await
ipcService
.
marco
();
return
assert
.
equal
(
r
,
'
polo
'
);
});
test
(
'
call error
'
,
async
function
()
{
try
{
await
ipcService
.
error
(
'
nice error
'
);
return
assert
.
fail
(
'
should not reach here
'
);
}
catch
(
err
)
{
return
assert
.
equal
(
err
.
message
,
'
nice error
'
);
}
});
test
(
'
listen to events
'
,
async
function
()
{
const
messages
:
string
[]
=
[];
ipcService
.
onPong
(
msg
=>
messages
.
push
(
msg
));
await
timeout
(
0
);
assert
.
deepEqual
(
messages
,
[]);
service
.
ping
(
'
hello
'
);
await
timeout
(
0
);
assert
.
deepEqual
(
messages
,
[
'
hello
'
]);
service
.
ping
(
'
world
'
);
await
timeout
(
0
);
assert
.
deepEqual
(
messages
,
[
'
hello
'
,
'
world
'
]);
});
test
(
'
marshalling uri
'
,
async
function
()
{
const
uri
=
URI
.
file
(
'
foobar
'
);
const
r
=
await
ipcService
.
marshall
(
uri
);
assert
.
ok
(
r
instanceof
URI
);
return
assert
.
ok
(
isEqual
(
r
,
uri
));
});
test
(
'
buffers in arrays
'
,
async
function
()
{
const
r
=
await
ipcService
.
buffersLength
([
Buffer
.
allocUnsafe
(
2
),
Buffer
.
allocUnsafe
(
3
)]);
return
assert
.
equal
(
r
,
5
);
});
});
suite
(
'
one to one (proxy, extra context)
'
,
function
()
{
let
server
:
IPCServer
;
let
client
:
IPCClient
;
let
service
:
TestService
;
let
ipcService
:
ITestService
;
setup
(
function
()
{
service
=
new
TestService
();
const
testServer
=
new
TestIPCServer
();
server
=
testServer
;
server
.
registerChannel
(
TestChannelId
,
createChannelReceiver
(
service
));
client
=
testServer
.
createConnection
(
'
client1
'
);
ipcService
=
createChannelSender
(
client
.
getChannel
(
TestChannelId
),
{
context
:
'
Super Context
'
});
});
teardown
(
function
()
{
client
.
dispose
();
server
.
dispose
();
});
test
(
'
call extra context
'
,
async
function
()
{
const
r
=
await
ipcService
.
context
();
return
assert
.
equal
(
r
,
'
Super Context
'
);
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录