Skip to content

Commit

Permalink
Lifecycle expiration date, WithEndpoint, WithSSL issues cause functio…
Browse files Browse the repository at this point in the history
…nal tests to fail (#844)
  • Loading branch information
ebozduman authored Oct 21, 2023
1 parent 0c57096 commit 3a38f1e
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 74 deletions.
83 changes: 45 additions & 38 deletions Minio.Functional.Tests/FunctionalTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,9 @@ internal static async Task TearDown(IMinioClient minio, string bucketName)
new GetObjectLockConfigurationArgs()
.WithBucket(bucketName);
ObjectLockConfiguration lockConfig = null;
VersioningConfiguration versioningConfig = null;
try
{
versioningConfig = await minio.GetVersioningAsync(new GetVersioningArgs()
var versioningConfig = await minio.GetVersioningAsync(new GetVersioningArgs()
.WithBucket(bucketName)).ConfigureAwait(false);
if (versioningConfig is not null &&
(versioningConfig.Status.Contains("Enabled", StringComparison.Ordinal) ||
Expand Down Expand Up @@ -633,7 +632,7 @@ internal static async Task TearDown(IMinioClient minio, string bucketName)
exceptionList.Add,
() => { });

await Task.Delay(4500).ConfigureAwait(false);
await Task.Delay(20000).ConfigureAwait(false);
if (lockConfig?.ObjectLockEnabled.Equals(ObjectLockConfiguration.LockEnabled,
StringComparison.OrdinalIgnoreCase) == true)
{
Expand Down Expand Up @@ -806,8 +805,8 @@ internal static async Task PutGetStatEncryptedObject_Test2(IMinioClient minio)
aesEncryption.KeySize = 256;
aesEncryption.GenerateKey();
var ssec = new SSEC(aesEncryption.Key);

using (var filestream = rsg.GenerateStreamFromSeed(6 * MB))
Stream filestream;
await using ((filestream = rsg.GenerateStreamFromSeed(6 * MB)).ConfigureAwait(false))
{
var file_write_size = filestream.Length;

Expand All @@ -827,16 +826,18 @@ internal static async Task PutGetStatEncryptedObject_Test2(IMinioClient minio)
.WithServerSideEncryption(ssec)
.WithCallbackStream(async (stream, cancellationToken) =>
{
using var fileStream = File.Create(tempFileName);

await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
await fileStream.DisposeAsync().ConfigureAwait(false);
Stream fileStream;
await using ((fileStream = File.Create(tempFileName)).ConfigureAwait(false))
{
await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
await fileStream.DisposeAsync().ConfigureAwait(false);

var writtenInfo = new FileInfo(tempFileName);
file_read_size = writtenInfo.Length;
var writtenInfo = new FileInfo(tempFileName);
file_read_size = writtenInfo.Length;

Assert.AreEqual(file_write_size, file_read_size);
File.Delete(tempFileName);
Assert.AreEqual(file_write_size, file_read_size);
File.Delete(tempFileName);
}
});
var statObjectArgs = new StatObjectArgs()
.WithBucket(bucketName)
Expand All @@ -849,24 +850,26 @@ internal static async Task PutGetStatEncryptedObject_Test2(IMinioClient minio)
new MintLogger("PutGetStatEncryptedObject_Test2", putObjectSignature,
"Tests whether Put/Get/Stat multipart upload with encryption passes", TestStatus.PASS,
DateTime.Now - startTime, args: args).Log();
File.Delete(tempFileName);
await TearDown(minio, bucketName).ConfigureAwait(false);
}
catch (NotImplementedException ex)
{
new MintLogger("PutGetStatEncryptedObject_Test2", putObjectSignature,
"Tests whether Put/Get/Stat multipart upload with encryption passes", TestStatus.NA,
DateTime.Now - startTime, "", ex.Message, ex.ToString(), args).Log();
File.Delete(tempFileName);
await TearDown(minio, bucketName).ConfigureAwait(false);
throw;
}
catch (Exception ex)
{
new MintLogger("PutGetStatEncryptedObject_Test2", putObjectSignature,
"Tests whether Put/Get/Stat multipart upload with encryption passes", TestStatus.FAIL,
DateTime.Now - startTime, "", ex.Message, ex.ToString(), args).Log();
throw;
}
finally
{
File.Delete(tempFileName);
await TearDown(minio, bucketName).ConfigureAwait(false);
throw;
}
}

Expand Down Expand Up @@ -2702,7 +2705,7 @@ internal static async Task ListenBucketNotificationsAsync_Test1(IMinioClient min
Exception ex = new UnexpectedMinioException(err.Message);
if (string.Equals(err.Code, "NotImplemented", StringComparison.OrdinalIgnoreCase))
ex = new NotImplementedException(err.Message);

await TearDown(minio, bucketName).ConfigureAwait(false);
throw ex;
}

Expand Down Expand Up @@ -2731,6 +2734,7 @@ internal static async Task ListenBucketNotificationsAsync_Test1(IMinioClient min
listenBucketNotificationsSignature,
"Tests whether ListenBucketNotifications passes for small object",
TestStatus.PASS, DateTime.Now - startTime, args: args).Log();
await TearDown(minio, bucketName).ConfigureAwait(false);
}
catch (NotImplementedException ex)
{
Expand All @@ -2739,6 +2743,7 @@ internal static async Task ListenBucketNotificationsAsync_Test1(IMinioClient min
"Tests whether ListenBucketNotifications passes for small object",
TestStatus.NA, DateTime.Now - startTime, ex.Message,
ex.ToString(), args: args).Log();
await TearDown(minio, bucketName).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -2770,13 +2775,10 @@ static bool isAWS(string endPoint)
"Tests whether ListenBucketNotifications passes for small object",
TestStatus.FAIL, DateTime.Now - startTime, ex.Message,
ex.ToString(), args: args).Log();
await TearDown(minio, bucketName).ConfigureAwait(false);
throw;
}
}
finally
{
await TearDown(minio, bucketName).ConfigureAwait(false);
}
}

internal static async Task ListenBucketNotificationsAsync_Test2(IMinioClient minio)
Expand Down Expand Up @@ -4873,18 +4875,20 @@ internal static async Task GetObject_3_OffsetLength_Tests(IMinioClient minio)

new MintLogger(testName, getObjectSignature, "Tests whether GetObject returns all the data",
TestStatus.PASS, DateTime.Now - startTime, args: args).Log();

if (File.Exists(tempFileName)) File.Delete(tempFileName);
if (File.Exists(tempSource)) File.Delete(tempSource);
await TearDown(minio, bucketName).ConfigureAwait(false);
}
catch (Exception ex)
{
new MintLogger(testName, getObjectSignature, "Tests whether GetObject returns all the data",
TestStatus.FAIL, DateTime.Now - startTime, ex.Message, ex.ToString(), args: args).Log();
throw;
}
finally
{

if (File.Exists(tempFileName)) File.Delete(tempFileName);
if (File.Exists(tempSource)) File.Delete(tempSource);
await TearDown(minio, bucketName).ConfigureAwait(false);
throw;
}
}
}
Expand Down Expand Up @@ -5389,7 +5393,7 @@ internal static async Task ListObjects_Test(IMinioClient minio, string bucketNam
() => { });
}

await Task.Delay(5000).ConfigureAwait(false);
await Task.Delay(40000).ConfigureAwait(false);
Assert.AreEqual(numObjects, count);
}

Expand Down Expand Up @@ -6046,21 +6050,23 @@ internal static async Task BucketLifecycleAsync_Test1(IMinioClient minio)
catch (Exception ex)
{
await TearDown(minio, bucketName).ConfigureAwait(false);
new MintLogger(nameof(BucketLifecycleAsync_Test1), setBucketLifecycleSignature,
new MintLogger(nameof(BucketLifecycleAsync_Test1) + ".0", setBucketLifecycleSignature,
"Tests whether SetBucketLifecycleAsync passes", TestStatus.FAIL, DateTime.Now - startTime, ex.Message,
ex.ToString(), args: args).Log();
throw;
}

var rules = new List<LifecycleRule>();
var exp = new Expiration(DateTime.Now.AddYears(1));
var compareDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
var expInDays = (compareDate.AddYears(1) - compareDate).TotalDays;
var baseDate = DateTime.Now;
var expDate = baseDate.AddYears(1);
var exp = new Expiration(expDate);

var rule1 = new LifecycleRule(null, "txt", exp, null,
new RuleFilter(null, "txt/", null),
null, null, LifecycleRule.LifecycleRuleStatusEnabled
);
var calcDateTime = DateTime.Parse(exp.ExpiryDate, null, DateTimeStyles.RoundtripKind);
var expInDays = (calcDateTime.Date - baseDate.ToUniversalTime().Date).TotalDays;

var rule1 = new LifecycleRule(null, "txt", exp,
null, new RuleFilter(null, "txt/", null), null,
null, LifecycleRule.LifecycleRuleStatusEnabled);
rules.Add(rule1);
var lfc = new LifecycleConfiguration(rules);
try
Expand All @@ -6082,7 +6088,6 @@ internal static async Task BucketLifecycleAsync_Test1(IMinioClient minio)
}
catch (Exception ex)
{
await TearDown(minio, bucketName).ConfigureAwait(false);
new MintLogger(nameof(BucketLifecycleAsync_Test1) + ".1", setBucketLifecycleSignature,
"Tests whether SetBucketLifecycleAsync passes", TestStatus.FAIL, DateTime.Now - startTime, ex.Message,
ex.ToString(), args: args).Log();
Expand All @@ -6098,8 +6103,10 @@ internal static async Task BucketLifecycleAsync_Test1(IMinioClient minio)
Assert.IsNotNull(lfcObj.Rules);
Assert.IsTrue(lfcObj.Rules.Count > 0);
Assert.AreEqual(lfcObj.Rules.Count, lfc.Rules.Count);
var lfcDate = DateTime.Parse(lfcObj.Rules[0].Expiration.Date, null, DateTimeStyles.RoundtripKind);
Assert.AreEqual(Math.Floor((lfcDate - compareDate).TotalDays), expInDays);
var lfcDate = DateTime.Parse(lfcObj.Rules[0].Expiration.ExpiryDate, null, DateTimeStyles.RoundtripKind);
var lfcExpInDays = (lfcDate.Date - baseDate.ToUniversalTime().Date).TotalDays;
Assert.AreEqual(lfcExpInDays, expInDays);

new MintLogger(nameof(BucketLifecycleAsync_Test1) + ".2", getBucketLifecycleSignature,
"Tests whether GetBucketLifecycleAsync passes", TestStatus.PASS, DateTime.Now - startTime,
args: args)
Expand Down
11 changes: 7 additions & 4 deletions Minio/ApiEndpoints/BucketOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ public async Task<bool> BucketExistsAsync(BucketExistsArgs args, CancellationTok
var requestMessageBuilder = await this.CreateRequest(args).ConfigureAwait(false);
using var response =
await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
cancellationToken: cancellationToken).ConfigureAwait(false);
if (response.Exception is not null &&
response.Exception.GetType() == typeof(BucketNotFoundException))
return false;
}
catch (InternalClientException ice)
{
if ((ice.ServerResponse is not null && HttpStatusCode.NotFound.Equals(ice.ServerResponse.StatusCode))
|| ice.ServerResponse is null)
if ((ice.ServerResponse is not null &&
HttpStatusCode.NotFound.Equals(ice.ServerResponse.StatusCode)) ||
ice.ServerResponse is null)
return false;
}
catch (Exception ex)
Expand Down
9 changes: 4 additions & 5 deletions Minio/DataModel/ILM/Duration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

using System.Xml.Serialization;
using Minio.Helper;

namespace Minio.DataModel.ILM;

Expand All @@ -24,14 +23,14 @@ public abstract class Duration
{
protected Duration()
{
Date = null;
ExpiryDate = null;
Days = null;
}

protected Duration(DateTime date)
{
date = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0);
Date = Utils.To8601String(date);
ExpiryDate = date.ToUniversalTime().Date.ToString("o")
?? date.AddDays(1).AddSeconds(-1).ToUniversalTime().Date.ToString("o");
}

protected Duration(double days)
Expand All @@ -40,7 +39,7 @@ protected Duration(double days)
}

[XmlElement(ElementName = "Date", IsNullable = true)]
public string Date { get; set; }
public string ExpiryDate { get; set; }

[XmlElement(ElementName = "Days", IsNullable = true)]
public double? Days { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions Minio/DataModel/ILM/LifecycleConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public LifecycleConfiguration()

public LifecycleConfiguration(IList<LifecycleRule> rules)
{
if (rules is null || rules.Count <= 0)
if (rules is null || rules.Count == 0)
throw new ArgumentNullException(nameof(rules),
"Rules object cannot be empty. A finite set of Lifecycle Rules are needed for LifecycleConfiguration.");

Expand Down Expand Up @@ -73,7 +73,7 @@ public string MarshalXML()
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
// throw ex;
throw;
}
finally
{
Expand Down
2 changes: 1 addition & 1 deletion Minio/DataModel/Result/ResponseResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ResponseResult(HttpRequestMessage request, Exception exception)
Exception = exception;
}

private Exception Exception { get; }
public Exception Exception { get; set; }
public HttpRequestMessage Request { get; }
public HttpResponseMessage Response { get; }

Expand Down
3 changes: 1 addition & 2 deletions Minio/Helper/OperationsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ private async Task GetObjectStreamAsync(GetObjectArgs args, CancellationToken ca
var requestMessageBuilder = await this.CreateRequest(args).ConfigureAwait(false);
using var response =
await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
cancellationToken: cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down
23 changes: 10 additions & 13 deletions Minio/MinioClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static IMinioClient WithEndpoint(this IMinioClient minioClient, string en
{
if (minioClient is null) throw new ArgumentNullException(nameof(minioClient));

minioClient.Config.BaseUrl = endpoint;
minioClient.Config.Endpoint = endpoint;
minioClient.SetBaseURL(GetBaseUrl(endpoint));
return minioClient;
}
Expand All @@ -63,16 +63,21 @@ public static IMinioClient WithEndpoint(this IMinioClient minioClient, string en
throw new ArgumentException(
string.Format(CultureInfo.InvariantCulture, "Port {0} is not a number between 1 and 65535", port),
nameof(port));
return minioClient.WithEndpoint(endpoint + ":" + port);
endpoint = endpoint + ":" + port.ToString(CultureInfo.InvariantCulture);
minioClient.Config.Endpoint = endpoint;
minioClient.SetBaseURL(GetBaseUrl(endpoint));
return minioClient;
}

public static IMinioClient WithEndpoint(this IMinioClient minioClient, Uri url)
{
if (minioClient is null) throw new ArgumentNullException(nameof(minioClient));

if (url is null) throw new ArgumentNullException(nameof(url));
minioClient.SetBaseURL(url);
minioClient.Config.Endpoint = url.AbsoluteUri;

return minioClient.WithEndpoint(url.AbsoluteUri);
return minioClient;
}

public static IMinioClient WithRegion(this IMinioClient minioClient, string region)
Expand All @@ -92,7 +97,7 @@ public static IMinioClient WithRegion(this IMinioClient minioClient)
{
if (minioClient is null) throw new ArgumentNullException(nameof(minioClient));
// Set region to its default value if empty or null
minioClient.Config.Region = "us-east-1";
minioClient.Config.Region ??= "us-east-1";
return minioClient;
}

Expand Down Expand Up @@ -120,15 +125,7 @@ public static IMinioClient WithSessionToken(this IMinioClient minioClient, strin
public static IMinioClient WithSSL(this IMinioClient minioClient, bool secure = true)
{
if (minioClient is null) throw new ArgumentNullException(nameof(minioClient));

if (secure)
{
minioClient.Config.Secure = true;
if (string.IsNullOrEmpty(minioClient.Config.BaseUrl))
return minioClient;
//var secureUrl = RequestUtil.MakeTargetURL(minioClient.BaseUrl, minioClient.Secure);
}

minioClient.Config.Secure = secure;
return minioClient;
}

Expand Down
Loading

0 comments on commit 3a38f1e

Please sign in to comment.