Skip to content

Commit

Permalink
Concurrency supported in Smoke Tests (#7169)
Browse files Browse the repository at this point in the history
* .NET smoke Test Sample

Performs functionalities with Key Vault, Identity, Event Hubs and Blob Storage Track 2 SDKs.

* Env Variables names changed

The names were changed to match the name convention for environment variables.

* Update .gitignore

* gitignore updated

A gitignore file was created in the SmokeTest folder, and now all launchSettings.json files are being ignored.

* Exit Codes, PascalCase and refactoring of the static methods.

Work based on the reviews from the PR #6652. The public methods are now in PascalCase, the methods does not longer return English strings, instead they return booleans or Exceptions.  And Exit Codes handling was implemented.

* Class names changed

Class names were changed to match the following pattern: <service>Test. Example: BlobStorage -> BlobStorageTest.

* Comments

XML comments were added and some unnecesary comments were deleted.

* Higher order functions

Use of higher order functions to dry up the code.

* Test classes refactured

Drying up the code by using high order functions.

* Create CosmosDBTest.cs

* Cosmos DB implementation

Tests done with Mirosoft.Azure.DocumentDB SDK.

* Update CosmosDBTest.cs

* Update CosmosDBTest.cs

* Unnecessary blank lines removed

* ExecuteTest typo

* Base class deleted

The samples not longer need the "TestBase" class to run.

* BlobTestSource.tst deleted

This text file is not going to be needed any more since the test Blob is being created within the code.

* Static Classes

All classes are now static.

* Pair programming comments

* Concurrency support

* License headers added

* License header added

* Adapted for concurrency

* Use of string interpolation

* Use of string interpolation

* Update EventHubsTest.cs
  • Loading branch information
JonathanCrd authored Aug 8, 2019
1 parent 72028f6 commit d73876f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
8 changes: 6 additions & 2 deletions samples/SmokeTest/SmokeTest/BlobStorageTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Azure.Storage.Blobs;
// ------------------------------------
// Copyright(c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------
using Azure.Storage.Blobs;
using System;
using System.IO;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -27,7 +31,7 @@ public static async Task RunTests()

string connectionString = Environment.GetEnvironmentVariable("BLOB_CONNECTION_STRING");
string containerName = "mycontainer"; //The container must exists, this sample is not creating it.
string blobName = "netSmokeTestBlob";
string blobName = $"netSmokeTestBlob-{Guid.NewGuid()}.txt";
serviceClient = new BlobServiceClient(connectionString);
blobClient = serviceClient.GetBlobContainerClient(containerName).GetBlockBlobClient(blobName);

Expand Down
8 changes: 6 additions & 2 deletions samples/SmokeTest/SmokeTest/CosmosDBTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Azure.Storage.Blobs.Models;
// ------------------------------------
// Copyright(c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------
using Azure.Storage.Blobs.Models;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Newtonsoft.Json;
Expand Down Expand Up @@ -34,7 +38,7 @@ public class Moon
class CosmosDBTest
{
private static DocumentClient client;
private const string DataBaseName = "netSolarSystemDB";
private static string DataBaseName = $"netSolarSystemDB-{Guid.NewGuid()}";
private const string CollectionName = "PlanetsCollection";
private static List<Planet> planets = new List<Planet>();

Expand Down
29 changes: 7 additions & 22 deletions samples/SmokeTest/SmokeTest/EventHubsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Azure;
// ------------------------------------
// Copyright(c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------
using Azure;
using Azure.Messaging.EventHubs;
using Microsoft.Azure.Amqp.Framing;
using System;
Expand Down Expand Up @@ -79,35 +83,16 @@ private static async Task SendAndReceiveEvents()
{
receivedEvents.AddRange(await receiver.ReceiveAsync(eventBatch.Length + 10, TimeSpan.FromMilliseconds(25)));
}
index = 0;

//Check if at least one event was received in order to start validation
if (receivedEvents.Count == 0)
{
throw new Exception(String.Format("Error, No events received."));
}
Console.Write(receivedEvents.Count() + " events received.\n");

Console.WriteLine("Beginning validation...");
foreach (var receivedEvent in receivedEvents)
if (receivedEvents.Count() < eventBatch.Count())
{
var receivedEventMessage = Encoding.UTF8.GetString(receivedEvent.Body.ToArray());
var sentEventMessage = Encoding.UTF8.GetString(eventBatch[index].Body.ToArray());

if (receivedEventMessage == sentEventMessage)
{
Console.WriteLine("\tEvent '" + receivedEventMessage + "' correctly validated.");
}
else
{
throw new Exception(String.Format("Error, Event: '" + receivedEventMessage + "' was not expected."));
}
index++;
}

if (index < eventBatch.Count())
{
throw new Exception(String.Format("Error, expecting " + eventBatch.Count().ToString() + " events, but only got " + index.ToString() + "."));
throw new Exception(String.Format($"Error, expecting {eventBatch.Count()} events, but only got {receivedEvents.Count().ToString()}."));
}

Console.WriteLine("done");
Expand Down
8 changes: 6 additions & 2 deletions samples/SmokeTest/SmokeTest/KeyVaultTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using Azure.Identity;
// ------------------------------------
// Copyright(c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using System;
using System.Threading.Tasks;
Expand All @@ -7,7 +11,7 @@ namespace SmokeTest
{
class KeyVaultTest
{
private const string SecretName = "SmokeTestSecret";
private static string SecretName = $"SmokeTestSecret-{Guid.NewGuid()}";
private const string SecretValue = "smokeTestValue";
private static SecretClient client;

Expand Down
7 changes: 6 additions & 1 deletion samples/SmokeTest/SmokeTest/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using Azure.Messaging.EventHubs;
// ------------------------------------
// Copyright(c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------
// ------------------------------------
using Azure.Messaging.EventHubs;
using System;
using System.Reflection.Metadata;
using System.Threading.Tasks;
Expand Down

0 comments on commit d73876f

Please sign in to comment.