diff --git a/changelog.d/unreleased/2775.fixed.md b/changelog.d/unreleased/2775.fixed.md new file mode 100644 index 0000000000..b2c7a790b2 --- /dev/null +++ b/changelog.d/unreleased/2775.fixed.md @@ -0,0 +1,17 @@ +--- +category: fixed +issues: + - 2775 +affected: + - tests/CodeIndex.Tests/TestConsoleLock.cs + - tests/CodeIndex.Tests/ConsoleCaptureTests.cs + - tests/CodeIndex.Tests/ChangelogToolTests.cs +--- + +## English + +- **net9 test runs no longer close shared console capture writers (#2775)** - console capture helpers now restore global streams without disposing captured writers, and changelog console tests run in the non-parallel test collection. + +## 日本語 + +- **net9 テスト実行で共有 console capture writer を閉じないようになりました (#2775)** - console capture helper は global stream を復元しても捕捉 writer を dispose せず、changelog の console テストも非並列 test collection で実行します。 diff --git a/tests/CodeIndex.Tests/ChangelogToolTests.cs b/tests/CodeIndex.Tests/ChangelogToolTests.cs index f889a93fc7..9ed3cffeb4 100644 --- a/tests/CodeIndex.Tests/ChangelogToolTests.cs +++ b/tests/CodeIndex.Tests/ChangelogToolTests.cs @@ -2,6 +2,7 @@ namespace CodeIndex.Tests; +[Collection("SQLite pool sensitive")] public sealed class ChangelogToolTests { [Fact] diff --git a/tests/CodeIndex.Tests/ConsoleCaptureTests.cs b/tests/CodeIndex.Tests/ConsoleCaptureTests.cs index 9deea525da..3038698b82 100644 --- a/tests/CodeIndex.Tests/ConsoleCaptureTests.cs +++ b/tests/CodeIndex.Tests/ConsoleCaptureTests.cs @@ -1,5 +1,6 @@ namespace CodeIndex.Tests; +[Collection("SQLite pool sensitive")] public class ConsoleCaptureTests { [Fact] @@ -33,4 +34,23 @@ public void Capture_RestoresConsoleStreams_WhenActionThrows() Assert.Same(originalError, Console.Error); } } + + [Fact] + public void Dispose_DoesNotCloseCapturedWriters() + { + var stdout = new StringWriter(); + var stderr = new StringWriter(); + + using (var capture = ConsoleCapture.Start(stdout, stderr)) + { + Console.Write("out"); + Console.Error.Write("err"); + } + + stdout.Write(" after"); + stderr.Write(" after"); + + Assert.Equal("out after", stdout.ToString()); + Assert.Equal("err after", stderr.ToString()); + } } diff --git a/tests/CodeIndex.Tests/TestConsoleLock.cs b/tests/CodeIndex.Tests/TestConsoleLock.cs index 3192ae8f52..ff89304453 100644 --- a/tests/CodeIndex.Tests/TestConsoleLock.cs +++ b/tests/CodeIndex.Tests/TestConsoleLock.cs @@ -86,10 +86,6 @@ public void Dispose() Restore(); disposed = true; - if (Out is not null) - Out.Dispose(); - if (Error is not null) - Error.Dispose(); System.Threading.Monitor.Exit(TestConsoleLock.Gate); }