Skip to content

Commit c8bf6be

Browse files
committed
Add test to check that indexes are reset on setup
1 parent 1fe5c7c commit c8bf6be

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/ServiceControl.Audit.Persistence.RavenDB/DatabaseSetup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public async Task Execute(IDocumentStore documentStore, CancellationToken cancel
2323

2424
await UpdateDatabaseSettings(documentStore, configuration.Name, cancellationToken);
2525

26-
await CreateIndexes(documentStore, cancellationToken);
26+
await CreateIndexes(documentStore, configuration.EnableFullTextSearch, cancellationToken);
2727

2828
await ConfigureExpiration(documentStore, cancellationToken);
2929
}
@@ -79,13 +79,13 @@ public static async Task DeleteLegacySagaDetailsIndex(IDocumentStore documentSto
7979
}
8080
}
8181

82-
async Task CreateIndexes(IDocumentStore documentStore, CancellationToken cancellationToken)
82+
internal static async Task CreateIndexes(IDocumentStore documentStore, bool enableFreeTextSearch, CancellationToken cancellationToken)
8383
{
8484
await DeleteLegacySagaDetailsIndex(documentStore, cancellationToken);
8585

8686
List<AbstractIndexCreationTask> indexList = [new FailedAuditImportIndex(), new SagaDetailsIndex()];
8787

88-
if (configuration.EnableFullTextSearch)
88+
if (enableFreeTextSearch)
8989
{
9090
indexList.Add(new MessagesViewIndexWithFullTextSearch());
9191
await documentStore.Maintenance.SendAsync(new DeleteIndexOperation(MessagesViewIndexName), cancellationToken);

src/ServiceControl.Audit.Persistence.Tests.RavenDB/IndexSetupTests.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
namespace ServiceControl.Audit.Persistence.Tests;
22

3-
using System;
3+
using System.Threading;
44
using System.Threading.Tasks;
5-
using global::ServiceControl.Audit.Persistence.RavenDB;
65
using NUnit.Framework;
6+
using Persistence.RavenDB;
7+
using Persistence.RavenDB.Indexes;
78
using Raven.Client.Documents.Indexes;
89
using Raven.Client.Documents.Operations.Indexes;
910

1011
[TestFixture]
1112
class IndexSetupTests : PersistenceTestFixture
1213
{
1314
[Test]
14-
public async Task Corax_should_the_defaul_search_engine_type()
15+
public async Task Corax_should_be_the_default_search_engine_type()
1516
{
1617
var indexes = await configuration.DocumentStore.Maintenance.SendAsync(new GetIndexesOperation(0, int.MaxValue));
1718

@@ -31,4 +32,27 @@ public async Task Free_text_search_index_should_be_used_by_default()
3132
Assert.That(nonFreeTextIndex, Is.Null);
3233
Assert.That(freeTextIndex, Is.Not.Null);
3334
}
35+
36+
[Test]
37+
public async Task Indexes_should_be_reset_on_setup()
38+
{
39+
var index = new MessagesViewIndexWithFullTextSearch { Configuration = { ["Indexing.Static.SearchEngineType"] = SearchEngineType.Lucene.ToString() } };
40+
41+
await IndexCreation.CreateIndexesAsync([index], configuration.DocumentStore);
42+
43+
//TODO: find a better way
44+
await Task.Delay(1000);
45+
46+
var indexStatsBefore = await configuration.DocumentStore.Maintenance.SendAsync(new GetIndexStatisticsOperation(index.IndexName));
47+
48+
Assert.That(indexStatsBefore.SearchEngineType, Is.EqualTo(SearchEngineType.Lucene));
49+
50+
await DatabaseSetup.CreateIndexes(configuration.DocumentStore, true, CancellationToken.None);
51+
52+
//TODO: find a better way
53+
await Task.Delay(1000);
54+
55+
var indexStatsAfter = await configuration.DocumentStore.Maintenance.SendAsync(new GetIndexStatisticsOperation(index.IndexName));
56+
Assert.That(indexStatsAfter.SearchEngineType, Is.EqualTo(SearchEngineType.Corax));
57+
}
3458
}

0 commit comments

Comments
 (0)