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 706e6fc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
33 changes: 29 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,33 @@ 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 async Task CleanBucketAsync()
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var minioClient = CreateMinioClient();
var toBeRemoved = new List<string>();
var listObjectArgs = new ListObjectsArgs()
.WithBucket(_options.Storage.StorageServiceBucketName)
.WithRecursive(true);
var objects = minioClient.ListObjectsAsync(listObjectArgs);
objects.Subscribe((item) =>
{
toBeRemoved.Add(item.Key);
});
var deletObjectsArgs = new RemoveObjectsArgs()
.WithBucket(_options.Storage.StorageServiceBucketName)
.WithObjects(toBeRemoved);
await minioClient.RemoveObjectsAsync(deletObjectsArgs).ConfigureAwait(false);

stopwatch.Stop();
_outputHelper.WriteLine($"Cleaned up {0} objects from Minio in {1}s...", toBeRemoved.Count, stopwatch.Elapsed.TotalSeconds);
}
}
}
1 change: 1 addition & 0 deletions tests/Integration.Test/Hooks/TestHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public static void Shtudown()
[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 706e6fc

Please sign in to comment.