Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
tsai
StackExchange.Redis
Commits
b82caefa
Commit
b82caefa
authored
Mar 13, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ambient exceptions: store on an AsyncLocal<T> for test isolation
parent
486f03fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
TestBase.cs
StackExchange.Redis.Tests/TestBase.cs
+19
-4
No files found.
StackExchange.Redis.Tests/TestBase.cs
View file @
b82caefa
...
@@ -62,7 +62,13 @@ static TestBase()
...
@@ -62,7 +62,13 @@ static TestBase()
#if NETCOREAPP1_0
#if NETCOREAPP1_0
if
(
IgnorableExceptionPredicates
.
Any
(
predicate
=>
predicate
(
args
.
Exception
.
InnerException
)))
return
;
if
(
IgnorableExceptionPredicates
.
Any
(
predicate
=>
predicate
(
args
.
Exception
.
InnerException
)))
return
;
#endif
#endif
Interlocked
.
Increment
(
ref
sharedFailCount
);
lock
(
sharedFailCount
)
{
if
(
sharedFailCount
!=
null
)
{
sharedFailCount
.
Value
++;
}
}
lock
(
backgroundExceptions
)
lock
(
backgroundExceptions
)
{
{
backgroundExceptions
.
Add
(
args
.
Exception
.
ToString
());
backgroundExceptions
.
Add
(
args
.
Exception
.
ToString
());
...
@@ -97,7 +103,7 @@ protected void OnInternalError(object sender, InternalErrorEventArgs e)
...
@@ -97,7 +103,7 @@ protected void OnInternalError(object sender, InternalErrorEventArgs e)
}
}
private
int
privateFailCount
;
private
int
privateFailCount
;
private
static
int
sharedFailCount
;
private
static
AsyncLocal
<
int
>
sharedFailCount
=
new
AsyncLocal
<
int
>()
;
private
volatile
int
expectedFailCount
;
private
volatile
int
expectedFailCount
;
private
static
readonly
List
<
string
>
privateExceptions
=
new
List
<
string
>();
private
static
readonly
List
<
string
>
privateExceptions
=
new
List
<
string
>();
...
@@ -107,7 +113,10 @@ public void ClearAmbientFailures()
...
@@ -107,7 +113,10 @@ public void ClearAmbientFailures()
{
{
Collect
();
Collect
();
Interlocked
.
Exchange
(
ref
privateFailCount
,
0
);
Interlocked
.
Exchange
(
ref
privateFailCount
,
0
);
Interlocked
.
Exchange
(
ref
sharedFailCount
,
0
);
lock
(
sharedFailCount
)
{
sharedFailCount
.
Value
=
0
;
}
expectedFailCount
=
0
;
expectedFailCount
=
0
;
lock
(
privateExceptions
)
lock
(
privateExceptions
)
{
{
...
@@ -136,7 +145,13 @@ private static void Collect()
...
@@ -136,7 +145,13 @@ private static void Collect()
public
void
Teardown
()
public
void
Teardown
()
{
{
Collect
();
Collect
();
if
(
expectedFailCount
>=
0
&&
(
Interlocked
.
CompareExchange
(
ref
sharedFailCount
,
0
,
0
)
+
privateFailCount
)
!=
expectedFailCount
)
int
sharedFails
;
lock
(
sharedFailCount
)
{
sharedFails
=
sharedFailCount
.
Value
;
sharedFailCount
.
Value
=
0
;
}
if
(
expectedFailCount
>=
0
&&
(
sharedFails
+
privateFailCount
)
!=
expectedFailCount
)
{
{
lock
(
privateExceptions
)
lock
(
privateExceptions
)
{
{
...
...
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