[PR #1137] Fix async test failures after xunit v3 upgrade #1575

Open
opened 2026-01-29 22:21:12 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/adamhathcock/sharpcompress/pull/1137

State: closed
Merged: Yes


The xunit v3 upgrade exposed that async tests were not properly awaiting async operations. Tests were passing ValueTask<IAsyncReader> directly to await using statements instead of awaiting the task first, and ReaderFactory.OpenAsyncReader was calling synchronous IsArchive methods during format detection.

Changes

  • Made ReaderFactory.OpenAsyncReader properly async: Changed return type to ValueTask<IAsyncReader> and replaced synchronous IsArchive() calls with IsArchiveAsync() during format detection
  • Fixed test await patterns: Added explicit await before ReaderFactory.OpenAsyncReader() in all async test methods
  • Kept AsyncOnlyStream in Archive async tests: Archive async tests continue to use AsyncOnlyStream to validate that archive operations properly handle async-only streams, exposing areas where synchronous I/O is still used in async code paths

Example

Before:

await using var reader = ReaderFactory.OpenAsyncReader(stream); // Sync IsArchive() called internally

After:

await using var reader = await ReaderFactory.OpenAsyncReader(stream); // Async IsArchiveAsync() called

Known Limitations

  • Archive APIs: Archive opening performs synchronous I/O during format probing, causing tests with AsyncOnlyStream to fail. These tests intentionally expose the need for async archive opening support.
  • Compressed tar formats: Reader opening for compressed tar formats (tar.bz2, tar.lz, tar.gz) requires multi-step format probing not yet implemented in the async path, causing "Cannot determine compressed stream type" errors.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

**Original Pull Request:** https://github.com/adamhathcock/sharpcompress/pull/1137 **State:** closed **Merged:** Yes --- The xunit v3 upgrade exposed that async tests were not properly awaiting async operations. Tests were passing `ValueTask<IAsyncReader>` directly to `await using` statements instead of awaiting the task first, and `ReaderFactory.OpenAsyncReader` was calling synchronous `IsArchive` methods during format detection. ## Changes - **Made `ReaderFactory.OpenAsyncReader` properly async**: Changed return type to `ValueTask<IAsyncReader>` and replaced synchronous `IsArchive()` calls with `IsArchiveAsync()` during format detection - **Fixed test await patterns**: Added explicit `await` before `ReaderFactory.OpenAsyncReader()` in all async test methods - **Kept `AsyncOnlyStream` in Archive async tests**: Archive async tests continue to use `AsyncOnlyStream` to validate that archive operations properly handle async-only streams, exposing areas where synchronous I/O is still used in async code paths ## Example Before: ```csharp await using var reader = ReaderFactory.OpenAsyncReader(stream); // Sync IsArchive() called internally ``` After: ```csharp await using var reader = await ReaderFactory.OpenAsyncReader(stream); // Async IsArchiveAsync() called ``` ## Known Limitations - **Archive APIs**: Archive opening performs synchronous I/O during format probing, causing tests with `AsyncOnlyStream` to fail. These tests intentionally expose the need for async archive opening support. - **Compressed tar formats**: Reader opening for compressed tar formats (tar.bz2, tar.lz, tar.gz) requires multi-step format probing not yet implemented in the async path, causing "Cannot determine compressed stream type" errors. <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
claunia added the pull-request label 2026-01-29 22:21:12 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1575