Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Unit test refactoring #41

Merged
merged 12 commits into from
Dec 19, 2016
Merged

Unit test refactoring #41

merged 12 commits into from
Dec 19, 2016

Conversation

jtaubensee
Copy link
Contributor

Building off of Sean's previous PR #38:

  • Combining unit test classes, 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
  • Also setting constants, so there is only the need for a single connection string. We will provide an ARM template to automatically provision resources.

SeanFeldman and others added 2 commits December 15, 2016 01:29
… 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
@msftclas
Copy link

Hi @jtaubensee, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!


It looks like you're a Microsoft contributor (John Taubensee). If you're full-time, we DON'T require a Contribution License Agreement. If you are a vendor, please DO sign the electronic Contribution License Agreement. It will take 2 minutes and there's no faxing! https://cla.microsoft.com.

TTYL, MSBOT;

@jtaubensee
Copy link
Contributor Author

Not all tests are passing, so this is a work in progress.

@SeanFeldman
Copy link
Collaborator

@jtaubensee if it's still WIP, could you please change the title to [WIP] Unit test refactoring?
To get it even better, you could install this addon
image

@jtaubensee
Copy link
Contributor Author

@SeanFeldman - Now you're just getting picky..... haha I've got the label on the item.

@SeanFeldman
Copy link
Collaborator

Labels come and go, titles stay man.

Copy link
Collaborator

@SeanFeldman SeanFeldman left a 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",
Copy link
Collaborator

@SeanFeldman SeanFeldman Dec 16, 2016

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it #Resolved

Copy link
Collaborator

@SeanFeldman SeanFeldman Dec 16, 2016

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"
Copy link
Collaborator

@SeanFeldman SeanFeldman Dec 16, 2016

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

Copy link
Contributor Author

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async

}
finally
{
queueClient.Close();
Copy link
Collaborator

@SeanFeldman SeanFeldman Dec 16, 2016

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));
Copy link
Collaborator

@SeanFeldman SeanFeldman Dec 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ yes! #Resolved

@jtaubensee jtaubensee changed the title Unit test refactoring [WIP] Unit test refactoring Dec 16, 2016
@SeanFeldman
Copy link
Collaborator

SeanFeldman commented Dec 18, 2016

@jtaubensee can I also suggest to add PowerShell steps to the readme.md file to create namespace with entities?

# 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()
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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.

Copy link
Member

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);
Copy link
Collaborator

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));
Copy link
Collaborator

@SeanFeldman SeanFeldman Dec 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image #Resolved

Assert.True(firstLockedUntilUtcTime >= initialSessionLockedUntilTime + TimeSpan.FromSeconds(10));

TestUtility.Log("Sleeping 5 seconds...");
Thread.Sleep(TimeSpan.FromSeconds(5));
Copy link
Collaborator

@SeanFeldman SeanFeldman Dec 19, 2016

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 },
Copy link
Collaborator

@SeanFeldman SeanFeldman Dec 19, 2016

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 },
Copy link
Collaborator

@SeanFeldman SeanFeldman Dec 19, 2016

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

Copy link
Collaborator

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();
Copy link
Collaborator

@SeanFeldman SeanFeldman Dec 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
#Resolved

var returnedSessionState = await sessionReceiver.GetStateAsync();
using (StreamReader reader = new StreamReader(returnedSessionState, Encoding.UTF8))
{
string returnedSessionStateString = reader.ReadToEnd();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

returnedSessionState = await sessionReceiver.GetStateAsync();
using (StreamReader reader = new StreamReader(returnedSessionState, Encoding.UTF8))
{
string returnedSessionStateString = reader.ReadToEnd();
Copy link
Collaborator

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);
Copy link
Collaborator

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 :)

Copy link
Collaborator

@SeanFeldman SeanFeldman left a 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.

@jtaubensee
Copy link
Contributor Author

This also addresses #43.

@jtaubensee
Copy link
Contributor Author

@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
{
Copy link
Member

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

Copy link
Contributor Author

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!

@jtaubensee jtaubensee changed the title [WIP] Unit test refactoring Unit test refactoring Dec 19, 2016
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}");
Copy link
Member

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

@vinaysurya
Copy link
Member

:shipit:

@SeanFeldman
Copy link
Collaborator

@jtaubensee sadly, the new test names do not reflect the meaning.

...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.

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.

@jtaubensee jtaubensee merged commit 9030d47 into Azure:master Dec 19, 2016
@jtaubensee jtaubensee deleted the unit-tests branch December 19, 2016 22:40
@jtaubensee jtaubensee modified the milestone: 0.0.1-preview Dec 20, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants