-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Recursion causing stack overflow when disposing client/service (#…
…588) - Fix recursion causing stack overflow when disposing client/service - Add unit tests to verify disposal does not cause stack overflow - Don't dispose of client via service due to shared reference (service can be disposed of via client)
- Loading branch information
Showing
15 changed files
with
197 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Collections.Generic; | ||
using EasyPost._base; | ||
using EasyPost.Http; | ||
using Xunit; | ||
using CustomAssertions = EasyPost.Tests._Utilities.Assertions.Assert; | ||
|
||
namespace EasyPost.Tests.HttpTests; | ||
|
||
public class RequestTest | ||
{ | ||
#region Tests | ||
|
||
[Fact] | ||
public void TestRequestDisposal() | ||
{ | ||
Request request = new("https://google.com", "not_a_real_endpoint", Method.Get, ApiVersion.V2, new Dictionary<string, object> { { "key", "value" } }, new Dictionary<string, string> { { "header_key", "header_value" } }); | ||
CustomAssertions.DoesNotThrow(() => request.Dispose()); | ||
} | ||
|
||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
EasyPost.Tests/_Utilities/Assertions/DoesNotThrowAssert.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
|
||
namespace EasyPost.Tests._Utilities.Assertions | ||
{ | ||
// ReSharper disable once PartialTypeWithSinglePart | ||
public abstract partial class Assert | ||
{ | ||
/// <summary> | ||
/// Verifies that an action does not throw an exception. | ||
/// </summary> | ||
/// <param name="action">The action to test</param> | ||
/// <exception cref="DoesNotThrowException">Thrown when the action throws an exception</exception> | ||
public static void DoesNotThrow(Action action) | ||
{ | ||
GuardArgumentNotNull(nameof(action), action); | ||
|
||
try | ||
{ | ||
action(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new DoesNotThrowException(ex); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Verifies that an action does not throw a specific exception. | ||
/// </summary> | ||
/// <param name="action">The action to test</param> | ||
/// <typeparam name="T">The type of the exception to not throw</typeparam> | ||
/// <exception cref="DoesNotThrowException">Thrown when the action throws an exception of type T</exception> | ||
public static void DoesNotThrow<T>(Action action) where T : Exception | ||
{ | ||
GuardArgumentNotNull(nameof(action), action); | ||
|
||
try | ||
{ | ||
action(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (ex.GetType() == typeof(T)) | ||
{ | ||
throw new DoesNotThrowException(ex); | ||
} | ||
} | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
EasyPost.Tests/_Utilities/Assertions/DoesNotThrowException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using Xunit.Sdk; | ||
|
||
namespace EasyPost.Tests._Utilities.Assertions | ||
{ | ||
/// <summary> | ||
/// Exception thrown when a DoesNotThrow assertion fails. | ||
/// </summary> | ||
public class DoesNotThrowException : XunitException | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of the <see cref="DoesNotThrowException"/> class. | ||
/// </summary> | ||
public DoesNotThrowException(Exception ex) | ||
: base("Assert.DoesNotThrow() Failure", ex) | ||
{ | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
EasyPost.Tests/_Utilities/Assertions/GuardArgumentNotNull.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
namespace EasyPost.Tests._Utilities.Assertions | ||
{ | ||
// ReSharper disable once PartialTypeWithSinglePart | ||
public abstract partial class Assert | ||
{ | ||
private static void GuardArgumentNotNull(string argName, object argValue) | ||
{ | ||
if (argValue == null) | ||
throw new ArgumentNullException(argName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.