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 @@
<LibraryTargetFrameworks>net45;net46;netstandard1.5</LibraryTargetFrameworks>
<CoreFxVersion>4.3.0</CoreFxVersion>
<xUnitVersion>2.3.0-beta5-build3750</xUnitVersion>
<xUnitVersion>2.3.1</xUnitVersion>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -35,39 +35,42 @@ public void Simple()
db.StringSet("hello", "world");
var val = db.StringGet("hello");
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);
Assert.Equal(2, cmds.Count());
Assert.Equal(3, cmds.Count());
var set = cmds.SingleOrDefault(cmd => cmd.Command == "SET");
Assert.NotNull(set);
var get = cmds.SingleOrDefault(cmd => cmd.Command == "GET");
Assert.NotNull(get);
var eval = cmds.SingleOrDefault(cmd => cmd.Command == "EVAL");
Assert.NotNull(eval);
Assert.True(set.CommandCreated <= get.CommandCreated);
Assert.True(get.CommandCreated <= eval.CommandCreated);
Assert.Equal(4, set.Db);
Assert.Equal(conn.GetEndPoints()[0], set.EndPoint);
Assert.True(set.CreationToEnqueued > TimeSpan.Zero);
Assert.True(set.EnqueuedToSending > TimeSpan.Zero);
Assert.True(set.SentToResponse > TimeSpan.Zero);
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);
AssertProfiledCommandValues(set, conn);
AssertProfiledCommandValues(get, conn);
AssertProfiledCommandValues(eval, conn);
}
}
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]
......
......@@ -26,7 +26,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="Moq" Version="4.7.99" />
<!-- 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.runner.visualstudio" Version="$(xUnitVersion)" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(xUnitVersion)" />
......
......@@ -530,6 +530,7 @@ internal bool TryEnqueue(List<Message> messages, bool isSlave)
internal bool WriteMessageDirect(PhysicalConnection tmp, Message next)
{
Trace("Writing: " + next);
var messageIsSent = false;
if (next is IMultiMessage)
{
SelectDatabase(tmp, next); // need to switch database *before* the transaction
......@@ -544,9 +545,14 @@ internal bool WriteMessageDirect(PhysicalConnection tmp, Message next)
CompleteSyncOrAsync(next);
return false;
}
//The parent message (next) may be returned from GetMessages
//and should not be marked as sent again below
messageIsSent = messageIsSent || subCommand == next;
}
if (!messageIsSent)
{
next.SetRequestSent();
}
return true;
}
......
......@@ -70,7 +70,7 @@ public static ProfileStorage NewAttachedToSameContext(ProfileStorage resentFor,
public void SetMessage(Message msg)
{
// 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;
MessageCreatedDateTime = msg.createdDateTime;
......@@ -80,7 +80,7 @@ public void SetMessage(Message msg)
public void SetEnqueued()
{
// 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();
}
......@@ -88,14 +88,14 @@ public void SetEnqueued()
public void SetRequestSent()
{
// 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();
}
public void SetResponseReceived()
{
if (ResponseReceivedTimeStamp > 0) throw new InvalidOperationException();
if (ResponseReceivedTimeStamp > 0) throw new InvalidOperationException($"{nameof(SetResponseReceived)} called more than once");
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