Skip to content

Commit

Permalink
Cleanup minio after scenario
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Chang <vicchang@nvidia.com>
  • Loading branch information
mocsharp committed Nov 8, 2022
1 parent 9da286b commit be7563b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 13 deletions.
34 changes: 30 additions & 4 deletions tests/Integration.Test/Common/MinioDataSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public MinioDataClient(Configurations configurations, InformaticsGatewayConfigur

public async Task SendAsync(DataProvider dataProvider, params object[] args)
{
var minioClient = new MinioClient()
.WithEndpoint(_options.Storage.Settings["endpoint"])
.WithCredentials(_options.Storage.Settings["accessKey"], _options.Storage.Settings["accessToken"])
.Build();
var minioClient = CreateMinioClient();

var stopwatch = new Stopwatch();
stopwatch.Start();
Expand All @@ -64,5 +61,34 @@ public async Task SendAsync(DataProvider dataProvider, params object[] args)
stopwatch.Stop();
_outputHelper.WriteLine($"Time to upload to Minio={0}s...", stopwatch.Elapsed.TotalSeconds);
}

private MinioClient CreateMinioClient() => new MinioClient()
.WithEndpoint(_options.Storage.Settings["endpoint"])
.WithCredentials(_options.Storage.Settings["accessKey"], _options.Storage.Settings["accessToken"])
.Build();

internal void CleanBucketAsync()
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var count = 0;
var minioClient = CreateMinioClient();
var listObjectArgs = new ListObjectsArgs()
.WithBucket(_options.Storage.StorageServiceBucketName)
.WithRecursive(true);

var objects = minioClient.ListObjectsAsync(listObjectArgs);
objects.Subscribe(async (item) =>
{
var deletObjectsArgs = new RemoveObjectArgs()
.WithBucket(_options.Storage.StorageServiceBucketName)
.WithObject(item.Key);
await minioClient.RemoveObjectAsync(deletObjectsArgs).ConfigureAwait(false);
count++;
});

stopwatch.Stop();
_outputHelper.WriteLine($"Cleaned up {0} objects from Minio in {1}s...", count, stopwatch.Elapsed.TotalSeconds);
}
}
}
32 changes: 25 additions & 7 deletions tests/Integration.Test/Drivers/RabbitMqConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,25 @@

namespace Monai.Deploy.InformaticsGateway.Integration.Test.Drivers
{
internal class RabbitMqConsumer
internal class RabbitMqConsumer : IDisposable
{
private readonly RabbitMQMessageSubscriberService _subscriberService;
private readonly string _queueName;
private readonly ISpecFlowOutputHelper _outputHelper;
private readonly ConcurrentBag<Message> _messages;
private bool _disposedValue;

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

public RabbitMqConsumer(RabbitMQMessageSubscriberService subscriberService, string queueName, ISpecFlowOutputHelper outputHelper)
{
if (subscriberService is null)
{
throw new ArgumentNullException(nameof(subscriberService));
}

if (string.IsNullOrWhiteSpace(queueName))
{
throw new ArgumentException($"'{nameof(queueName)}' cannot be null or whitespace.", nameof(queueName));
}

_subscriberService = subscriberService ?? throw new ArgumentNullException(nameof(subscriberService));
_queueName = queueName;
_outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper));
_messages = new ConcurrentBag<Message>();
Expand All @@ -67,5 +64,26 @@ public void SetupMessageHandle(int count)
_messages.Clear();
MessageWaitHandle = new CountdownEvent(count);
}

protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
_subscriberService.Dispose();
}

_disposedValue = true;
}
}


public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
5 changes: 5 additions & 0 deletions tests/Integration.Test/Hooks/TestHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,17 @@ public static void Shtudown()
{
s_informaticsGatewayHost.StopAsync().Wait();
s_dicomServer.Dispose();

s_rabbitMqConsumer_WorkflowRequest.Dispose();
s_rabbitMqConsumer_ExportComplete.Dispose();
s_rabbitMqConnectionFactory.Dispose();
}

[AfterTestRun(Order = 0)]
[AfterScenario]
public static void ClearTestData()
{
s_minioSink.CleanBucketAsync();
RabbitConnectionFactory.PurgeAllQueues(s_options.Value.Messaging);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Integration.Test/study.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"MR": {
"SeriesMin": 1,
"SeriesMax": 2,
"InstanceMin": 32,
"InstanceMax": 64,
"InstanceMin": 64,
"InstanceMax": 128,
"SizeMin": 0.36,
"SizeMax": 2
},
Expand Down

0 comments on commit be7563b

Please sign in to comment.