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
827fa704
Commit
827fa704
authored
Aug 13, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move ParallelTransactionsWithConditions to the non-parallel set
parent
91fd316e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
63 deletions
+79
-63
AggresssiveTests.cs
StackExchange.Redis.Tests/AggresssiveTests.cs
+76
-0
GarbageCollectionTests.cs
StackExchange.Redis.Tests/GarbageCollectionTests.cs
+2
-2
Locking.cs
StackExchange.Redis.Tests/Locking.cs
+1
-0
Transactions.cs
StackExchange.Redis.Tests/Transactions.cs
+0
-61
No files found.
StackExchange.Redis.Tests/AggresssiveTests.cs
0 → 100644
View file @
827fa704
using
System
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Xunit
;
using
Xunit.Abstractions
;
namespace
StackExchange.Redis.Tests
{
[
Collection
(
NonParallelCollection
.
Name
)]
public
class
AggresssiveTests
:
TestBase
{
public
AggresssiveTests
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
[
Fact
]
public
async
Task
ParallelTransactionsWithConditions
()
{
const
int
Muxers
=
4
,
Workers
=
20
,
PerThread
=
250
;
var
muxers
=
new
ConnectionMultiplexer
[
Muxers
];
try
{
for
(
int
i
=
0
;
i
<
Muxers
;
i
++)
muxers
[
i
]
=
Create
();
RedisKey
hits
=
Me
(),
trigger
=
Me
()
+
"3"
;
int
expectedSuccess
=
0
;
await
muxers
[
0
].
GetDatabase
().
KeyDeleteAsync
(
new
[]
{
hits
,
trigger
});
Task
[]
tasks
=
new
Task
[
Workers
];
for
(
int
i
=
0
;
i
<
tasks
.
Length
;
i
++)
{
var
scopedDb
=
muxers
[
i
%
Muxers
].
GetDatabase
();
var
rand
=
new
Random
(
i
);
tasks
[
i
]
=
Task
.
Run
(
async
()
=>
{
for
(
int
j
=
0
;
j
<
PerThread
;
j
++)
{
var
oldVal
=
await
scopedDb
.
StringGetAsync
(
trigger
);
var
tran
=
scopedDb
.
CreateTransaction
();
tran
.
AddCondition
(
Condition
.
StringEqual
(
trigger
,
oldVal
));
var
x
=
tran
.
StringIncrementAsync
(
trigger
);
var
y
=
tran
.
StringIncrementAsync
(
hits
);
if
(
await
tran
.
ExecuteAsync
())
{
Interlocked
.
Increment
(
ref
expectedSuccess
);
await
x
;
await
y
;
}
else
{
await
Assert
.
ThrowsAsync
<
TaskCanceledException
>(()
=>
x
);
await
Assert
.
ThrowsAsync
<
TaskCanceledException
>(()
=>
y
);
}
}
});
}
for
(
int
i
=
tasks
.
Length
-
1
;
i
>=
0
;
i
--)
{
await
tasks
[
i
];
}
var
actual
=
(
int
)
await
muxers
[
0
].
GetDatabase
().
StringGetAsync
(
hits
);
Assert
.
Equal
(
expectedSuccess
,
actual
);
Writer
.
WriteLine
(
$"success:
{
actual
}
out of
{
Workers
*
PerThread
}
attempts"
);
}
finally
{
for
(
int
i
=
0
;
i
<
muxers
.
Length
;
i
++)
{
try
{
muxers
[
i
]?.
Dispose
();
}
catch
{
}
}
}
}
}
}
StackExchange.Redis.Tests/GarbageCollectionTests.cs
View file @
827fa704
...
...
@@ -22,8 +22,8 @@ private static void ForceGC()
[
Fact
]
public
void
MuxerIsCollected
()
{
#if DEBUG
Skip
.
Inconclusive
(
"Only predictable in builds"
);
#if
!
DEBUG
Skip
.
Inconclusive
(
"Only predictable in
debug
builds"
);
#endif
// this is more nuanced than it looks; multiple sockets with
// async callbacks, plus a heartbeat on a timer
...
...
StackExchange.Redis.Tests/Locking.cs
View file @
827fa704
...
...
@@ -7,6 +7,7 @@
namespace
StackExchange.Redis.Tests
{
[
Collection
(
NonParallelCollection
.
Name
)]
public
class
Locking
:
TestBase
{
protected
override
string
GetConfiguration
()
=>
TestConfig
.
Current
.
MasterServerAndPort
;
...
...
StackExchange.Redis.Tests/Transactions.cs
View file @
827fa704
...
...
@@ -897,67 +897,6 @@ public async Task CombineFireAndForgetAndRegularAsyncInTransaction()
}
}
[
Fact
]
public
async
Task
ParallelTransactionsWithConditions
()
{
const
int
Muxers
=
4
,
Workers
=
20
,
PerThread
=
250
;
var
muxers
=
new
ConnectionMultiplexer
[
Muxers
];
try
{
for
(
int
i
=
0
;
i
<
Muxers
;
i
++)
muxers
[
i
]
=
Create
();
RedisKey
hits
=
Me
(),
trigger
=
Me
()
+
"3"
;
int
expectedSuccess
=
0
;
await
muxers
[
0
].
GetDatabase
().
KeyDeleteAsync
(
new
[]
{
hits
,
trigger
});
Task
[]
tasks
=
new
Task
[
Workers
];
for
(
int
i
=
0
;
i
<
tasks
.
Length
;
i
++)
{
var
scopedDb
=
muxers
[
i
%
Muxers
].
GetDatabase
();
var
rand
=
new
Random
(
i
);
tasks
[
i
]
=
Task
.
Run
(
async
()
=>
{
for
(
int
j
=
0
;
j
<
PerThread
;
j
++)
{
var
oldVal
=
await
scopedDb
.
StringGetAsync
(
trigger
);
var
tran
=
scopedDb
.
CreateTransaction
();
tran
.
AddCondition
(
Condition
.
StringEqual
(
trigger
,
oldVal
));
var
x
=
tran
.
StringIncrementAsync
(
trigger
);
var
y
=
tran
.
StringIncrementAsync
(
hits
);
if
(
await
tran
.
ExecuteAsync
())
{
Interlocked
.
Increment
(
ref
expectedSuccess
);
await
x
;
await
y
;
}
else
{
await
Assert
.
ThrowsAsync
<
TaskCanceledException
>(()
=>
x
);
await
Assert
.
ThrowsAsync
<
TaskCanceledException
>(()
=>
y
);
}
}
});
}
for
(
int
i
=
tasks
.
Length
-
1
;
i
>=
0
;
i
--)
{
await
tasks
[
i
];
}
var
actual
=
(
int
)
await
muxers
[
0
].
GetDatabase
().
StringGetAsync
(
hits
);
Assert
.
Equal
(
expectedSuccess
,
actual
);
Writer
.
WriteLine
(
$"success:
{
actual
}
out of
{
Workers
*
PerThread
}
attempts"
);
}
finally
{
for
(
int
i
=
0
;
i
<
muxers
.
Length
;
i
++)
{
try
{
muxers
[
i
]?.
Dispose
();
}
catch
{
}
}
}
}
[
Fact
]
public
async
Task
WatchAbort_StringEqual
()
{
...
...
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