Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
20daf121
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
20daf121
编写于
8月 06, 2020
作者:
D
David Wengier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test mutating state and non-mutating interact as expected
上级
a07b9036
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
226 addition
and
0 deletion
+226
-0
src/Features/LanguageServer/ProtocolUnitTests/Ordering/AbstractTestRequestHandler.cs
.../ProtocolUnitTests/Ordering/AbstractTestRequestHandler.cs
+42
-0
src/Features/LanguageServer/ProtocolUnitTests/Ordering/MutatingRequestHandler.cs
...rver/ProtocolUnitTests/Ordering/MutatingRequestHandler.cs
+24
-0
src/Features/LanguageServer/ProtocolUnitTests/Ordering/NonMutatingRequestHandler.cs
...r/ProtocolUnitTests/Ordering/NonMutatingRequestHandler.cs
+24
-0
src/Features/LanguageServer/ProtocolUnitTests/Ordering/OrderedLspRequest.cs
...ageServer/ProtocolUnitTests/Ordering/OrderedLspRequest.cs
+17
-0
src/Features/LanguageServer/ProtocolUnitTests/Ordering/OrderedLspResponse.cs
...geServer/ProtocolUnitTests/Ordering/OrderedLspResponse.cs
+15
-0
src/Features/LanguageServer/ProtocolUnitTests/Ordering/RequestOrderingTests.cs
...Server/ProtocolUnitTests/Ordering/RequestOrderingTests.cs
+104
-0
未找到文件。
src/Features/LanguageServer/ProtocolUnitTests/Ordering/AbstractTestRequestHandler.cs
0 → 100644
浏览文件 @
20daf121
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.LanguageServer.Handler
;
using
Microsoft.VisualStudio.LanguageServer.Protocol
;
using
Microsoft.VisualStudio.TextManager.Interop
;
namespace
Microsoft.CodeAnalysis.LanguageServer.UnitTests.RequestOrdering
{
internal
abstract
class
AbstractTestRequestHandler
:
AbstractRequestHandler
<
OrderedLspRequest
,
OrderedLspResponse
>
{
private
const
int
Delay
=
100
;
public
AbstractTestRequestHandler
(
ILspSolutionProvider
solutionProvider
)
:
base
(
solutionProvider
)
{
}
public
override
async
Task
<
OrderedLspResponse
>
HandleRequestAsync
(
OrderedLspRequest
request
,
RequestContext
context
,
CancellationToken
cancellationToken
)
{
var
response
=
new
OrderedLspResponse
();
response
.
RequestOrder
=
request
.
RequestOrder
;
response
.
StartTime
=
DateTime
.
UtcNow
;
await
Task
.
Delay
(
Delay
,
cancellationToken
).
ConfigureAwait
(
false
);
// some busy work
response
.
ToString
();
await
Task
.
Delay
(
Delay
,
cancellationToken
).
ConfigureAwait
(
false
);
response
.
EndTime
=
DateTime
.
UtcNow
;
return
response
;
}
}
}
src/Features/LanguageServer/ProtocolUnitTests/Ordering/MutatingRequestHandler.cs
0 → 100644
浏览文件 @
20daf121
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
using
System.Composition
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.LanguageServer.Handler
;
namespace
Microsoft.CodeAnalysis.LanguageServer.UnitTests.RequestOrdering
{
[
Shared
,
ExportLspMethod
(
MethodName
,
mutatesSolutionState
:
true
)]
internal
class
MutatingRequestHandler
:
AbstractTestRequestHandler
{
public
const
string
MethodName
=
nameof
(
MutatingRequestHandler
);
[
ImportingConstructor
]
[
Obsolete
(
MefConstruction
.
ImportingConstructorMessage
,
error
:
true
)]
public
MutatingRequestHandler
(
ILspSolutionProvider
solutionProvider
)
:
base
(
solutionProvider
)
{
}
}
}
src/Features/LanguageServer/ProtocolUnitTests/Ordering/NonMutatingRequestHandler.cs
0 → 100644
浏览文件 @
20daf121
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
using
System.Composition
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.LanguageServer.Handler
;
namespace
Microsoft.CodeAnalysis.LanguageServer.UnitTests.RequestOrdering
{
[
Shared
,
ExportLspMethod
(
MethodName
,
mutatesSolutionState
:
false
)]
internal
class
NonMutatingRequestHandler
:
AbstractTestRequestHandler
{
public
const
string
MethodName
=
nameof
(
NonMutatingRequestHandler
);
[
ImportingConstructor
]
[
Obsolete
(
MefConstruction
.
ImportingConstructorMessage
,
error
:
true
)]
public
NonMutatingRequestHandler
(
ILspSolutionProvider
solutionProvider
)
:
base
(
solutionProvider
)
{
}
}
}
src/Features/LanguageServer/ProtocolUnitTests/Ordering/OrderedLspRequest.cs
0 → 100644
浏览文件 @
20daf121
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace
Microsoft.CodeAnalysis.LanguageServer.UnitTests.RequestOrdering
{
internal
class
OrderedLspRequest
{
public
string
MethodName
{
get
;
}
public
int
RequestOrder
{
get
;
set
;
}
public
OrderedLspRequest
(
string
methodName
)
{
MethodName
=
methodName
;
}
}
}
src/Features/LanguageServer/ProtocolUnitTests/Ordering/OrderedLspResponse.cs
0 → 100644
浏览文件 @
20daf121
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
namespace
Microsoft.CodeAnalysis.LanguageServer.UnitTests.RequestOrdering
{
internal
class
OrderedLspResponse
{
public
int
RequestOrder
{
get
;
set
;
}
public
DateTime
StartTime
{
get
;
set
;
}
public
DateTime
EndTime
{
get
;
set
;
}
}
}
src/Features/LanguageServer/ProtocolUnitTests/Ordering/RequestOrderingTests.cs
0 → 100644
浏览文件 @
20daf121
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
using
System.Collections.Generic
;
using
System.Composition
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.LanguageServer.Handler
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Roslyn.Test.Utilities
;
using
Xunit
;
using
LSP
=
Microsoft
.
VisualStudio
.
LanguageServer
.
Protocol
;
namespace
Microsoft.CodeAnalysis.LanguageServer.UnitTests.RequestOrdering
{
public
partial
class
RequestOrderingTests
:
AbstractLanguageServerProtocolTests
{
protected
override
TestComposition
Composition
=>
base
.
Composition
.
AddParts
(
typeof
(
MutatingRequestHandler
))
.
AddParts
(
typeof
(
NonMutatingRequestHandler
));
[
Fact
]
public
async
Task
SerialRequestsDontOverlap
()
{
var
requests
=
new
[]
{
new
OrderedLspRequest
(
MutatingRequestHandler
.
MethodName
),
new
OrderedLspRequest
(
MutatingRequestHandler
.
MethodName
),
new
OrderedLspRequest
(
MutatingRequestHandler
.
MethodName
),
};
var
responses
=
await
TestAsync
(
requests
);
// Every request should have started at or after the one before it
Assert
.
True
(
responses
[
1
].
StartTime
>=
responses
[
0
].
EndTime
);
Assert
.
True
(
responses
[
2
].
StartTime
>=
responses
[
1
].
EndTime
);
}
[
Fact
]
public
async
Task
ParallelRequestsOverlap
()
{
var
requests
=
new
[]
{
new
OrderedLspRequest
(
NonMutatingRequestHandler
.
MethodName
),
new
OrderedLspRequest
(
NonMutatingRequestHandler
.
MethodName
),
new
OrderedLspRequest
(
NonMutatingRequestHandler
.
MethodName
),
};
var
responses
=
await
TestAsync
(
requests
);
// Every request should have started immediately, without waiting
Assert
.
True
(
responses
[
1
].
StartTime
<
responses
[
0
].
EndTime
);
Assert
.
True
(
responses
[
2
].
StartTime
<
responses
[
1
].
EndTime
);
}
[
Fact
]
public
async
Task
ParallelWaitsForSerial
()
{
var
requests
=
new
[]
{
new
OrderedLspRequest
(
MutatingRequestHandler
.
MethodName
),
new
OrderedLspRequest
(
NonMutatingRequestHandler
.
MethodName
),
new
OrderedLspRequest
(
NonMutatingRequestHandler
.
MethodName
),
};
var
responses
=
await
TestAsync
(
requests
);
// The parallel tasks should have waited for the first task to finish
Assert
.
True
(
responses
[
1
].
StartTime
>=
responses
[
0
].
EndTime
);
Assert
.
True
(
responses
[
2
].
StartTime
>=
responses
[
0
].
EndTime
);
// The parallel requests shouldn't have waited for each other
Assert
.
True
(
responses
[
1
].
StartTime
<
responses
[
2
].
EndTime
);
Assert
.
True
(
responses
[
2
].
StartTime
<
responses
[
1
].
EndTime
);
}
private
async
Task
<
OrderedLspResponse
[
]>
TestAsync
(
OrderedLspRequest
[]
requests
)
{
using
var
workspace
=
CreateTestWorkspace
(
"class C { }"
,
out
_
);
var
solution
=
workspace
.
CurrentSolution
;
var
languageServer
=
GetLanguageServer
(
solution
);
var
clientCapabilities
=
new
LSP
.
ClientCapabilities
();
var
waitables
=
new
List
<
Task
<
OrderedLspResponse
>>();
var
order
=
1
;
foreach
(
var
request
in
requests
)
{
request
.
RequestOrder
=
order
++;
waitables
.
Add
(
languageServer
.
ExecuteRequestAsync
<
OrderedLspRequest
,
OrderedLspResponse
>(
request
.
MethodName
,
request
,
clientCapabilities
,
null
,
CancellationToken
.
None
));
}
var
responses
=
await
Task
.
WhenAll
(
waitables
);
// Sanity checks to ensure test handlers aren't doing something wacky, making future checks invalid
Assert
.
Empty
(
responses
.
Where
(
r
=>
r
.
StartTime
==
default
));
Assert
.
All
(
responses
,
r
=>
Assert
.
True
(
r
.
EndTime
>
r
.
StartTime
));
return
responses
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录