Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifecycle expiration date, WithEndpoint, WithSSL issues cause functional tests to fail #844

Merged
merged 9 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 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 @@ -2702,7 +2701,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 +2730,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 +2739,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 +2771,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 @@ -5389,7 +5387,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 +6044,22 @@ 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 calculatedExpDate = expDate.AddDays(1).AddSeconds(-1).ToUniversalTime().Date;
var expInDays = (calculatedExpDate.ToLocalTime().Date - baseDate.Date).TotalDays;

var rule1 = new LifecycleRule(null, "txt", exp, null,
new RuleFilter(null, "txt/", null),
null, null, LifecycleRule.LifecycleRuleStatusEnabled
);
new RuleFilter(null, "txt/", null), null, null, LifecycleRule.LifecycleRuleStatusEnabled);
rules.Add(rule1);
var lfc = new LifecycleConfiguration(rules);
try
Expand All @@ -6082,7 +6081,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 +6096,8 @@ 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);
Assert.AreEqual((lfcDate.Date - baseDate.Date).TotalDays, expInDays);
new MintLogger(nameof(BucketLifecycleAsync_Test1) + ".2", getBucketLifecycleSignature,
"Tests whether GetBucketLifecycleAsync passes", TestStatus.PASS, DateTime.Now - startTime,
args: args)
Expand Down
12 changes: 10 additions & 2 deletions Minio/ApiEndpoints/BucketOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,20 @@ public async Task<bool> BucketExistsAsync(BucketExistsArgs args, CancellationTok
await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder,
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
13 changes: 4 additions & 9 deletions Minio/MinioClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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,6 +64,7 @@ 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));
minioClient.Config.Endpoint = endpoint;
return minioClient.WithEndpoint(endpoint + ":" + port);
}

Expand All @@ -71,6 +73,7 @@ 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.Config.Endpoint = url.AbsoluteUri;

return minioClient.WithEndpoint(url.AbsoluteUri);
}
Expand Down Expand Up @@ -120,15 +123,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
50 changes: 41 additions & 9 deletions Minio/RequestExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http.Headers;
using Microsoft.Win32;
using Minio.Credentials;
using Minio.DataModel;
using Minio.DataModel.Args;
Expand Down Expand Up @@ -47,18 +50,29 @@ internal static Task<ResponseResult> ExecuteTaskAsync(this IMinioClient minioCli
bool isSts = false,
CancellationToken cancellationToken = default)
{
if (minioClient.Config.RequestTimeout > 0)
Task<ResponseResult> responseResult;
try
{
if (minioClient.Config.RequestTimeout > 0)
{
using var internalTokenSource =
new CancellationTokenSource(new TimeSpan(0, 0, 0, 0, minioClient.Config.RequestTimeout));
using var timeoutTokenSource =
CancellationTokenSource.CreateLinkedTokenSource(internalTokenSource.Token, cancellationToken);
cancellationToken = timeoutTokenSource.Token;
}

responseResult = minioClient.ExecuteWithRetry(
async () => await minioClient.ExecuteTaskCoreAsync(errorHandlers, requestMessageBuilder,
isSts, cancellationToken).ConfigureAwait(false));
}
catch (Exception ex)
{
using var internalTokenSource =
new CancellationTokenSource(new TimeSpan(0, 0, 0, 0, minioClient.Config.RequestTimeout));
using var timeoutTokenSource =
CancellationTokenSource.CreateLinkedTokenSource(internalTokenSource.Token, cancellationToken);
cancellationToken = timeoutTokenSource.Token;
Console.WriteLine($"\n\n *** ExecuteTaskAsync::Threw an exception => {ex.Message}");
throw;
}

return minioClient.ExecuteWithRetry(
() => minioClient.ExecuteTaskCoreAsync(errorHandlers, requestMessageBuilder,
isSts, cancellationToken));
return responseResult;
}

private static async Task<ResponseResult> ExecuteTaskCoreAsync(this IMinioClient minioClient,
Expand Down Expand Up @@ -101,6 +115,24 @@ await requestMessageBuilder.FunctionResponseWriter(responseResult.ContentStream,
responseResult = new ResponseResult(request, e);
}

if (responseResult.StatusCode == HttpStatusCode.NotFound)
{
if (request.Method == HttpMethod.Head)
{
Exception ex = new BucketNotFoundException();
responseResult.Exception = ex;
return responseResult;
}

if (request.RequestUri.ToString().Contains("lock", StringComparison.OrdinalIgnoreCase) &&
request.Method == HttpMethod.Get)
{
Exception ex = new MissingObjectLockConfigurationException();
responseResult.Exception = ex;
return responseResult;
}
}

minioClient.HandleIfErrorResponse(responseResult, errorHandlers, startTime);
return responseResult;
}
Expand Down
Loading