Repository navigation
Fix/test isolation #724
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
Merged
Merged
Fix/test isolation #724
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
24 changes: 24 additions & 0 deletions
24
src/LogExpert.Persister.Tests/PluginTrustIsolationSetup.cs
This file contains hidden or 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,24 @@ | ||
| using LogExpert.PluginRegistry; | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| // Outside any namespace so it runs once before every fixture in the assembly. | ||
| [SetUpFixture] | ||
| public class PluginTrustIsolationSetup | ||
| { | ||
| private readonly string _configDir = Path.Join(Path.GetTempPath(), "LogExpert_TestPluginTrust_" + Guid.NewGuid().ToString("N")); | ||
|
|
||
| // Until initialized, PluginValidator reads and writes trusted-plugins.json in the developer's %APPDATA%\LogExpert. | ||
| [OneTimeSetUp] | ||
| public void RedirectPluginTrust () | ||
| { | ||
| _ = Directory.CreateDirectory(_configDir); | ||
| PluginValidator.Initialize(_configDir); | ||
| } | ||
|
|
||
| [OneTimeTearDown] | ||
| public void RemovePluginTrustDir () | ||
| { | ||
| Directory.Delete(_configDir, recursive: true); | ||
| } | ||
| } |
This file contains hidden or 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,29 @@ | ||
| using LogExpert.Configuration; | ||
| using LogExpert.PluginRegistry; | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| // Outside any namespace so it runs once before every fixture in the assembly. | ||
| [SetUpFixture] | ||
| public class ConfigDirIsolationSetup | ||
| { | ||
| private string _configDir; | ||
|
|
||
| [OneTimeSetUp] | ||
| public void RedirectConfigDir () | ||
| { | ||
| _configDir = Path.Join(Path.GetTempPath(), "LogExpert_TestConfig_" + Guid.NewGuid().ToString("N")); | ||
| _ = Directory.CreateDirectory(_configDir); | ||
| ConfigManager.Instance.ConfigDir = _configDir; | ||
| PluginValidator.Initialize(_configDir); | ||
| } | ||
|
|
||
| [OneTimeTearDown] | ||
| public void RemoveConfigDir () | ||
| { | ||
| if (Directory.Exists(_configDir)) | ||
| { | ||
| Directory.Delete(_configDir, recursive: true); | ||
| } | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/LogExpert.Tests/ConfigManagerTests/ConfigDirIsolationTests.cs
This file contains hidden or 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,23 @@ | ||
| using System.Reflection; | ||
|
|
||
| using LogExpert.Configuration; | ||
| using LogExpert.PluginRegistry; | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| namespace LogExpert.Tests.ConfigManagerTests; | ||
|
|
||
| [TestFixture] | ||
| public class ConfigDirIsolationTests | ||
| { | ||
| [Test] | ||
| public void Tests_NeverUseTheUsersRealConfigOrPluginTrustDirectory () | ||
| { | ||
| var realConfigDir = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "LogExpert"); | ||
|
|
||
| Assert.That(ConfigManager.Instance.ConfigDir, Is.Not.EqualTo(realConfigDir)); | ||
|
|
||
| var trustFile = (string)typeof(PluginValidator).GetField("_configPath", BindingFlags.NonPublic | BindingFlags.Static)!.GetValue(null)!; | ||
| Assert.That(trustFile, Does.Not.StartWith(realConfigDir)); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
| namespace LogExpert.UI.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Installs the WinForms synchronization context the app runs with. NUnit gives STA tests its own context, which | ||
| /// WinForms does not replace, so services that capture it would run UI callbacks on other threads. | ||
| /// </summary> | ||
| internal sealed class WinFormsSynchronizationScope : IDisposable | ||
| { | ||
| private readonly SynchronizationContext? _previous = SynchronizationContext.Current; | ||
| private readonly WindowsFormsSynchronizationContext _context = new(); | ||
|
|
||
| public WinFormsSynchronizationScope () | ||
| { | ||
| SynchronizationContext.SetSynchronizationContext(_context); | ||
| } | ||
|
|
||
| // Not disposed: disposing a WinForms context destroys the thread's shared marshaling control, and await | ||
| // continuations still queued by the test would then crash the test host. | ||
| public void Dispose () | ||
| { | ||
| SynchronizationContext.SetSynchronizationContext(_previous); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,24 @@ | ||
| using LogExpert.PluginRegistry; | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| // Outside any namespace so it runs once before every fixture in the assembly. | ||
| [SetUpFixture] | ||
| public class PluginTrustIsolationSetup | ||
| { | ||
| private readonly string _configDir = Path.Join(Path.GetTempPath(), "LogExpert_TestPluginTrust_" + Guid.NewGuid().ToString("N")); | ||
|
|
||
| // Until initialized, PluginValidator reads and writes trusted-plugins.json in the developer's %APPDATA%\LogExpert. | ||
| [OneTimeSetUp] | ||
| public void RedirectPluginTrust () | ||
| { | ||
| _ = Directory.CreateDirectory(_configDir); | ||
| PluginValidator.Initialize(_configDir); | ||
| } | ||
|
|
||
| [OneTimeTearDown] | ||
| public void RemovePluginTrustDir () | ||
| { | ||
| Directory.Delete(_configDir, recursive: true); | ||
| } | ||
| } |
This file contains hidden or 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,15 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- Applied to every test project through RunSettingsFilePath in Directory.Build.props. --> | ||
| <RunSettings> | ||
| <DataCollectionRunSettings> | ||
| <DataCollectors> | ||
| <!-- A single hung test (e.g. a WinForms deadlock) kills the test host after 3 minutes with a mini dump, | ||
| and the run reports which test was running, instead of the whole run freezing. --> | ||
| <DataCollector friendlyName="blame" enabled="true"> | ||
| <Configuration> | ||
| <CollectDumpOnTestSessionHang TestTimeout="3m" HangDumpType="mini" /> | ||
| </Configuration> | ||
| </DataCollector> | ||
| </DataCollectors> | ||
| </DataCollectionRunSettings> | ||
| </RunSettings> |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.