fixed test by adding semaphores. Also reduced collections name to avoid hitting the 127 byte limit regarding index names.

This commit is contained in:
alexandre-spieser
2018-09-30 19:26:25 +01:00
parent 0b939592ba
commit fa6687c084
3 changed files with 37 additions and 16 deletions
@@ -5,7 +5,7 @@ using System;
namespace CoreIntegrationTests namespace CoreIntegrationTests
{ {
[CollectionName("CoreTestingCollectionNameAttributePartitionedTKey")] [CollectionName("CoreTestingCNameAttrPart")]
public class CorePartitionedCollectionNameDoc : TestDoc, IPartitionedDocument public class CorePartitionedCollectionNameDoc : TestDoc, IPartitionedDocument
{ {
public CorePartitionedCollectionNameDoc() public CorePartitionedCollectionNameDoc()
@@ -5,7 +5,7 @@ using System;
namespace CoreIntegrationTests namespace CoreIntegrationTests
{ {
[CollectionName("TestingCollectionNameAttributePartitionedTKey")] [CollectionName("TestingCNameAttrPartTKey")]
public class CoreTKeyPartitionedCollectionNameDoc : TestDoc<Guid>, IPartitionedDocument public class CoreTKeyPartitionedCollectionNameDoc : TestDoc<Guid>, IPartitionedDocument
{ {
public CoreTKeyPartitionedCollectionNameDoc() public CoreTKeyPartitionedCollectionNameDoc()
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Xunit; using Xunit;
@@ -946,6 +947,10 @@ namespace CoreIntegrationTests.Infrastructure
#region Index Management #region Index Management
//Instantiate a Singleton of the Semaphore with a value of 1. This means that only 1 thread can be granted access at a time.
static SemaphoreSlim textIndexSemaphore = new SemaphoreSlim(1, 1);
[Fact] [Fact]
public async Task CreateTextIndexNoOptionAsync() public async Task CreateTextIndexNoOptionAsync()
{ {
@@ -953,6 +958,9 @@ namespace CoreIntegrationTests.Infrastructure
const string expectedIndexName = "SomeContent_text"; const string expectedIndexName = "SomeContent_text";
// Act // Act
await textIndexSemaphore.WaitAsync();
try
{
var result = await SUT.CreateTextIndexAsync<T>(x => x.SomeContent, null, PartitionKey); var result = await SUT.CreateTextIndexAsync<T>(x => x.SomeContent, null, PartitionKey);
// Assert // Assert
@@ -962,18 +970,26 @@ namespace CoreIntegrationTests.Infrastructure
// Cleanup // Cleanup
await SUT.DropIndexAsync<T>(expectedIndexName, PartitionKey); await SUT.DropIndexAsync<T>(expectedIndexName, PartitionKey);
} }
finally
{
textIndexSemaphore.Release();
}
}
[Fact] [Fact]
public async Task CreateTextIndexWithOptionAsync() public async Task CreateTextIndexWithOptionAsync()
{ {
// Arrange // Arrange
string expectedIndexName = $"SomeContent_text_{Guid.NewGuid()}"; string expectedIndexName = $"{Guid.NewGuid()}";
var option = new IndexCreationOptions var option = new IndexCreationOptions
{ {
Name = expectedIndexName Name = expectedIndexName
}; };
await textIndexSemaphore.WaitAsync();
try
{
// Act // Act
var result = await SUT.CreateTextIndexAsync<T>(x => x.SomeContent, option, PartitionKey); var result = await SUT.CreateTextIndexAsync<T>(x => x.AddedAtUtc, option, PartitionKey);
// Assert // Assert
var listOfIndexNames = await SUT.GetIndexesNamesAsync<T>(PartitionKey); var listOfIndexNames = await SUT.GetIndexesNamesAsync<T>(PartitionKey);
@@ -982,6 +998,11 @@ namespace CoreIntegrationTests.Infrastructure
// Cleanup // Cleanup
await SUT.DropIndexAsync<T>(expectedIndexName, PartitionKey); await SUT.DropIndexAsync<T>(expectedIndexName, PartitionKey);
} }
finally
{
textIndexSemaphore.Release();
}
}
#endregion Index Management #endregion Index Management