44#include < cloud/blockstore/libs/storage/partition_common/events_private.h>
55#include < cloud/blockstore/libs/storage/partition_nonrepl/model/processing_blocks.h>
66#include < cloud/blockstore/libs/storage/stats_service/stats_service_events_private.h>
7+
78#include < util/system/hostname.h>
89
910namespace NCloud ::NBlockStore::NStorage {
1011
12+ using namespace std ::chrono_literals;
13+
1114using namespace NActors ;
1215
1316using namespace NKikimr ;
@@ -24,53 +27,52 @@ namespace {
2427
2528// //////////////////////////////////////////////////////////////////////////////
2629
27- struct TTestContext
30+ struct TFixture : public NUnitTest ::TBaseFixture
2831{
29- TVolumeClient Volume;
3032 std::unique_ptr<TTestActorRuntime> Runtime;
31- TIntrusivePtr<TDiskRegistryState> DRState;
32- };
33+ TIntrusivePtr<TDiskRegistryState> State;
3334
34- TTestContext SetupTest (TDuration agentRequestTimeout = TDuration::Seconds(1 ))
35- {
36- NProto::TStorageServiceConfig config;
37- config.SetAcquireNonReplicatedDevices (true );
38- config.SetNonReplicatedVolumeDirectAcquireEnabled (true );
39- config.SetAgentRequestTimeout (agentRequestTimeout.MilliSeconds ());
40- config.SetClientRemountPeriod (2000 );
41- auto state = MakeIntrusive<TDiskRegistryState>();
42- auto runtime = PrepareTestActorRuntime (config, state);
43- TVolumeClient volume (*runtime);
44-
45- volume.UpdateVolumeConfig (
46- 0 ,
47- 0 ,
48- 0 ,
49- 0 ,
50- false ,
51- 1 ,
52- NCloud::NProto::STORAGE_MEDIA_SSD_NONREPLICATED,
53- 1024 );
54-
55- return {
56- .Volume = std::move (volume),
57- .Runtime = std::move (runtime),
58- .DRState = std::move (state)};
59- }
35+ void SetupTest (TDuration agentRequestTimeout = 1s)
36+ {
37+ NProto::TStorageServiceConfig config;
38+ config.SetAcquireNonReplicatedDevices (true );
39+ config.SetNonReplicatedVolumeDirectAcquireEnabled (true );
40+ config.SetAgentRequestTimeout (agentRequestTimeout.MilliSeconds ());
41+ config.SetClientRemountPeriod (2000 );
42+ State = MakeIntrusive<TDiskRegistryState>();
43+ Runtime = PrepareTestActorRuntime (config, State);
44+ auto volume = GetVolumeClient ();
45+
46+ volume.UpdateVolumeConfig (
47+ 0 ,
48+ 0 ,
49+ 0 ,
50+ 0 ,
51+ false ,
52+ 1 ,
53+ NCloud::NProto::STORAGE_MEDIA_SSD_NONREPLICATED,
54+ 1024 );
55+
56+ volume.WaitReady ();
57+ }
58+
59+ TVolumeClient GetVolumeClient () const
60+ {
61+ return {*Runtime};
62+ }
63+ };
6064
61- } // namespace
65+ } // namespace
6266
6367// //////////////////////////////////////////////////////////////////////////////
6468
65- Y_UNIT_TEST_SUITE (TVolumeTest )
69+ Y_UNIT_TEST_SUITE (TVolumeSessionTest )
6670{
67- Y_UNIT_TEST (ShouldPassAllParamsInAcquireDevicesRequest)
71+ Y_UNIT_TEST_F (ShouldPassAllParamsInAcquireDevicesRequest, TFixture )
6872 {
69- auto [volume, runtime, _] = SetupTest ();
70-
71- TVolumeClient writerClient (*runtime);
73+ SetupTest ();
7274
73- volume. WaitReady ();
75+ auto volume = GetVolumeClient ();
7476
7577 auto response = volume.GetVolumeInfo ();
7678 auto diskInfo = response->Record .GetVolume ();
@@ -86,7 +88,7 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
8688
8789 bool requestSended = false ;
8890
89- runtime ->SetObserverFunc (
91+ Runtime ->SetObserverFunc (
9092 [&](TAutoPtr<IEventHandle>& event)
9193 {
9294 if (event->GetTypeRewrite () ==
@@ -103,9 +105,7 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
103105 record.GetAccessMode (),
104106 NProto::VOLUME_ACCESS_READ_WRITE);
105107
106- UNIT_ASSERT_EQUAL (
107- record.GetDiskId (),
108- diskInfo.GetDiskId ());
108+ UNIT_ASSERT_EQUAL (record.GetDiskId (), diskInfo.GetDiskId ());
109109
110110 const auto & deviceUUIDS = record.GetDeviceUUIDs ();
111111 UNIT_ASSERT_EQUAL (
@@ -131,24 +131,22 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
131131 NProto::VOLUME_ACCESS_READ_WRITE,
132132 NProto::VOLUME_MOUNT_LOCAL,
133133 0 );
134- writerClient .AddClient (writer);
134+ volume .AddClient (writer);
135135
136136 UNIT_ASSERT (requestSended);
137137 }
138138
139- Y_UNIT_TEST (ShouldPassAllParamsInReleaseDevicesRequest)
139+ Y_UNIT_TEST_F (ShouldPassAllParamsInReleaseDevicesRequest, TFixture )
140140 {
141- auto [volume, runtime, _] = SetupTest ();
141+ SetupTest ();
142142
143- TVolumeClient writerClient (*runtime);
144-
145- volume.WaitReady ();
143+ auto volume = GetVolumeClient ();
146144
147145 auto writer = CreateVolumeClientInfo (
148146 NProto::VOLUME_ACCESS_READ_WRITE,
149147 NProto::VOLUME_MOUNT_LOCAL,
150148 0 );
151- writerClient .AddClient (writer);
149+ volume .AddClient (writer);
152150
153151 auto response = volume.GetVolumeInfo ();
154152 auto diskInfo = response->Record .GetVolume ();
@@ -164,7 +162,7 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
164162
165163 bool requestSended = false ;
166164
167- runtime ->SetObserverFunc (
165+ Runtime ->SetObserverFunc (
168166 [&](TAutoPtr<IEventHandle>& event)
169167 {
170168 if (event->GetTypeRewrite () ==
@@ -200,23 +198,21 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
200198 UNIT_ASSERT (requestSended);
201199 }
202200
203- Y_UNIT_TEST (ShouldSendAcquireReleaseRequestsDirectlyToDiskAgent)
201+ Y_UNIT_TEST_F (ShouldSendAcquireReleaseRequestsDirectlyToDiskAgent, TFixture )
204202 {
205- auto [volume, runtime, _] = SetupTest ();
206-
207- TVolumeClient writerClient (*runtime);
208- TVolumeClient readerClient1 (*runtime);
209- TVolumeClient readerClient2 (*runtime);
203+ SetupTest ();
210204
211- volume.WaitReady ();
205+ TVolumeClient writerClient = GetVolumeClient ();
206+ auto readerClient1 = GetVolumeClient ();
207+ auto readerClient2 = GetVolumeClient ();
212208
213209 ui32 acquireRequestsToDiskRegistry = 0 ;
214210 ui32 releaseRequestsToDiskRegistry = 0 ;
215211 ui32 readerAcquireRequests = 0 ;
216212 ui32 writerAcquireRequests = 0 ;
217213 ui32 releaseRequests = 0 ;
218214
219- runtime ->SetObserverFunc (
215+ Runtime ->SetObserverFunc (
220216 [&](TAutoPtr<IEventHandle>& event)
221217 {
222218 switch (event->GetTypeRewrite ()) {
@@ -249,8 +245,8 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
249245 return TTestActorRuntime::DefaultObserverFunc (event);
250246 });
251247
252- runtime ->AdvanceCurrentTime (TDuration::Seconds ( 2 ) );
253- runtime ->DispatchEvents ({}, TDuration::MilliSeconds ( 1 ) );
248+ Runtime ->AdvanceCurrentTime (2s );
249+ Runtime ->DispatchEvents ({}, 1ms );
254250
255251 UNIT_ASSERT_VALUES_EQUAL (acquireRequestsToDiskRegistry, 0 );
256252 UNIT_ASSERT_VALUES_EQUAL (writerAcquireRequests, 0 );
@@ -282,8 +278,8 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
282278 UNIT_ASSERT_VALUES_EQUAL (writerAcquireRequests, 1 );
283279 UNIT_ASSERT_VALUES_EQUAL (readerAcquireRequests, 2 );
284280
285- runtime ->AdvanceCurrentTime (TDuration::Seconds ( 2 ) );
286- runtime ->DispatchEvents ({}, TDuration::MilliSeconds ( 1 ) );
281+ Runtime ->AdvanceCurrentTime (2s );
282+ Runtime ->DispatchEvents ({}, 1ms );
287283
288284 UNIT_ASSERT_VALUES_EQUAL (acquireRequestsToDiskRegistry, 0 );
289285 UNIT_ASSERT_VALUES_EQUAL (writerAcquireRequests, 2 );
@@ -294,8 +290,8 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
294290
295291 readerClient1.RemoveClient (reader1.GetClientId ());
296292
297- runtime ->AdvanceCurrentTime (TDuration::Seconds ( 2 ) );
298- runtime ->DispatchEvents ({}, TDuration::MilliSeconds ( 1 ) );
293+ Runtime ->AdvanceCurrentTime (2s );
294+ Runtime ->DispatchEvents ({}, 1ms );
299295
300296 UNIT_ASSERT_VALUES_EQUAL (acquireRequestsToDiskRegistry, 0 );
301297 UNIT_ASSERT_VALUES_EQUAL (writerAcquireRequests, 3 );
@@ -307,8 +303,8 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
307303 writerClient.RemoveClient (writer.GetClientId ());
308304 readerClient2.RemoveClient (reader2.GetClientId ());
309305
310- runtime ->AdvanceCurrentTime (TDuration::Seconds ( 2 ) );
311- runtime ->DispatchEvents ({}, TDuration::MilliSeconds ( 1 ) );
306+ Runtime ->AdvanceCurrentTime (2s );
307+ Runtime ->DispatchEvents ({}, 1ms );
312308
313309 UNIT_ASSERT_VALUES_EQUAL (acquireRequestsToDiskRegistry, 0 );
314310 UNIT_ASSERT_VALUES_EQUAL (writerAcquireRequests, 3 );
@@ -318,15 +314,14 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
318314 UNIT_ASSERT_VALUES_EQUAL (releaseRequestsToDiskRegistry, 0 );
319315 }
320316
321- Y_UNIT_TEST (ShouldRejectTimedoutAcquireRequests)
317+ Y_UNIT_TEST_F (ShouldRejectTimedoutAcquireRequests, TFixture )
322318 {
323- auto [volume, runtime, _] = SetupTest (TDuration::MilliSeconds ( 100 ) );
319+ SetupTest (100ms );
324320
325- TVolumeClient writerClient (*runtime );
321+ auto writerClient = GetVolumeClient ( );
326322
327- volume.WaitReady ();
328323 std::unique_ptr<IEventHandle> stollenResponse;
329- runtime ->SetObserverFunc (
324+ Runtime ->SetObserverFunc (
330325 [&](TAutoPtr<IEventHandle>& event)
331326 {
332327 if (event->GetTypeRewrite () ==
@@ -349,15 +344,13 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
349344 UNIT_ASSERT_VALUES_EQUAL (response->GetError ().GetMessage (), " timeout" );
350345 }
351346
352- Y_UNIT_TEST (ShouldPassErrorsFromDiskAgent)
347+ Y_UNIT_TEST_F (ShouldPassErrorsFromDiskAgent, TFixture )
353348 {
354- auto [volume, runtime, _] = SetupTest ();
349+ SetupTest ();
355350
356- TVolumeClient writerClient (*runtime );
351+ auto writerClient = GetVolumeClient ( );
357352
358- volume.WaitReady ();
359-
360- runtime->SetObserverFunc (
353+ Runtime->SetObserverFunc (
361354 [&](TAutoPtr<IEventHandle>& event)
362355 {
363356 if (event->GetTypeRewrite () ==
@@ -367,7 +360,7 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
367360 TEvDiskAgent::TEvAcquireDevicesResponse>(
368361 MakeError (E_TRY_AGAIN));
369362
370- runtime ->Send (new IEventHandle (
363+ Runtime ->Send (new IEventHandle (
371364 event->Recipient ,
372365 event->Sender ,
373366 response.release (),
@@ -391,16 +384,13 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
391384 UNIT_ASSERT_EQUAL (response->GetError ().GetCode (), E_TRY_AGAIN);
392385 }
393386
394- Y_UNIT_TEST (ShouldMuteErrorsWithMuteIoErrors)
387+ Y_UNIT_TEST_F (ShouldMuteErrorsWithMuteIoErrors, TFixture )
395388 {
396- auto [volume, runtime, state] = SetupTest ();
389+ SetupTest ();
397390
398- TVolumeClient writerClient (*runtime);
399-
400- volume.WaitReady ();
391+ auto writerClient = GetVolumeClient ();
401392
402-
403- runtime->SetObserverFunc (
393+ Runtime->SetObserverFunc (
404394 [&](TAutoPtr<IEventHandle>& event)
405395 {
406396 if (event->GetTypeRewrite () ==
@@ -410,7 +400,7 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
410400 TEvDiskAgent::TEvAcquireDevicesResponse>(
411401 MakeError (E_TRY_AGAIN));
412402
413- runtime ->Send (new IEventHandle (
403+ Runtime ->Send (new IEventHandle (
414404 event->Recipient ,
415405 event->Sender ,
416406 response.release (),
@@ -428,35 +418,34 @@ Y_UNIT_TEST_SUITE(TVolumeTest)
428418 NProto::VOLUME_MOUNT_LOCAL,
429419 0 );
430420
431- auto & disk = state ->Disks .at (" vol0" );
421+ auto & disk = State ->Disks .at (" vol0" );
432422 disk.IOMode = NProto::VOLUME_IO_ERROR_READ_ONLY;
433- disk.IOModeTs = runtime ->GetCurrentTime ();
423+ disk.IOModeTs = Runtime ->GetCurrentTime ();
434424 disk.MuteIOErrors = true ;
435425
426+ auto volume = GetVolumeClient ();
436427 volume.ReallocateDisk ();
437428 // reallocate disk will trigger pipes reset, so reestablish connection
438429 volume.ReconnectPipe ();
439430
440431 writerClient.AddClient (writer);
441432 }
442433
443- Y_UNIT_TEST (ShouldHandleRequestsUndelivery)
434+ Y_UNIT_TEST_F (ShouldHandleRequestsUndelivery, TFixture )
444435 {
445- auto [volume, runtime, state] = SetupTest ();
446-
447- TVolumeClient writerClient (*runtime);
436+ SetupTest ();
448437
449- volume. WaitReady ();
438+ auto writerClient = GetVolumeClient ();
450439
451440 auto writer = CreateVolumeClientInfo (
452441 NProto::VOLUME_ACCESS_READ_WRITE,
453442 NProto::VOLUME_MOUNT_LOCAL,
454443 0 );
455444
456445 auto agentNodeId = MakeDiskAgentServiceId (
457- state ->Disks .at (" vol0" ).Devices [0 ].GetNodeId ());
446+ State ->Disks .at (" vol0" ).Devices [0 ].GetNodeId ());
458447
459- runtime ->Send (new IEventHandle (
448+ Runtime ->Send (new IEventHandle (
460449 agentNodeId,
461450 TActorId (),
462451 new TEvents::TEvPoisonPill));
0 commit comments