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
63c80596
Commit
63c80596
authored
Aug 08, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test invalidating transactions *right before* we issue the exec
parent
f2e00539
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
4 deletions
+70
-4
Transactions.cs
StackExchange.Redis.Tests/Transactions.cs
+54
-3
PhysicalBridge.cs
StackExchange.Redis/StackExchange/Redis/PhysicalBridge.cs
+10
-1
RedisSubscriber.cs
StackExchange.Redis/StackExchange/Redis/RedisSubscriber.cs
+6
-0
No files found.
StackExchange.Redis.Tests/Transactions.cs
View file @
63c80596
...
...
@@ -9,7 +9,7 @@ namespace StackExchange.Redis.Tests
{
public
class
Transactions
:
TestBase
{
public
Transactions
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
public
Transactions
(
ITestOutputHelper
output
)
:
base
(
output
)
{
}
[
Fact
]
public
void
BasicEmptyTran
()
...
...
@@ -924,7 +924,7 @@ public async Task ParallelTransactionsWithConditions()
tran
.
AddCondition
(
Condition
.
StringEqual
(
trigger
,
oldVal
));
var
x
=
tran
.
StringIncrementAsync
(
trigger
);
var
y
=
tran
.
StringIncrementAsync
(
hits
);
if
(
await
tran
.
ExecuteAsync
())
if
(
await
tran
.
ExecuteAsync
())
{
Interlocked
.
Increment
(
ref
expectedSuccess
);
await
x
;
...
...
@@ -942,7 +942,7 @@ public async Task ParallelTransactionsWithConditions()
{
await
tasks
[
i
];
}
var
actual
=
(
int
)
await
muxers
[
0
].
GetDatabase
().
StringGetAsync
(
hits
);
var
actual
=
(
int
)
await
muxers
[
0
].
GetDatabase
().
StringGetAsync
(
hits
);
Assert
.
Equal
(
expectedSuccess
,
actual
);
Writer
.
WriteLine
(
$"success:
{
actual
}
out of
{
Workers
*
PerThread
}
attempts"
);
}
...
...
@@ -954,5 +954,56 @@ public async Task ParallelTransactionsWithConditions()
}
}
}
[
Fact
]
public
async
Task
WatchAbort_StringEqual
()
{
using
(
var
vic
=
Create
(
log
:
TextWriter
.
Null
))
using
(
var
perp
=
Create
(
log
:
TextWriter
.
Null
))
{
var
key
=
Me
();
var
db
=
vic
.
GetDatabase
();
// expect foo, change to bar at the last minute
vic
.
PreTransactionExec
+=
cmd
=>
{
Writer
.
WriteLine
(
$"'
{
cmd
}
' detected; changing it..."
);
perp
.
GetDatabase
().
StringSet
(
key
,
"bar"
);
};
db
.
KeyDelete
(
key
);
db
.
StringSet
(
key
,
"foo"
);
var
tran
=
db
.
CreateTransaction
();
tran
.
AddCondition
(
Condition
.
StringEqual
(
key
,
"foo"
));
var
pong
=
tran
.
PingAsync
();
Assert
.
False
(
await
tran
.
ExecuteAsync
());
await
Assert
.
ThrowsAsync
<
TaskCanceledException
>(()
=>
pong
);
}
}
[
Fact
]
public
async
Task
WatchAbort_HashLengthEqual
()
{
using
(
var
vic
=
Create
(
log
:
TextWriter
.
Null
))
using
(
var
perp
=
Create
(
log
:
TextWriter
.
Null
))
{
var
key
=
Me
();
var
db
=
vic
.
GetDatabase
();
// expect foo, change to bar at the last minute
vic
.
PreTransactionExec
+=
cmd
=>
{
Writer
.
WriteLine
(
$"'
{
cmd
}
' detected; changing it..."
);
perp
.
GetDatabase
().
HashSet
(
key
,
"bar"
,
"def"
);
};
db
.
KeyDelete
(
key
);
db
.
HashSet
(
key
,
"foo"
,
"abc"
);
var
tran
=
db
.
CreateTransaction
();
tran
.
AddCondition
(
Condition
.
HashLengthEqual
(
key
,
1
));
var
pong
=
tran
.
PingAsync
();
Assert
.
False
(
await
tran
.
ExecuteAsync
());
await
Assert
.
ThrowsAsync
<
TaskCanceledException
>(()
=>
pong
);
}
}
}
}
StackExchange.Redis/StackExchange/Redis/PhysicalBridge.cs
View file @
63c80596
...
...
@@ -704,7 +704,16 @@ private WriteResult WriteMessageToServerInsideWriteLock(PhysicalConnection conne
{
throw
ExceptionFactory
.
MasterOnly
(
Multiplexer
.
IncludeDetailInExceptions
,
message
.
Command
,
message
,
ServerEndPoint
);
}
if
(
cmd
==
RedisCommand
.
QUIT
)
connection
.
RecordQuit
();
switch
(
cmd
)
{
case
RedisCommand
.
QUIT
:
connection
.
RecordQuit
();
break
;
case
RedisCommand
.
EXEC
:
Multiplexer
.
OnPreTransactionExec
(
message
);
// testing purposes, to force certain errors
break
;
}
SelectDatabaseInsideWriteLock
(
connection
,
message
);
if
(!
connection
.
TransactionActive
)
...
...
StackExchange.Redis/StackExchange/Redis/RedisSubscriber.cs
View file @
63c80596
...
...
@@ -254,6 +254,7 @@ internal string GetConnectionName(EndPoint endPoint, ConnectionType connectionTy
internal
event
Action
<
string
,
Exception
,
string
>
MessageFaulted
;
internal
event
Action
<
bool
>
Closing
;
internal
event
Action
<
string
>
PreTransactionExec
;
internal
event
Action
<
EndPoint
,
ConnectionType
>
Connecting
;
internal
event
Action
<
EndPoint
,
ConnectionType
>
Resurrecting
;
...
...
@@ -276,6 +277,11 @@ internal void OnResurrecting(EndPoint endpoint, ConnectionType connectionType)
{
Resurrecting
.
Invoke
(
endpoint
,
connectionType
);
}
internal
void
OnPreTransactionExec
(
Message
message
)
{
PreTransactionExec
?.
Invoke
(
message
.
CommandAndKey
);
}
}
internal
sealed
class
RedisSubscriber
:
RedisBase
,
ISubscriber
...
...
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