-
Notifications
You must be signed in to change notification settings - Fork 621
Leverate NUnit Assert.Throws #1416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
johnthcall
wants to merge
3
commits into
microsoft:main
Choose a base branch
from
johnthcall:AssertThrows
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -283,33 +283,19 @@ public void ClusterCLUSTERDOWNTest() | |
|
|
||
| void SERedisClusterDown(BaseCommand command) | ||
| { | ||
| try | ||
| { | ||
| AssertSlotsNotAssigned(requestNodeIndex); | ||
| _ = context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest()); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| ClassicAssert.AreEqual("CLUSTERDOWN Hash slot not served", ex.Message, command.Command); | ||
| return; | ||
| } | ||
| Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| AssertSlotsNotAssigned(requestNodeIndex); | ||
| var ex = Assert.Throws<RedisServerException>(() => context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest()), | ||
| $"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| ClassicAssert.AreEqual("CLUSTERDOWN Hash slot not served", ex.Message, command.Command); | ||
| } | ||
|
|
||
| void GarnetClientSessionClusterDown(BaseCommand command) | ||
| { | ||
| var client = context.clusterTestUtils.GetGarnetClientSession(requestNodeIndex); | ||
| try | ||
| { | ||
| AssertSlotsNotAssigned(requestNodeIndex); | ||
| _ = client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| ClassicAssert.AreEqual("CLUSTERDOWN Hash slot not served", ex.Message, command.Command); | ||
| return; | ||
| } | ||
| Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| AssertSlotsNotAssigned(requestNodeIndex); | ||
| var ex = Assert.Throws<Exception>(() => client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult(), | ||
| $"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| ClassicAssert.AreEqual("CLUSTERDOWN Hash slot not served", ex.Message, command.Command); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -391,33 +377,19 @@ void SERedisCrossslotTest(BaseCommand command) | |
| { | ||
| if (!command.IsArrayCommand) | ||
| return; | ||
| try | ||
| { | ||
| _ = context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetCrossSlotRequest()); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| ClassicAssert.AreEqual("CROSSSLOT Keys in request do not hash to the same slot", ex.Message, command.Command); | ||
| return; | ||
| } | ||
| Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| var ex = Assert.Throws<RedisServerException>(() => context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetCrossSlotRequest()), | ||
| $"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| ClassicAssert.AreEqual("CROSSSLOT Keys in request do not hash to the same slot", ex.Message, command.Command); | ||
| } | ||
|
|
||
| void GarnetClientSessionCrossslotTest(BaseCommand command) | ||
| { | ||
| if (!command.IsArrayCommand) | ||
| return; | ||
| var client = context.clusterTestUtils.GetGarnetClientSession(requestNodeIndex); | ||
| try | ||
| { | ||
| client.ExecuteAsync(command.GetCrossslotRequestWithCommand).GetAwaiter().GetResult(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| ClassicAssert.AreEqual("CROSSSLOT Keys in request do not hash to the same slot", ex.Message, command.Command); | ||
| return; | ||
| } | ||
| Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| var ex = Assert.Throws<Exception>(() => client.ExecuteAsync(command.GetCrossslotRequestWithCommand).GetAwaiter().GetResult(), | ||
| $"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| ClassicAssert.AreEqual("CROSSSLOT Keys in request do not hash to the same slot", ex.Message, command.Command); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -442,40 +414,26 @@ public void ClusterMOVEDTest() | |
|
|
||
| void SERedisMOVEDTest(BaseCommand command) | ||
| { | ||
| try | ||
| { | ||
| context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| ClassicAssert.IsTrue(ex.Message.StartsWith("Key has MOVED"), command.Command); | ||
| var tokens = ex.Message.Split(' '); | ||
| ClassicAssert.IsTrue(tokens.Length > 10 && tokens[2].Equals("MOVED"), command.Command); | ||
|
|
||
| var _address = tokens[5].Split(':')[0]; | ||
| var _port = int.Parse(tokens[5].Split(':')[1]); | ||
| var _slot = int.Parse(tokens[8]); | ||
| ClassicAssert.AreEqual(address, _address, command.Command); | ||
| ClassicAssert.AreEqual(port, _port, command.Command); | ||
| ClassicAssert.AreEqual(command.GetSlot, _slot, command.Command); | ||
| return; | ||
| } | ||
| Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| var ex = Assert.Throws<RedisServerException>(() => context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect), | ||
| $"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| ClassicAssert.IsTrue(ex.Message.StartsWith("Key has MOVED"), command.Command); | ||
| var tokens = ex.Message.Split(' '); | ||
| ClassicAssert.IsTrue(tokens.Length > 10 && tokens[2].Equals("MOVED"), command.Command); | ||
|
|
||
| var _address = tokens[5].Split(':')[0]; | ||
| var _port = int.Parse(tokens[5].Split(':')[1]); | ||
| var _slot = int.Parse(tokens[8]); | ||
| ClassicAssert.AreEqual(address, _address, command.Command); | ||
| ClassicAssert.AreEqual(port, _port, command.Command); | ||
| ClassicAssert.AreEqual(command.GetSlot, _slot, command.Command); | ||
| } | ||
|
|
||
| void GarnetClientSessionMOVEDTest(BaseCommand command) | ||
| { | ||
| var client = context.clusterTestUtils.GetGarnetClientSession(requestNodeIndex); | ||
| try | ||
| { | ||
| client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| ClassicAssert.AreEqual($"MOVED {command.GetSlot} {address}:{port}", ex.Message, command.Command); | ||
| return; | ||
| } | ||
| Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| var ex = Assert.Throws<Exception>(() => client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult(), | ||
| $"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| ClassicAssert.AreEqual($"MOVED {command.GetSlot} {address}:{port}", ex.Message, command.Command); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -518,40 +476,25 @@ public void ClusterASKTest() | |
|
|
||
| void SERedisASKTest(BaseCommand command) | ||
| { | ||
| RedisResult result = default; | ||
| try | ||
| { | ||
| result = context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| var tokens = ex.Message.Split(' '); | ||
| ClassicAssert.IsTrue(tokens.Length > 10 && tokens[0].Equals("Endpoint"), command.Command + " => " + ex.Message); | ||
|
|
||
| var _address = tokens[1].Split(':')[0]; | ||
| var _port = int.Parse(tokens[1].Split(':')[1]); | ||
| var _slot = int.Parse(tokens[4]); | ||
| ClassicAssert.AreEqual(address, _address, command.Command); | ||
| ClassicAssert.AreEqual(port, _port, command.Command); | ||
| ClassicAssert.AreEqual(command.GetSlot, _slot, command.Command); | ||
| return; | ||
| } | ||
| Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| var ex = Assert.Throws<RedisConnectionException>(() => context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect), | ||
| $"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| var tokens = ex.Message.Split(' '); | ||
| ClassicAssert.IsTrue(tokens.Length > 10 && tokens[0].Equals("Endpoint"), command.Command + " => " + ex.Message); | ||
|
|
||
| var _address = tokens[1].Split(':')[0]; | ||
| var _port = int.Parse(tokens[1].Split(':')[1]); | ||
| var _slot = int.Parse(tokens[4]); | ||
| ClassicAssert.AreEqual(address, _address, command.Command); | ||
| ClassicAssert.AreEqual(port, _port, command.Command); | ||
| ClassicAssert.AreEqual(command.GetSlot, _slot, command.Command); | ||
| } | ||
|
|
||
| void GarnetClientSessionASKTest(BaseCommand command) | ||
| { | ||
| var client = context.clusterTestUtils.GetGarnetClientSession(requestNodeIndex); | ||
| try | ||
| { | ||
| _ = client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult(); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| ClassicAssert.AreEqual($"ASK {command.GetSlot} {address}:{port}", ex.Message, command.Command); | ||
| return; | ||
| } | ||
| Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| var ex = Assert.Throws<Exception>(() => client.ExecuteAsync(command.GetSingleSlotRequestWithCommand).GetAwaiter().GetResult(), | ||
| $"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| ClassicAssert.AreEqual($"ASK {command.GetSlot} {address}:{port}", ex.Message, command.Command); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -591,12 +534,9 @@ void SERedisTRYAGAINTest(BaseCommand command) | |
| ConfigureSlotForMigration(); | ||
| try | ||
| { | ||
| _ = context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| var ex = Assert.Throws<RedisServerException>(() => context.clusterTestUtils.GetServer(requestNodeIndex).Execute(command.Command, command.GetSingleSlotRequest(), CommandFlags.NoRedirect), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like there are still a couple of try/catch blocks in this method? |
||
| $"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| ClassicAssert.AreEqual("TRYAGAIN Multiple keys request during rehashing of slot", ex.Message, command.Command, $"\n{ClusterState()}"); | ||
| return; | ||
| } | ||
| finally | ||
| { | ||
|
|
@@ -611,8 +551,6 @@ void SERedisTRYAGAINTest(BaseCommand command) | |
| Assert.Fail($"Failed executing cleanup. Command: {command.Command} \n{ClusterState()}"); | ||
| } | ||
| } | ||
|
|
||
| Assert.Fail($"Should not reach here. Command: {command.Command} \n{ClusterState()}"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a better debugging experience, please use
Assert.That(ex.Message, Is.EqualTo(<message>));. Otherwise it'll give a generic error, something like "Expected True but was False" rather than "Expected message was "abcd" but got "efgh"".