1
1
#include < ydb/core/fq/libs/ydb/ydb.h>
2
+ #include < ydb/core/fq/libs/ydb/util.h>
2
3
3
4
#include < ydb/library/security/ydb_credentials_provider_factory.h>
4
5
@@ -19,31 +20,45 @@ namespace {
19
20
20
21
// //////////////////////////////////////////////////////////////////////////////
21
22
22
- TYdbConnectionPtr MakeConnection (const char * tablePrefix) {
23
- NConfig::TYdbStorageConfig config;
23
+ class TFixture : public NUnitTest ::TBaseFixture {
24
+ public:
25
+ TYdbConnectionPtr MakeConnection (const char * tablePrefix) {
26
+ NConfig::TYdbStorageConfig config;
24
27
25
- config.SetEndpoint (GetEnv (" YDB_ENDPOINT" ));
26
- config.SetDatabase (GetEnv (" YDB_DATABASE" ));
27
- config.SetToken (" " );
28
- config.SetTablePrefix (tablePrefix);
28
+ config.SetEndpoint (GetEnv (" YDB_ENDPOINT" ));
29
+ config.SetDatabase (GetEnv (" YDB_DATABASE" ));
30
+ config.SetToken (" " );
31
+ config.SetTablePrefix (tablePrefix);
29
32
30
- NYdb::TDriver driver ({});
31
- auto connection = NewYdbConnection (config, NKikimr::CreateYdbCredentialsProviderFactory, driver);
33
+ NYdb::TDriver driver ({});
34
+ Connection = NewYdbConnection (config, NKikimr::CreateYdbCredentialsProviderFactory, driver);
32
35
33
- auto status = connection ->SchemeClient .MakeDirectory (connection ->TablePathPrefix ).GetValueSync ();
34
- UNIT_ASSERT_C (status.IsSuccess (), status.GetIssues ().ToString ());
36
+ auto status = Connection ->SchemeClient .MakeDirectory (Connection ->TablePathPrefix ).GetValueSync ();
37
+ UNIT_ASSERT_C (status.IsSuccess (), status.GetIssues ().ToString ());
35
38
36
- auto desc = TTableBuilder ()
37
- .AddNullableColumn (" id" , EPrimitiveType::String)
38
- .AddNullableColumn (" generation" , EPrimitiveType::Uint64)
39
- .SetPrimaryKeyColumn (" id" )
40
- .Build ();
39
+ auto desc = TTableBuilder ()
40
+ .AddNullableColumn (" id" , EPrimitiveType::String)
41
+ .AddNullableColumn (" generation" , EPrimitiveType::Uint64)
42
+ .SetPrimaryKeyColumn (" id" )
43
+ .Build ();
41
44
42
- status = CreateTable (connection, " test" , std::move (desc)).GetValueSync ();
43
- UNIT_ASSERT_C (status.IsSuccess (), status.GetIssues ().ToString ());
45
+ status = CreateTable (Connection, " test" , std::move (desc)).GetValueSync ();
46
+ UNIT_ASSERT_C (status.IsSuccess (), status.GetIssues ().ToString ());
47
+ return Connection;
48
+ }
44
49
45
- return connection;
46
- }
50
+ void TearDown (NUnitTest::TTestContext& /* ctx*/ ) override {
51
+ if (Connection) {
52
+ auto tablePath = JoinPath (Connection->TablePathPrefix , " test" );
53
+ Connection->TableClient .RetryOperation (
54
+ [tablePath = std::move (tablePath)] (TSession session) mutable {
55
+ return session.DropTable (tablePath);
56
+ }).GetValueSync ();;
57
+ }
58
+ }
59
+
60
+ TYdbConnectionPtr Connection;
61
+ };
47
62
48
63
TFuture<TStatus> CheckTransactionClosed (const TFuture<TStatus>& future, const TGenerationContextPtr& context) {
49
64
return future.Apply (
@@ -90,7 +105,7 @@ TFuture<TStatus> UpsertDummyInTransaction(const TFuture<TStatus>& future, const
90
105
// //////////////////////////////////////////////////////////////////////////////
91
106
92
107
Y_UNIT_TEST_SUITE (TRegisterCheckTest) {
93
- Y_UNIT_TEST (ShouldRegisterCheckNewGeneration)
108
+ Y_UNIT_TEST_F (ShouldRegisterCheckNewGeneration, TFixture )
94
109
{
95
110
auto connection = MakeConnection (" ShouldRegisterCheckNewGeneration" );
96
111
@@ -114,7 +129,7 @@ Y_UNIT_TEST_SUITE(TRegisterCheckTest) {
114
129
UNIT_ASSERT_C (status.IsSuccess (), status.GetIssues ().ToString ());
115
130
}
116
131
117
- Y_UNIT_TEST (ShouldRegisterCheckSameGeneration)
132
+ Y_UNIT_TEST_F (ShouldRegisterCheckSameGeneration, TFixture )
118
133
{
119
134
auto connection = MakeConnection (" ShouldRegisterCheckSameGeneration" );
120
135
@@ -156,7 +171,7 @@ Y_UNIT_TEST_SUITE(TRegisterCheckTest) {
156
171
UNIT_ASSERT_C (status.IsSuccess (), status.GetIssues ().ToString ());
157
172
}
158
173
159
- Y_UNIT_TEST (ShouldRegisterCheckNextGeneration)
174
+ Y_UNIT_TEST_F (ShouldRegisterCheckNextGeneration, TFixture )
160
175
{
161
176
auto connection = MakeConnection (" ShouldRegisterCheckNextGeneration" );
162
177
@@ -197,7 +212,7 @@ Y_UNIT_TEST_SUITE(TRegisterCheckTest) {
197
212
UNIT_ASSERT_C (status.IsSuccess (), status.GetIssues ().ToString ());
198
213
}
199
214
200
- Y_UNIT_TEST (ShouldNotRegisterCheckPrevGeneration)
215
+ Y_UNIT_TEST_F (ShouldNotRegisterCheckPrevGeneration, TFixture )
201
216
{
202
217
auto connection = MakeConnection (" ShouldNotRegisterCheckPrevGeneration" );
203
218
@@ -239,7 +254,7 @@ Y_UNIT_TEST_SUITE(TRegisterCheckTest) {
239
254
UNIT_ASSERT (!status.IsSuccess ());
240
255
}
241
256
242
- Y_UNIT_TEST (ShouldNotRegisterCheckPrevGeneration2)
257
+ Y_UNIT_TEST_F (ShouldNotRegisterCheckPrevGeneration2, TFixture )
243
258
{
244
259
auto connection = MakeConnection (" ShouldNotRegisterCheckPrevGeneration2" );
245
260
@@ -281,7 +296,7 @@ Y_UNIT_TEST_SUITE(TRegisterCheckTest) {
281
296
UNIT_ASSERT (!status.IsSuccess ());
282
297
}
283
298
284
- Y_UNIT_TEST (ShouldRegisterCheckNewGenerationAndTransact)
299
+ Y_UNIT_TEST_F (ShouldRegisterCheckNewGenerationAndTransact, TFixture )
285
300
{
286
301
auto connection = MakeConnection (" ShouldRegisterCheckNewGenerationAndTransact" );
287
302
@@ -313,7 +328,7 @@ Y_UNIT_TEST_SUITE(TRegisterCheckTest) {
313
328
UNIT_ASSERT_C (status.IsSuccess (), status.GetIssues ().ToString ());
314
329
}
315
330
316
- Y_UNIT_TEST (ShouldRegisterCheckSameGenerationAndTransact)
331
+ Y_UNIT_TEST_F (ShouldRegisterCheckSameGenerationAndTransact, TFixture )
317
332
{
318
333
auto connection = MakeConnection (" ShouldRegisterCheckNewGenerationAndTransact" );
319
334
@@ -368,7 +383,7 @@ Y_UNIT_TEST_SUITE(TRegisterCheckTest) {
368
383
369
384
// most of logic is tested inside libs/storage, thus we don't test here again
370
385
Y_UNIT_TEST_SUITE (TCheckGenerationTest) {
371
- Y_UNIT_TEST (ShouldRollbackTransactionWhenCheckFails)
386
+ Y_UNIT_TEST_F (ShouldRollbackTransactionWhenCheckFails, TFixture )
372
387
{
373
388
auto connection = MakeConnection (" ShouldRollbackTransactionWhenCheckFails" );
374
389
@@ -410,9 +425,9 @@ Y_UNIT_TEST_SUITE(TCheckGenerationTest) {
410
425
UNIT_ASSERT (!status.IsSuccess ());
411
426
}
412
427
413
- Y_UNIT_TEST (ShouldRollbackTransactionWhenCheckFails2)
428
+ Y_UNIT_TEST_F (ShouldRollbackTransactionWhenCheckFails2, TFixture )
414
429
{
415
- auto connection = MakeConnection (" ShouldRollbackTransactionWhenCheckFails " );
430
+ auto connection = MakeConnection (" ShouldRollbackTransactionWhenCheckFails2 " );
416
431
417
432
auto future = connection->TableClient .RetryOperation (
418
433
[prefix = connection->TablePathPrefix ] (TSession session) {
0 commit comments