Skip to content

Commit be7563b

Browse files
committed
Cleanup minio after scenario
Signed-off-by: Victor Chang <[email protected]>
1 parent 9da286b commit be7563b

File tree

4 files changed

+62
-13
lines changed

4 files changed

+62
-13
lines changed

tests/Integration.Test/Common/MinioDataSink.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ public MinioDataClient(Configurations configurations, InformaticsGatewayConfigur
3737

3838
public async Task SendAsync(DataProvider dataProvider, params object[] args)
3939
{
40-
var minioClient = new MinioClient()
41-
.WithEndpoint(_options.Storage.Settings["endpoint"])
42-
.WithCredentials(_options.Storage.Settings["accessKey"], _options.Storage.Settings["accessToken"])
43-
.Build();
40+
var minioClient = CreateMinioClient();
4441

4542
var stopwatch = new Stopwatch();
4643
stopwatch.Start();
@@ -64,5 +61,34 @@ public async Task SendAsync(DataProvider dataProvider, params object[] args)
6461
stopwatch.Stop();
6562
_outputHelper.WriteLine($"Time to upload to Minio={0}s...", stopwatch.Elapsed.TotalSeconds);
6663
}
64+
65+
private MinioClient CreateMinioClient() => new MinioClient()
66+
.WithEndpoint(_options.Storage.Settings["endpoint"])
67+
.WithCredentials(_options.Storage.Settings["accessKey"], _options.Storage.Settings["accessToken"])
68+
.Build();
69+
70+
internal void CleanBucketAsync()
71+
{
72+
var stopwatch = new Stopwatch();
73+
stopwatch.Start();
74+
var count = 0;
75+
var minioClient = CreateMinioClient();
76+
var listObjectArgs = new ListObjectsArgs()
77+
.WithBucket(_options.Storage.StorageServiceBucketName)
78+
.WithRecursive(true);
79+
80+
var objects = minioClient.ListObjectsAsync(listObjectArgs);
81+
objects.Subscribe(async (item) =>
82+
{
83+
var deletObjectsArgs = new RemoveObjectArgs()
84+
.WithBucket(_options.Storage.StorageServiceBucketName)
85+
.WithObject(item.Key);
86+
await minioClient.RemoveObjectAsync(deletObjectsArgs).ConfigureAwait(false);
87+
count++;
88+
});
89+
90+
stopwatch.Stop();
91+
_outputHelper.WriteLine($"Cleaned up {0} objects from Minio in {1}s...", count, stopwatch.Elapsed.TotalSeconds);
92+
}
6793
}
6894
}

tests/Integration.Test/Drivers/RabbitMqConsumer.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,25 @@
2222

2323
namespace Monai.Deploy.InformaticsGateway.Integration.Test.Drivers
2424
{
25-
internal class RabbitMqConsumer
25+
internal class RabbitMqConsumer : IDisposable
2626
{
27+
private readonly RabbitMQMessageSubscriberService _subscriberService;
2728
private readonly string _queueName;
2829
private readonly ISpecFlowOutputHelper _outputHelper;
2930
private readonly ConcurrentBag<Message> _messages;
31+
private bool _disposedValue;
3032

3133
public IReadOnlyList<Message> Messages
3234
{ get { return _messages.ToList(); } }
3335
public CountdownEvent MessageWaitHandle { get; private set; }
3436

3537
public RabbitMqConsumer(RabbitMQMessageSubscriberService subscriberService, string queueName, ISpecFlowOutputHelper outputHelper)
3638
{
37-
if (subscriberService is null)
38-
{
39-
throw new ArgumentNullException(nameof(subscriberService));
40-
}
41-
4239
if (string.IsNullOrWhiteSpace(queueName))
4340
{
4441
throw new ArgumentException($"'{nameof(queueName)}' cannot be null or whitespace.", nameof(queueName));
4542
}
46-
43+
_subscriberService = subscriberService ?? throw new ArgumentNullException(nameof(subscriberService));
4744
_queueName = queueName;
4845
_outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper));
4946
_messages = new ConcurrentBag<Message>();
@@ -67,5 +64,26 @@ public void SetupMessageHandle(int count)
6764
_messages.Clear();
6865
MessageWaitHandle = new CountdownEvent(count);
6966
}
67+
68+
protected virtual void Dispose(bool disposing)
69+
{
70+
if (!_disposedValue)
71+
{
72+
if (disposing)
73+
{
74+
_subscriberService.Dispose();
75+
}
76+
77+
_disposedValue = true;
78+
}
79+
}
80+
81+
82+
public void Dispose()
83+
{
84+
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
85+
Dispose(disposing: true);
86+
GC.SuppressFinalize(this);
87+
}
7088
}
7189
}

tests/Integration.Test/Hooks/TestHooks.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,17 @@ public static void Shtudown()
173173
{
174174
s_informaticsGatewayHost.StopAsync().Wait();
175175
s_dicomServer.Dispose();
176+
177+
s_rabbitMqConsumer_WorkflowRequest.Dispose();
178+
s_rabbitMqConsumer_ExportComplete.Dispose();
179+
s_rabbitMqConnectionFactory.Dispose();
176180
}
177181

178182
[AfterTestRun(Order = 0)]
179183
[AfterScenario]
180184
public static void ClearTestData()
181185
{
186+
s_minioSink.CleanBucketAsync();
182187
RabbitConnectionFactory.PurgeAllQueues(s_options.Value.Messaging);
183188
}
184189

tests/Integration.Test/study.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"MR": {
33
"SeriesMin": 1,
44
"SeriesMax": 2,
5-
"InstanceMin": 32,
6-
"InstanceMax": 64,
5+
"InstanceMin": 64,
6+
"InstanceMax": 128,
77
"SizeMin": 0.36,
88
"SizeMax": 2
99
},

0 commit comments

Comments
 (0)