Skip to content

Commit 104b461

Browse files
JaBistDuNarrischJaBistDuNarrisch
authored andcommitted
Removed tablespace creation and deletion since the server container is recreated before the test runs (once per github workflow run)
1 parent e2aae09 commit 104b461

File tree

1 file changed

+9
-91
lines changed

1 file changed

+9
-91
lines changed

src/Migrator.Tests/Database/DerivedDatabaseIntegrationTestServices/OracleDatabaseIntegrationTestService.cs

Lines changed: 9 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Linq;
33
using System.Text;
4-
using System.Text.RegularExpressions;
54
using System.Threading;
65
using System.Threading.Tasks;
76
using DotNetProjects.Migrator.Framework.Data.Common;
@@ -19,17 +18,21 @@
1918

2019
namespace Migrator.Tests.Database.DerivedDatabaseIntegrationTestServices;
2120

22-
public partial class OracleDatabaseIntegrationTestService(
21+
22+
/// <summary>
23+
/// We use the tablespace users since the server container is recreated before the test runs (once per github workflow run)
24+
/// </summary>
25+
/// <param name="timeProvider"></param>
26+
/// <param name="databaseNameService"></param>
27+
public class OracleDatabaseIntegrationTestService(
2328
TimeProvider timeProvider,
2429
IDatabaseNameService databaseNameService)
2530
: DatabaseIntegrationTestServiceBase(databaseNameService), IDatabaseIntegrationTestService
2631
{
27-
private const string TableSpacePrefix = "TS_";
2832
private const string UserStringKey = "User Id";
2933
private const string PasswordStringKey = "Password";
3034
private const string ReplaceString = "RandomStringThatIsNotQuotedByTheBuilderDoNotChange";
3135
private readonly MappingSchema _mappingSchema = new MappingSchemaFactory().CreateOracleMappingSchema();
32-
private Regex _tablespaceRegex = new("^TS_TESTS_");
3336

3437
/// <summary>
3538
/// Creates an oracle database for test purposes.
@@ -109,62 +112,11 @@ await Parallel.ForEachAsync(
109112
await DropDatabaseAsync(databaseInfoToBeDeleted, cancellationTokenInner);
110113
});
111114

112-
// To be on the safe side we check for table spaces used in tests that have not been deleted for any reason (possible connection issues/concurrent deletion attempts - there is
113-
// no transaction for DDL in Oracle etc.).
114-
var tableSpaceNames = await context.GetTable<DBADataFiles>()
115-
.Select(x => x.TablespaceName)
116-
.ToListAsync(cancellationToken);
117-
118-
var toBeDeletedTableSpaces = tableSpaceNames
119-
.Where(x =>
120-
{
121-
var replacedTablespaceString = TableSpacePrefixRegex().Replace(x, "");
122-
var creationDate = DatabaseNameService.ReadTimeStampFromString(replacedTablespaceString);
123-
return creationDate.HasValue && creationDate.Value < timeProvider.GetUtcNow().Subtract(_MinTimeSpanBeforeDatabaseDeletion);
124-
});
125-
126-
foreach (var toBeDeletedTableSpace in toBeDeletedTableSpaces)
127-
{
128-
var maxAttempts = 4;
129-
var delayBetweenAttempts = TimeSpan.FromSeconds(1);
130-
131-
for (var i = 0; i < maxAttempts; i++)
132-
{
133-
try
134-
{
135-
await context.ExecuteAsync($"DROP TABLESPACE {toBeDeletedTableSpace} INCLUDING CONTENTS AND DATAFILES", cancellationToken);
136-
}
137-
catch
138-
{
139-
var exists = await context.GetTable<DBADataFiles>().AnyAsync(x => x.TablespaceName == toBeDeletedTableSpace, cancellationToken);
140-
141-
if (!exists)
142-
{
143-
break;
144-
}
145-
146-
if (i + 1 == maxAttempts)
147-
{
148-
throw;
149-
}
150-
151-
await Task.Delay(delayBetweenAttempts, cancellationToken);
152-
153-
delayBetweenAttempts = delayBetweenAttempts.Add(TimeSpan.FromSeconds(1));
154-
}
155-
}
156-
}
157-
158-
var tableSpaceName = $"{TableSpacePrefix}{tempUserName}";
159-
160-
var createTablespaceSql = $"CREATE TABLESPACE {tableSpaceName}";
161-
await context.ExecuteAsync(createTablespaceSql, cancellationToken: cancellationToken);
162-
163115
var stringBuilder = new StringBuilder();
164116
stringBuilder.Append($"CREATE USER \"{tempUserName}\" IDENTIFIED BY \"{tempUserName}\"");
165-
stringBuilder.AppendLine($"DEFAULT TABLESPACE {tableSpaceName}");
117+
stringBuilder.AppendLine($"DEFAULT TABLESPACE users");
166118
stringBuilder.AppendLine($"TEMPORARY TABLESPACE TEMP");
167-
stringBuilder.AppendLine($"QUOTA UNLIMITED ON {tableSpaceName}");
119+
stringBuilder.AppendLine($"QUOTA UNLIMITED ON users");
168120

169121
await context.ExecuteAsync(stringBuilder.ToString(), cancellationToken);
170122

@@ -253,40 +205,6 @@ public override async Task DropDatabaseAsync(DatabaseInfo databaseInfo, Cancella
253205
}
254206
}
255207

256-
var tablespaceName = $"{TableSpacePrefix}{databaseInfo.SchemaName}";
257-
258-
maxAttempts = 4;
259-
delayBetweenAttempts = TimeSpan.FromSeconds(1);
260-
261-
for (var i = 0; i < maxAttempts; i++)
262-
{
263-
try
264-
{
265-
await context.ExecuteAsync($"DROP TABLESPACE {tablespaceName} INCLUDING CONTENTS AND DATAFILES", cancellationToken);
266-
}
267-
catch
268-
{
269-
var exists = await context.GetTable<DBADataFiles>().AnyAsync(x => x.TablespaceName == tablespaceName, cancellationToken);
270-
271-
if (!exists)
272-
{
273-
break;
274-
}
275-
276-
if (i + 1 == maxAttempts)
277-
{
278-
throw;
279-
}
280-
281-
await Task.Delay(delayBetweenAttempts, cancellationToken);
282-
283-
delayBetweenAttempts = delayBetweenAttempts.Add(TimeSpan.FromSeconds(1));
284-
}
285-
}
286-
287208
await context.ExecuteAsync($"PURGE RECYCLEBIN", cancellationToken);
288209
}
289-
290-
[GeneratedRegex("^TS_TESTS_")]
291-
private static partial Regex TableSpacePrefixRegex();
292210
}

0 commit comments

Comments
 (0)