Skip to content

Commit a7d7b44

Browse files
committed
fixes
1 parent 7ec4ef1 commit a7d7b44

File tree

1 file changed

+39
-44
lines changed

1 file changed

+39
-44
lines changed

src/EfCore.Ydb.FunctionalTests/TestUtilities/YdbTestStore.cs

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
using EfCore.Ydb.Extensions;
55
using Microsoft.EntityFrameworkCore;
66
using Microsoft.EntityFrameworkCore.TestUtilities;
7-
using Microsoft.IdentityModel.Tokens;
87
using Ydb.Sdk.Ado;
98

109
namespace EfCore.Ydb.FunctionalTests.TestUtilities;
1110

1211
public class YdbTestStore : RelationalTestStore
1312
{
14-
public const int CommandTimeout = 690;
13+
public const int CommandTimeout = 600;
1514
private readonly string? _scriptPath;
1615
private readonly string? _additionalSql;
1716

@@ -22,7 +21,7 @@ public YdbTestStore(
2221
string? connectionStringOptions = null,
2322
bool shared = true,
2423
bool useConnectionString = false
25-
) : base(name, shared, CreateConnection(name, shared))
24+
) : base(name, shared, CreateConnection())
2625
{
2726
_scriptPath = scriptPath;
2827
_additionalSql = additionalSql;
@@ -46,11 +45,11 @@ protected override async Task InitializeAsync(
4645
{
4746
if (_scriptPath is not null)
4847
{
49-
ExecuteScript(_scriptPath);
48+
await ExecuteScript(_scriptPath);
5049

5150
if (_additionalSql is not null)
5251
{
53-
Execute(Connection, command => command.ExecuteNonQuery(), _additionalSql);
52+
await ExecuteAsync(Connection, command => command.ExecuteNonQueryAsync(), _additionalSql);
5453
}
5554
}
5655
else
@@ -60,7 +59,7 @@ protected override async Task InitializeAsync(
6059

6160
if (_additionalSql is not null)
6261
{
63-
Execute(Connection, command => command.ExecuteNonQuery(), _additionalSql);
62+
await ExecuteAsync(Connection, command => command.ExecuteNonQueryAsync(), _additionalSql);
6463
}
6564

6665
if (seed is not null)
@@ -71,16 +70,16 @@ protected override async Task InitializeAsync(
7170
}
7271

7372

74-
public void ExecuteScript(string scriptPath)
73+
public async Task ExecuteScript(string scriptPath)
7574
{
76-
var script = File.ReadAllText(scriptPath);
77-
Execute(
75+
var script = await File.ReadAllTextAsync(scriptPath);
76+
await ExecuteAsync(
7877
Connection, command =>
7978
{
8079
var commandsToExecute =
8180
new Regex("^GO",
8281
RegexOptions.IgnoreCase | RegexOptions.Multiline,
83-
TimeSpan.FromMilliseconds(4269.0)
82+
TimeSpan.FromMilliseconds(1000.0)
8483
)
8584
.Split(script)
8685
.Where(b => !string.IsNullOrEmpty(b));
@@ -90,60 +89,67 @@ public void ExecuteScript(string scriptPath)
9089
{
9190
try
9291
{
93-
var pureCommand = new Regex("\n", RegexOptions.IgnoreCase | RegexOptions.Multiline,
94-
TimeSpan.FromMilliseconds(1_000))
92+
var commandsSplitted = new Regex(
93+
"\n",
94+
RegexOptions.IgnoreCase | RegexOptions.Multiline,
95+
TimeSpan.FromMilliseconds(1_000)
96+
)
9597
.Split(commandToExecute)
96-
.Where(b => !b.StartsWith("--") && !b.IsNullOrEmpty())
98+
.Where(b => !b.StartsWith("--") && !string.IsNullOrEmpty(b))
9799
.ToList();
98100

99-
var commandJoined = string.Join("\n", pureCommand);
101+
var readyCommand = string.Join("\n", commandsSplitted);
100102

101103
command.CommandTimeout = 100_000;
102-
command.CommandText = commandJoined;
103-
command.ExecuteNonQuery();
104+
command.CommandText = readyCommand;
105+
command.ExecuteNonQueryAsync();
104106
}
105107
catch (Exception e)
106108
{
107-
throw new AggregateException(
108-
new Exception($"Command:\n{commandToExecute}\n"), e
109-
);
109+
throw new AggregateException($"Exception for command:\n{commandToExecute}\n", e);
110110
}
111111
}
112112

113-
return 0;
113+
return Task.FromResult(0);
114114
}, "");
115115
}
116116

117-
private static T Execute<T>(
117+
private static async Task ExecuteAsync<T>(
118118
DbConnection connection,
119-
Func<DbCommand, T> execute,
119+
Func<DbCommand, Task<T>> execute,
120120
string sql,
121+
bool useTransaction = false,
121122
object[]? parameters = null
122-
) => ExecuteCommand(connection, execute, sql, parameters);
123+
)
124+
{
125+
await ExecuteCommandAsync(connection, execute, sql, useTransaction, parameters);
126+
}
123127

124-
private static T ExecuteCommand<T>(
128+
private static async Task ExecuteCommandAsync<T>(
125129
DbConnection connection,
126-
Func<DbCommand, T> execute,
130+
Func<DbCommand, Task<T>> execute,
127131
string sql,
132+
bool useTransaction,
128133
object[]? parameters
129134
)
130135
{
131136
if (connection.State != ConnectionState.Closed)
132137
{
133-
connection.Close();
138+
await connection.CloseAsync();
134139
}
135140

136-
connection.Open();
141+
await connection.OpenAsync();
137142
try
138143
{
139-
using var command = CreateCommand(connection, sql, parameters);
140-
return execute(command);
144+
await using var command = CreateCommand(connection, sql, parameters);
145+
await execute(command);
141146
}
142147
finally
143148
{
144-
if (connection.State != ConnectionState.Closed)
149+
if (connection.State == ConnectionState.Closed
150+
&& connection.State != ConnectionState.Closed)
145151
{
146-
connection.Close();
152+
await connection.CloseAsync();
147153
}
148154
}
149155
}
@@ -171,20 +177,9 @@ private static YdbCommand CreateCommand(
171177
}
172178

173179

174-
private static YdbConnection CreateConnection(string name, bool sharedCache)
180+
private static YdbConnection CreateConnection()
175181
{
176-
var connectionString = new YdbConnectionStringBuilder(
177-
$"Host=localhost;" +
178-
$"Port=2135;" +
179-
$"Database = \"/local\";" +
180-
$"MaxSessionPool=10;" +
181-
$"RootCertificate=" + Path.Combine(
182-
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
183-
"dev/ydb_ca/ca.pem"
184-
)
185-
);
186-
187-
return new YdbConnection(connectionString);
182+
return new YdbConnection();
188183
}
189184

190185
public override Task CleanAsync(DbContext context)

0 commit comments

Comments
 (0)