-
Notifications
You must be signed in to change notification settings - Fork 118
Conversation
… TopicClientTestBase to a single file use async API only use xunit to parameterize test cases inputs
* Combining unit test classes, and using XUnit MemberDataAttribute to provide test permutations. * Adding DisplayTestMethodNameAttribute to do default logging for each unit test. * Removed ITestOutputHelper since tests are all run in a single thread
Hi @jtaubensee, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
Not all tests are passing, so this is a work in progress. |
@jtaubensee if it's still WIP, could you please change the title to |
@SeanFeldman - Now you're just getting picky..... haha I've got the label on the item. |
Labels come and go, titles stay man. |
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.
Like it! A few little items in the comments.
} | ||
}, | ||
"variables": { | ||
"partitionedQueueName": "partitionedqueue", |
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.
Since entities support dashes, what do you think about giving entity names some love for readability?
partitionedqueue
=>partitioned-queue
nonpartitionedsessionqueue
=>non-partitioned-session-queue
#Resolved
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.
I like it #Resolved
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.
Wait, it's not the end of "Sean's rules" list 😛 #Resolved
@@ -18,7 +18,8 @@ | |||
}, | |||
"Microsoft.NETCore.Platforms": "1.1.0", | |||
"xunit": "2.2.0-beta4-build3444", | |||
"dotnet-test-xunit": "2.2.0-preview2-build1029" | |||
"dotnet-test-xunit": "2.2.0-preview2-build1029", | |||
"Microsoft.Extensions.PlatformAbstractions": "1.1.0" |
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.
What's this one is used for? #Resolved
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.
Its used in the logger for DisplayTestMethodNameAttribute to log what platform the tests are running on. i.e. .NET Core #Resolved
var deferredMessage = await queueClient.ReceiveBySequenceNumberAsync(deferredSequenceNumber); | ||
await deferredMessage.CompleteAsync(); | ||
|
||
queueClient.Close(); |
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.
async
} | ||
finally | ||
{ | ||
queueClient.Close(); |
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.
Async? there are a few of these. #Resolved
{ | ||
QueueClient queueClient = QueueClient.CreateFromConnectionString(this.ConnectionString); | ||
var queueClient = QueueClient.CreateFromConnectionString(TestUtility.GetEntityConnectionString(queueName)); |
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.
❤️ yes! #Resolved
@jtaubensee can I also suggest to add PowerShell steps to the # log in
Login-AzureRmAccount
# see your subscriptions
Get-AzureSubscription
# select subscription to use
Set-AzureRmContext -SubscriptionName "<subscription-name>"
# create a new resource group (if needed)
New-AzureRmResourceGroup -Name "ASB-client-tests-RG" -Location "West US"
# verify deployment script
Test-AzureRmResourceGroupDeployment -ResourceGroupName "ASB-client-tests-RG" -TemplateFile <path-to>\templates\azuredeploy.json
# deploy
New-AzureRmResourceGroupDeployment -Name "ASB-client-tests-Deployment" -ResourceGroupName "ASB-client-tests-RG" -TemplateFile <path-to>\templates\azuredeploy.json |
using Xunit; | ||
|
||
public class BrokeredMessageTests | ||
{ | ||
[Fact] | ||
async Task BrokeredMessageOperationsTest() |
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.
This test is brutal 😞 Just the name BrokeredMessageOperationsTest
indicates that there are multiple tests hidden within a single test.
I suggest to break this apart into multiple ones.
// Send a Message, Receive/ Abandon and Complete it using BrokeredMessage methods | ||
queueClient = QueueClient.CreateFromConnectionString( | ||
TestUtility.GetEntityConnectionString(Constants.PartitionedQueueName), | ||
ReceiveMode.ReceiveAndDelete); |
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.
How did this become ReceiveAndDelete
? The comments says PeekLock
. Test is failing because of of the incorrect mode used.
Again, it's a test on its own 😉 Personally, I'd call it When_receiving_in_PeekLock_mode.Should_be_able_to_abandon
.
TestUtility.GetEntityConnectionString(Constants.PartitionedQueueName), | ||
ReceiveMode.ReceiveAndDelete); | ||
|
||
await TestUtility.SendMessagesAsync(queueClient.InnerSender, 1); |
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.
Question: why do we use the internal queueClient.InnerSender
of the queueClient
this is a sign of something that is not right. Testing a unit (queue client) should go through the unit, not its internals.
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.
I agree, we should test using the exposed classes. But this was to make the testing a little more easier and possibly re-use the code rather than have to rewrite the same code for queues/topic subscriptions..Since we'r still debating whether its a good idea to open the MessageSender/Receiver or keep a smaller surface area and making it as specific as possible until and unless for writing tests like here etc. Inputs welcome on that. But until then we thought we'll keep it this way early on. As we gather more feedback on opening the Sender/Receiver, we can change the tests too to reflect the same behavior.
TestUtility.GetEntityConnectionString(Constants.PartitionedQueueName), | ||
ReceiveMode.ReceiveAndDelete); | ||
|
||
await TestUtility.SendMessagesAsync(queueClient.InnerSender, 1); |
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.
same question - why through internal?
Assert.True(message.MessageId == messageId); | ||
|
||
TestUtility.Log("Sleeping 10 seconds..."); | ||
Thread.Sleep(TimeSpan.FromSeconds(10)); |
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.
Assert.True(firstLockedUntilUtcTime >= initialSessionLockedUntilTime + TimeSpan.FromSeconds(10)); | ||
|
||
TestUtility.Log("Sleeping 5 seconds..."); | ||
Thread.Sleep(TimeSpan.FromSeconds(5)); |
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.
Will repeat it #Resolved
{ | ||
public static IEnumerable<object> TestPermutations => new object[] | ||
{ | ||
new object[] { Constants.PartitionedQueueName }, |
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.
Using wrong queue name. Should be Constants.SessionPartitionedQueueName
. #Resolved
public static IEnumerable<object> TestPermutations => new object[] | ||
{ | ||
new object[] { Constants.PartitionedQueueName }, | ||
new object[] { Constants.NonPartitionedQueueName }, |
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.
Using wrong queue name. Should be Constants.SessionNonPartitionedQueueName
. #Resolved
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.
The exception thrown in AmqpLinkCreator
is not propagated properly. Original exception contains information about non-sessioned queue used for sessions. But exception thrown didn't contain that info.
returnedSessionState = await sessionReceiver.GetStateAsync(); | ||
using (StreamReader reader = new StreamReader(returnedSessionState, Encoding.UTF8)) | ||
{ | ||
string returnedSessionStateString = reader.ReadToEnd(); |
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.
var returnedSessionState = await sessionReceiver.GetStateAsync(); | ||
using (StreamReader reader = new StreamReader(returnedSessionState, Encoding.UTF8)) | ||
{ | ||
string returnedSessionStateString = reader.ReadToEnd(); |
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.
returnedSessionState = await sessionReceiver.GetStateAsync(); | ||
using (StreamReader reader = new StreamReader(returnedSessionState, Encoding.UTF8)) | ||
{ | ||
string returnedSessionStateString = reader.ReadToEnd(); |
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.
async
receivedMessages = await TestUtility.ReceiveMessagesAsync(messageReceiver, messageCount - deferMessagesCount, this.Output); | ||
await TestUtility.CompleteMessagesAsync(messageReceiver, receivedMessages, this.Output); | ||
receivedMessages = await TestUtility.ReceiveMessagesAsync(messageReceiver, messageCount - deferMessagesCount); | ||
await TestUtility.CompleteMessagesAsync(messageReceiver, receivedMessages); | ||
Assert.True(receivedMessages.Count() == messageCount - deferMessagesCount); | ||
|
||
// Receive / Abandon deferred messages | ||
receivedMessages = await messageReceiver.ReceiveBySequenceNumberAsync(sequenceNumbers); | ||
Assert.True(receivedMessages.Count() == 5); |
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.
Evil. When fails, all it says "expected True, but was False". Good luck with that :)
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.
@jtaubensee added comments to point where tests are failing. Once those are addressed (and hopefully tests are more focused), PR should be good.
Some of the tests are failing due to #17 - no proper cleanup.
…o peeklock, and moving all brokered messages tests to a single class.
This also addresses #43. |
@SeanFeldman - I agree with you about the test names, but I dont want to have two different conventions in the same repo. I know it could be a lot of work, but I'd prefer to have a PR where all of the test names are changed to the format you suggest, rather than bit by bit. |
await this.PeekLockWithDeadLetterTestCase(topicClient.InnerSender, subscriptionClient.InnerReceiver, deadLetterSubscriptionClient.InnerReceiver, messageCount); | ||
} | ||
finally | ||
{ |
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.
Close the subscriptionClient here as well
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.
Thanks @vinaysurya - Hopefully that will help with the tests running multiple times!
Assert.True(message.MessageId == messageId); | ||
TestUtility.Log($"Received Message: {message.MessageId} from Session: {sessionReceiver.SessionId}"); | ||
await message.CompleteAsync(); | ||
TestUtility.Log($"Completed Message: {message.MessageId} for Session: {sessionReceiver.SessionId}"); |
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.
Add a last step to close the session receiver here as well
@jtaubensee sadly, the new test names do not reflect the meaning.
Then perhaps don't wipe the names and leave them as comments/TODOs? No offence, but the new names are cryptic and you'll be adding work to decypher them later. Which might become a hassle so no one will do it. |
Building off of Sean's previous PR #38: