-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Remove IAsyncLifetime from TestKit #6475
Merged
Aaronontheweb
merged 1 commit into
akkadotnet:dev
from
Arkatufus:REMOVE_IAsyncLifetime_from_TestKit
Mar 1, 2023
Merged
Remove IAsyncLifetime from TestKit #6475
Aaronontheweb
merged 1 commit into
akkadotnet:dev
from
Arkatufus:REMOVE_IAsyncLifetime_from_TestKit
Mar 1, 2023
Conversation
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
Aaronontheweb
requested changes
Mar 1, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the internals of the xUnit2 TestKit
base class look exactly like how they did in v1.4, XML-DOC comments and all:
akka.net/src/contrib/testkits/Akka.TestKit.Xunit2/TestKit.cs
Lines 22 to 168 in a455019
public class TestKit : TestKitBase , IDisposable | |
{ | |
private bool _isDisposed; //Automatically initialized to false; | |
/// <summary> | |
/// The provider used to write test output. | |
/// </summary> | |
protected readonly ITestOutputHelper Output; | |
/// <summary> | |
/// <para> | |
/// Initializes a new instance of the <see cref="TestKit"/> class. | |
/// </para> | |
/// <para> | |
/// If no <paramref name="system"/> is passed in, a new system with | |
/// <see cref="DefaultConfig"/> will be created. | |
/// </para> | |
/// </summary> | |
/// <param name="system">The actor system to use for testing. The default value is <see langword="null"/>.</param> | |
/// <param name="output">The provider used to write test output. The default value is <see langword="null"/>.</param> | |
public TestKit(ActorSystem system = null, ITestOutputHelper output = null) | |
: base(Assertions, system) | |
{ | |
Output = output; | |
InitializeLogger(Sys); | |
} | |
/// <summary> | |
/// Initializes a new instance of the <see cref="TestKit"/> class. | |
/// </summary> | |
/// <param name="config">The <see cref="Setup"/> to use for configuring the ActorSystem.</param> | |
/// <param name="actorSystemName">The name of the system. The default name is "test".</param> | |
/// <param name="output">The provider used to write test output. The default value is <see langword="null"/>.</param> | |
public TestKit(ActorSystemSetup config, string actorSystemName = null, ITestOutputHelper output = null) | |
: base(Assertions, config, actorSystemName) | |
{ | |
Output = output; | |
InitializeLogger(Sys); | |
} | |
/// <summary> | |
/// Initializes a new instance of the <see cref="TestKit"/> class. | |
/// </summary> | |
/// <param name="config">The configuration to use for the system.</param> | |
/// <param name="actorSystemName">The name of the system. The default name is "test".</param> | |
/// <param name="output">The provider used to write test output. The default value is <see langword="null"/>.</param> | |
public TestKit(Config config, string actorSystemName = null, ITestOutputHelper output = null) | |
: base(Assertions, config, actorSystemName) | |
{ | |
Output = output; | |
InitializeLogger(Sys); | |
} | |
/// <summary> | |
/// Initializes a new instance of the <see cref="TestKit"/> class. | |
/// </summary> | |
/// <param name="config">The configuration to use for the system.</param> | |
/// <param name="output">The provider used to write test output. The default value is <see langword="null"/>.</param> | |
public TestKit(string config, ITestOutputHelper output = null) | |
: base(Assertions, ConfigurationFactory.ParseString(config)) | |
{ | |
Output = output; | |
InitializeLogger(Sys); | |
} | |
/// <summary> | |
/// A configuration that has just the default log settings enabled. The default settings can be found in | |
/// <a href="https://github.com/akkadotnet/akka.net/blob/master/src/core/Akka.TestKit/Internal/Reference.conf">Akka.TestKit.Internal.Reference.conf</a>. | |
/// </summary> | |
public new static Config DefaultConfig => TestKitBase.DefaultConfig; | |
/// <summary> | |
/// A configuration that has all log settings enabled | |
/// </summary> | |
public new static Config FullDebugConfig => TestKitBase.FullDebugConfig; | |
/// <summary> | |
/// Commonly used assertions used throughout the testkit. | |
/// </summary> | |
protected static XunitAssertions Assertions { get; } = new XunitAssertions(); | |
/// <summary> | |
/// This method is called when a test ends. | |
/// | |
/// <remarks> | |
/// If you override this, then make sure you either call base.AfterTest() or | |
/// <see cref="TestKitBase.Shutdown(System.Nullable{System.TimeSpan},bool)">TestKitBase.Shutdown</see> | |
/// to shut down the system. Otherwise a memory leak will occur. | |
/// </remarks> | |
/// </summary> | |
protected virtual void AfterAll() | |
{ | |
Shutdown(); | |
} | |
/// <summary> | |
/// Initializes a new <see cref="TestOutputLogger"/> used to log messages. | |
/// </summary> | |
/// <param name="system">The actor system used to attach the logger</param> | |
protected void InitializeLogger(ActorSystem system) | |
{ | |
if (Output != null) | |
{ | |
var extSystem = (ExtendedActorSystem)system; | |
var logger = extSystem.SystemActorOf(Props.Create(() => new TestOutputLogger(Output)), "log-test"); | |
logger.Tell(new InitializeLogger(system.EventStream)); | |
} | |
} | |
public void Dispose() | |
{ | |
Dispose(true); | |
//Take this object off the finalization queue and prevent finalization code for this object | |
//from executing a second time. | |
GC.SuppressFinalize(this); | |
} | |
/// <summary> | |
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. | |
/// </summary> | |
/// <param name="disposing"> | |
/// if set to <c>true</c> the method has been called directly or indirectly by a user's code. | |
/// Managed and unmanaged resources will be disposed.<br /> if set to <c>false</c> the method | |
/// has been called by the runtime from inside the finalizer and only unmanaged resources can | |
/// be disposed. | |
/// </param> | |
protected virtual void Dispose(bool disposing) | |
{ | |
// If disposing equals false, the method has been called by the | |
// runtime from inside the finalizer and you should not reference | |
// other objects. Only unmanaged resources can be disposed. | |
try | |
{ | |
//Make sure Dispose does not get called more than once, by checking the disposed field | |
if(!_isDisposed && disposing) | |
{ | |
AfterAll(); | |
} | |
_isDisposed = true; | |
} | |
finally | |
{ | |
} | |
} | |
} |
Aaronontheweb
approved these changes
Mar 1, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.