Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c61052a5
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,发现更多精彩内容 >>
未验证
提交
c61052a5
编写于
5月 19, 2020
作者:
S
Sam Harwell
提交者:
GitHub
5月 19, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #44383 from sharwell/unwrap-exception
Properly unwrap faulted tasks in AsyncLazy<T>
上级
01820995
3272c3f0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
9 deletion
+39
-9
src/EditorFeatures/Test/Utilities/AsyncLazyTests.cs
src/EditorFeatures/Test/Utilities/AsyncLazyTests.cs
+32
-8
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/AsyncLazy`1.cs
...itiesAndExtensions/Compiler/Core/Utilities/AsyncLazy`1.cs
+7
-1
未找到文件。
src/EditorFeatures/Test/Utilities/AsyncLazyTests.cs
浏览文件 @
c61052a5
...
...
@@ -12,10 +12,9 @@
namespace
Microsoft.CodeAnalysis.UnitTests
{
public
partial
class
AsyncLazyTests
public
class
AsyncLazyTests
{
// This probably shouldn't need WpfFact, but the failure is being tracked by https://github.com/dotnet/roslyn/issues/7438
[
WpfFact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
AsyncLazy
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
AsyncLazy
)]
public
void
CancellationDuringInlinedComputationFromGetValueStillCachesResult
()
{
CancellationDuringInlinedComputationFromGetValueOrGetValueAsyncStillCachesResultCore
((
lazy
,
ct
)
=>
lazy
.
GetValue
(
ct
),
includeSynchronousComputation
:
true
);
...
...
@@ -46,16 +45,13 @@ private static void CancellationDuringInlinedComputationFromGetValueOrGetValueAs
includeSynchronousComputation
?
synchronousComputation
:
null
,
cacheResult
:
true
);
var
thrownException
=
Assert
.
Throws
Any
<
Exception
>(()
=>
var
thrownException
=
Assert
.
Throws
<
OperationCanceled
Exception
>(()
=>
{
// Do a first request. Even though we will get a cancellation during the evaluation,
// since we handed a result back, that result must be cached.
doGetValue
(
lazy
,
requestCancellationTokenSource
.
Token
);
});
// Assert it's either cancellation or aggregate exception
Assert
.
True
(
thrownException
is
OperationCanceledException
||
((
AggregateException
)
thrownException
).
Flatten
().
InnerException
is
OperationCanceledException
);
// And a second request. We'll let this one complete normally.
var
secondRequestResult
=
doGetValue
(
lazy
,
CancellationToken
.
None
);
...
...
@@ -64,7 +60,7 @@ private static void CancellationDuringInlinedComputationFromGetValueOrGetValueAs
Assert
.
Equal
(
1
,
computations
);
}
[
Wpf
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
AsyncLazy
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
AsyncLazy
)]
public
void
SynchronousRequestShouldCacheValueWithAsynchronousComputeFunction
()
{
var
lazy
=
new
AsyncLazy
<
object
>(
c
=>
Task
.
FromResult
(
new
object
()),
cacheResult
:
true
);
...
...
@@ -74,5 +70,33 @@ public void SynchronousRequestShouldCacheValueWithAsynchronousComputeFunction()
Assert
.
Same
(
secondRequestResult
,
firstRequestResult
);
}
[
Theory
]
[
CombinatorialData
]
public
async
Task
AwaitingProducesCorrectException
(
bool
producerAsync
,
bool
consumerAsync
)
{
var
exception
=
new
ArgumentException
();
Func
<
CancellationToken
,
Task
<
object
>>
asynchronousComputeFunction
=
async
cancellationToken
=>
{
await
Task
.
Yield
();
throw
exception
;
};
Func
<
CancellationToken
,
object
>
synchronousComputeFunction
=
cancellationToken
=>
{
throw
exception
;
};
var
lazy
=
producerAsync
?
new
AsyncLazy
<
object
>(
asynchronousComputeFunction
,
cacheResult
:
true
)
:
new
AsyncLazy
<
object
>(
asynchronousComputeFunction
,
synchronousComputeFunction
,
cacheResult
:
true
);
var
actual
=
consumerAsync
?
await
Assert
.
ThrowsAsync
<
ArgumentException
>(
async
()
=>
await
lazy
.
GetValueAsync
(
CancellationToken
.
None
))
:
Assert
.
Throws
<
ArgumentException
>(()
=>
lazy
.
GetValue
(
CancellationToken
.
None
));
Assert
.
Same
(
exception
,
actual
);
}
}
}
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/AsyncLazy`1.cs
浏览文件 @
c61052a5
...
...
@@ -574,7 +574,13 @@ public void CompleteFromTask(Task<T> task)
}
else
if
(
task
.
IsFaulted
)
{
this
.
TrySetException
(
task
.
Exception
!);
// TrySetException wraps its argument in an AggregateException, so we pass the inner exceptions from
// the antecedent to avoid wrapping in two layers of AggregateException.
RoslynDebug
.
AssertNotNull
(
task
.
Exception
);
if
(
task
.
Exception
.
InnerExceptions
.
Count
>
0
)
this
.
TrySetException
(
task
.
Exception
.
InnerExceptions
);
else
this
.
TrySetException
(
task
.
Exception
);
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录