[Tests] ChainingSearchTest - Improve stability (#3762)

* Improvement in test to make it more stable

* Decrease batch size
This commit is contained in:
Fernando Henrique Inocêncio Borba Ferreira 2024-03-20 06:52:48 -07:00 коммит произвёл GitHub
Родитель 072b14fbcb
Коммит e815c369af
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 41 добавлений и 6 удалений

Просмотреть файл

@ -268,17 +268,52 @@ namespace Microsoft.Health.Fhir.Tests.E2E.Rest.Search
[Fact]
public async Task GivenANonSelectiveChainingQueryInCosmosDb_WhenSearched_ThenAnErrorShouldBeThrown()
{
string query = $"subject:Patient.gender=male";
string tag = Guid.NewGuid().ToString();
string query = $"_tag={tag}&subject:Patient.gender=male";
Patient resource = Samples.GetJsonSample("Patient-f001").ToPoco<Patient>();
// Create 1001 patients that exceed the sub-query limit
foreach (IEnumerable<int> batch in Enumerable.Range(1, 1001).TakeBatch(100))
resource.Meta = new Meta()
{
await Task.WhenAll(batch.Select(_ => Client.CreateAsync(resource)));
Tag = new List<Coding>()
{
new Coding("testTag", tag),
},
};
try
{
// Safe number to create resources without hitting any Cosmos DB limit, as the number of RUs assigned is low.
const int batchSize = 10;
// Create 1001 patients that exceed the sub-query limit
foreach (IEnumerable<int> batch in Enumerable.Range(1, 1001).TakeBatch(batchSize))
{
await Task.WhenAll(batch.Select(_ => Client.CreateAsync(resource)));
}
}
catch (Exception ex)
{
throw new Exception($"Failed while creating resources: {ex.Message}", ex);
}
await Assert.ThrowsAsync<FhirClientException>(async () => await Client.SearchAsync(ResourceType.Observation, query));
try
{
await Client.SearchAsync(ResourceType.Observation, query);
Assert.Fail("Test was expected to fail with a FhirException.");
}
catch (FhirClientException fce)
{
const string expectedMessage = "Sub-queries in a chained expression cannot return more than 1000 results";
Assert.True(
fce.Message.Contains(expectedMessage),
$"FhirClientException received is different than the one expected: Message: {fce.Message}");
}
catch (Exception ex)
{
Assert.Fail($"Unexpected exception thrown: {ex}");
}
}
[HttpIntegrationFixtureArgumentSets(DataStore.SqlServer, Format.Json)]