-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: or-1894 return bad request instead of server error when scroll t…
…imed out
- Loading branch information
Showing
3 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/OrganisationRegistry.Api/Infrastructure/ElasticsearchScrollTimeoutException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace OrganisationRegistry.Api.Infrastructure; | ||
|
||
using System; | ||
|
||
public class ElasticsearchScrollTimeoutException : DomainException | ||
{ | ||
public ElasticsearchScrollTimeoutException() | ||
{ | ||
} | ||
|
||
public ElasticsearchScrollTimeoutException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public ElasticsearchScrollTimeoutException(string message, Exception inner) : base(message, inner) | ||
{ | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
test/OrganisationRegistry.ElasticSearch.Tests/OrganisationSearchTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
namespace OrganisationRegistry.ElasticSearch.Tests; | ||
|
||
using FluentAssertions; | ||
using Infrastructure.Events; | ||
using Microsoft.Extensions.Logging; | ||
using Projections.Infrastructure; | ||
using Scenario; | ||
using Xunit; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Api; | ||
using AutoFixture; | ||
using Location; | ||
using Location.Events; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Moq; | ||
using OpenSearch.Net; | ||
using Organisation.Events; | ||
using OrganisationRegistry.Tests.Shared; | ||
using OrganisationRegistry.Tests.Shared.Stubs; | ||
using Organisations; | ||
using Osc; | ||
using Projections.Organisations; | ||
using Scenario.Specimen; | ||
using SqlServer.Infrastructure; | ||
|
||
[Collection(nameof(ElasticSearchFixture))] | ||
public class OrganisationSearchTests | ||
{ | ||
private readonly ElasticSearchFixture _fixture; | ||
private readonly TestEventProcessor _eventProcessor; | ||
private readonly LocationUpdated? lastLocationEvent; | ||
|
||
public OrganisationSearchTests(ElasticSearchFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
// [Fact] | ||
[Fact(Skip = "Manual only")] | ||
public async Task ElasticSearchClient_Search_With_Scroll_Timedout_Does_Not_Throw_Exception() | ||
{ | ||
var client = _fixture.Elastic.ReadClient; | ||
var indexName = "scroll-timeout-test-index"; | ||
|
||
try | ||
{ | ||
var indexResponse = await _fixture.Elastic.WriteClient.Indices.CreateAsync(indexName); | ||
|
||
var scrollTimeout = "1s"; | ||
var scroll = await client.SearchAsync<OrganisationDocument>( | ||
s => s | ||
.Index(indexResponse.Index) | ||
.From(0) | ||
.Size(5) | ||
.Scroll(scrollTimeout)); | ||
|
||
await Task.Delay(5000); | ||
scroll = await client.ScrollAsync<OrganisationDocument>(scrollTimeout, scroll.ScrollId); | ||
|
||
Assert.Equal(scroll.ServerError.Error.Type, "search_phase_execution_exception"); | ||
} | ||
finally | ||
{ | ||
await _fixture.Elastic.WriteClient.Indices.DeleteAsync(indexName); | ||
} | ||
} | ||
} |