Commit 71825ce3 authored by Gunnar Liljas's avatar Gunnar Liljas Committed by Marc Gravell

Removed invalid call to SetRequestSent for IMultiMessage (#769)

* Removed invalid call to SetRequestSent for IMultiMessage

* Improved (corrected) check logic.
parent b96f4973
...@@ -24,6 +24,6 @@ ...@@ -24,6 +24,6 @@
<LibraryTargetFrameworks>net45;net46;netstandard1.5</LibraryTargetFrameworks> <LibraryTargetFrameworks>net45;net46;netstandard1.5</LibraryTargetFrameworks>
<CoreFxVersion>4.3.0</CoreFxVersion> <CoreFxVersion>4.3.0</CoreFxVersion>
<xUnitVersion>2.3.0-beta5-build3750</xUnitVersion> <xUnitVersion>2.3.1</xUnitVersion>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
\ No newline at end of file
...@@ -35,41 +35,44 @@ public void Simple() ...@@ -35,41 +35,44 @@ public void Simple()
db.StringSet("hello", "world"); db.StringSet("hello", "world");
var val = db.StringGet("hello"); var val = db.StringGet("hello");
Assert.Equal("world", (string)val); Assert.Equal("world", (string)val);
var result=db.ScriptEvaluate(LuaScript.Prepare("return redis.call('get', @key)"), new { key = (RedisKey)"hello" });
Assert.Equal("world", result.AsString());
var cmds = conn.FinishProfiling(profiler.MyContext); var cmds = conn.FinishProfiling(profiler.MyContext);
Assert.Equal(2, cmds.Count()); Assert.Equal(3, cmds.Count());
var set = cmds.SingleOrDefault(cmd => cmd.Command == "SET"); var set = cmds.SingleOrDefault(cmd => cmd.Command == "SET");
Assert.NotNull(set); Assert.NotNull(set);
var get = cmds.SingleOrDefault(cmd => cmd.Command == "GET"); var get = cmds.SingleOrDefault(cmd => cmd.Command == "GET");
Assert.NotNull(get); Assert.NotNull(get);
var eval = cmds.SingleOrDefault(cmd => cmd.Command == "EVAL");
Assert.NotNull(eval);
Assert.True(set.CommandCreated <= get.CommandCreated); Assert.True(set.CommandCreated <= get.CommandCreated);
Assert.True(get.CommandCreated <= eval.CommandCreated);
Assert.Equal(4, set.Db); AssertProfiledCommandValues(set, conn);
Assert.Equal(conn.GetEndPoints()[0], set.EndPoint);
Assert.True(set.CreationToEnqueued > TimeSpan.Zero); AssertProfiledCommandValues(get, conn);
Assert.True(set.EnqueuedToSending > TimeSpan.Zero);
Assert.True(set.SentToResponse > TimeSpan.Zero); AssertProfiledCommandValues(eval, conn);
Assert.True(set.ResponseToCompletion > TimeSpan.Zero);
Assert.True(set.ElapsedTime > TimeSpan.Zero);
Assert.True(set.ElapsedTime > set.CreationToEnqueued && set.ElapsedTime > set.EnqueuedToSending && set.ElapsedTime > set.SentToResponse);
Assert.True(set.RetransmissionOf == null);
Assert.True(set.RetransmissionReason == null);
Assert.Equal(4, get.Db);
Assert.Equal(conn.GetEndPoints()[0], get.EndPoint);
Assert.True(get.CreationToEnqueued > TimeSpan.Zero);
Assert.True(get.EnqueuedToSending > TimeSpan.Zero);
Assert.True(get.SentToResponse > TimeSpan.Zero);
Assert.True(get.ResponseToCompletion > TimeSpan.Zero);
Assert.True(get.ElapsedTime > TimeSpan.Zero);
Assert.True(get.ElapsedTime > get.CreationToEnqueued && get.ElapsedTime > get.EnqueuedToSending && get.ElapsedTime > get.SentToResponse);
Assert.True(get.RetransmissionOf == null);
Assert.True(get.RetransmissionReason == null);
} }
} }
private static void AssertProfiledCommandValues(IProfiledCommand command, ConnectionMultiplexer conn)
{
Assert.Equal(4, command.Db);
Assert.Equal(conn.GetEndPoints()[0], command.EndPoint);
Assert.True(command.CreationToEnqueued > TimeSpan.Zero);
Assert.True(command.EnqueuedToSending > TimeSpan.Zero);
Assert.True(command.SentToResponse > TimeSpan.Zero);
Assert.True(command.ResponseToCompletion > TimeSpan.Zero);
Assert.True(command.ElapsedTime > TimeSpan.Zero);
Assert.True(command.ElapsedTime > command.CreationToEnqueued && command.ElapsedTime > command.EnqueuedToSending && command.ElapsedTime > command.SentToResponse);
Assert.True(command.RetransmissionOf == null);
Assert.True(command.RetransmissionReason == null);
}
[Fact] [Fact]
public void ManyThreads() public void ManyThreads()
{ {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="Moq" Version="4.7.99" /> <PackageReference Include="Moq" Version="4.7.99" />
<!-- Temp workaround for analyzer issue --> <!-- Temp workaround for analyzer issue -->
<PackageReference Include="xunit.analyzers" Version="0.6.1" /> <PackageReference Include="xunit.analyzers" Version="0.7.0" />
<PackageReference Include="xunit" Version="$(xUnitVersion)" /> <PackageReference Include="xunit" Version="$(xUnitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" /> <PackageReference Include="xunit.runner.visualstudio" Version="$(xUnitVersion)" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(xUnitVersion)" /> <DotNetCliToolReference Include="dotnet-xunit" Version="$(xUnitVersion)" />
......
...@@ -530,6 +530,7 @@ internal bool TryEnqueue(List<Message> messages, bool isSlave) ...@@ -530,6 +530,7 @@ internal bool TryEnqueue(List<Message> messages, bool isSlave)
internal bool WriteMessageDirect(PhysicalConnection tmp, Message next) internal bool WriteMessageDirect(PhysicalConnection tmp, Message next)
{ {
Trace("Writing: " + next); Trace("Writing: " + next);
var messageIsSent = false;
if (next is IMultiMessage) if (next is IMultiMessage)
{ {
SelectDatabase(tmp, next); // need to switch database *before* the transaction SelectDatabase(tmp, next); // need to switch database *before* the transaction
...@@ -543,10 +544,15 @@ internal bool WriteMessageDirect(PhysicalConnection tmp, Message next) ...@@ -543,10 +544,15 @@ internal bool WriteMessageDirect(PhysicalConnection tmp, Message next)
next.Fail(ConnectionFailureType.ProtocolFailure, null); next.Fail(ConnectionFailureType.ProtocolFailure, null);
CompleteSyncOrAsync(next); CompleteSyncOrAsync(next);
return false; return false;
} }
} //The parent message (next) may be returned from GetMessages
//and should not be marked as sent again below
next.SetRequestSent(); messageIsSent = messageIsSent || subCommand == next;
}
if (!messageIsSent)
{
next.SetRequestSent();
}
return true; return true;
} }
......
...@@ -70,7 +70,7 @@ public static ProfileStorage NewAttachedToSameContext(ProfileStorage resentFor, ...@@ -70,7 +70,7 @@ public static ProfileStorage NewAttachedToSameContext(ProfileStorage resentFor,
public void SetMessage(Message msg) public void SetMessage(Message msg)
{ {
// This method should never be called twice // This method should never be called twice
if (Message != null) throw new InvalidOperationException(); if (Message != null) throw new InvalidOperationException($"{nameof(SetMessage)} called more than once");
Message = msg; Message = msg;
MessageCreatedDateTime = msg.createdDateTime; MessageCreatedDateTime = msg.createdDateTime;
...@@ -80,7 +80,7 @@ public void SetMessage(Message msg) ...@@ -80,7 +80,7 @@ public void SetMessage(Message msg)
public void SetEnqueued() public void SetEnqueued()
{ {
// This method should never be called twice // This method should never be called twice
if (EnqueuedTimeStamp > 0) throw new InvalidOperationException(); if (EnqueuedTimeStamp > 0) throw new InvalidOperationException($"{nameof(SetEnqueued)} called more than once");
EnqueuedTimeStamp = Stopwatch.GetTimestamp(); EnqueuedTimeStamp = Stopwatch.GetTimestamp();
} }
...@@ -88,14 +88,14 @@ public void SetEnqueued() ...@@ -88,14 +88,14 @@ public void SetEnqueued()
public void SetRequestSent() public void SetRequestSent()
{ {
// This method should never be called twice // This method should never be called twice
if (RequestSentTimeStamp > 0) throw new InvalidOperationException(); if (RequestSentTimeStamp > 0) throw new InvalidOperationException($"{nameof(SetRequestSent)} called more than once");
RequestSentTimeStamp = Stopwatch.GetTimestamp(); RequestSentTimeStamp = Stopwatch.GetTimestamp();
} }
public void SetResponseReceived() public void SetResponseReceived()
{ {
if (ResponseReceivedTimeStamp > 0) throw new InvalidOperationException(); if (ResponseReceivedTimeStamp > 0) throw new InvalidOperationException($"{nameof(SetResponseReceived)} called more than once");
ResponseReceivedTimeStamp = Stopwatch.GetTimestamp(); ResponseReceivedTimeStamp = Stopwatch.GetTimestamp();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment