Skip to content

Commit 0b97945

Browse files
committed
Add lock mode tests
1 parent c8bf6be commit 0b97945

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
namespace ServiceControl.Audit.Persistence.Tests;
22

3+
using System;
34
using System.Threading;
45
using System.Threading.Tasks;
56
using NUnit.Framework;
67
using Persistence.RavenDB;
78
using Persistence.RavenDB.Indexes;
89
using Raven.Client.Documents.Indexes;
910
using Raven.Client.Documents.Operations.Indexes;
11+
using Raven.Client.Exceptions.Documents.Indexes;
1012

1113
[TestFixture]
1214
class IndexSetupTests : PersistenceTestFixture
@@ -55,4 +57,50 @@ public async Task Indexes_should_be_reset_on_setup()
5557
var indexStatsAfter = await configuration.DocumentStore.Maintenance.SendAsync(new GetIndexStatisticsOperation(index.IndexName));
5658
Assert.That(indexStatsAfter.SearchEngineType, Is.EqualTo(SearchEngineType.Corax));
5759
}
60+
61+
[Test]
62+
public async Task Indexes_should_not_be_reset_on_setup_when_locked_as_ignore()
63+
{
64+
var index = new MessagesViewIndexWithFullTextSearch { Configuration = { ["Indexing.Static.SearchEngineType"] = SearchEngineType.Lucene.ToString() } };
65+
66+
await IndexCreation.CreateIndexesAsync([index], configuration.DocumentStore);
67+
68+
await configuration.DocumentStore.Maintenance.SendAsync(new SetIndexesLockOperation(new SetIndexesLockOperation.Parameters
69+
{
70+
IndexNames = [index.IndexName],
71+
Mode = IndexLockMode.LockedIgnore
72+
}));
73+
74+
//TODO: find a better way
75+
await Task.Delay(1000);
76+
77+
var indexStatsBefore = await configuration.DocumentStore.Maintenance.SendAsync(new GetIndexStatisticsOperation(index.IndexName));
78+
79+
Assert.That(indexStatsBefore.SearchEngineType, Is.EqualTo(SearchEngineType.Lucene));
80+
81+
82+
await DatabaseSetup.CreateIndexes(configuration.DocumentStore, true, CancellationToken.None);
83+
84+
//TODO: find a better way
85+
await Task.Delay(1000);
86+
87+
var indexStatsAfter = await configuration.DocumentStore.Maintenance.SendAsync(new GetIndexStatisticsOperation(index.IndexName));
88+
Assert.That(indexStatsAfter.SearchEngineType, Is.EqualTo(SearchEngineType.Lucene));
89+
}
90+
91+
[Test]
92+
public async Task Indexes_should_not_be_reset_on_setup_when_locked_as_error()
93+
{
94+
var index = new MessagesViewIndexWithFullTextSearch { Configuration = { ["Indexing.Static.SearchEngineType"] = SearchEngineType.Lucene.ToString() } };
95+
96+
await IndexCreation.CreateIndexesAsync([index], configuration.DocumentStore);
97+
98+
await configuration.DocumentStore.Maintenance.SendAsync(new SetIndexesLockOperation(new SetIndexesLockOperation.Parameters
99+
{
100+
IndexNames = [index.IndexName],
101+
Mode = IndexLockMode.LockedError
102+
}));
103+
104+
Assert.ThrowsAsync<IndexCreationException>(async () => await DatabaseSetup.CreateIndexes(configuration.DocumentStore, true, CancellationToken.None));
105+
}
58106
}

0 commit comments

Comments
 (0)