Stream Opus/derived read path: serve from seekable disk FileStream, never a whole-file byte[]; HasOpusAsync is index-only
This commit is contained in:
@@ -26,10 +26,10 @@ namespace DeepDrftTests;
|
||||
/// required to assert the delivery contract.
|
||||
///
|
||||
/// The Range→206 contract is asserted at the load-bearing seam: ASP.NET performs the actual byte-slicing
|
||||
/// for any <see cref="FileResult"/> whose <see cref="FileResult"/>.EnableRangeProcessing is true. The lossless
|
||||
/// path proves this via the disk-stream <see cref="FileStreamResult"/>; the resolved Opus path via the
|
||||
/// in-memory <see cref="FileContentResult"/> — both must report range processing enabled, the explicit fix
|
||||
/// the 18.2 reviewer flagged for the byte[] path.
|
||||
/// for any <see cref="FileResult"/> whose <see cref="FileResult"/>.EnableRangeProcessing is true over a
|
||||
/// seekable stream. Both the lossless path AND the resolved Opus path now serve a disk-backed
|
||||
/// <see cref="FileStreamResult"/> (read-path streaming — no whole-file byte[]); both must report range
|
||||
/// processing enabled, and the FileStream is seekable, so an incoming Range yields a 206 slice.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class TrackFormatDeliveryTests
|
||||
@@ -59,13 +59,14 @@ public class TrackFormatDeliveryTests
|
||||
|
||||
var result = await controller.GetTrack(entryKey, format: "opus");
|
||||
|
||||
var file = result as FileContentResult;
|
||||
Assert.That(file, Is.Not.Null, "Opus delivery serves an in-memory byte[] (FileContentResult)");
|
||||
var file = result as FileStreamResult;
|
||||
Assert.That(file, Is.Not.Null, "Opus delivery streams from disk (FileStreamResult), not a byte[]");
|
||||
var bytes = await ReadAllAsync(file!.FileStream);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(file!.ContentType, Is.EqualTo("audio/ogg"), "Opus bytes must carry the audio/ogg content-type");
|
||||
Assert.That(file.FileContents, Is.EqualTo(OpusBytes), "The served bytes must be the Opus artifact, not the source");
|
||||
Assert.That(file.EnableRangeProcessing, Is.True, "Range processing must be enabled on the resolved Opus byte[] path");
|
||||
Assert.That(file.ContentType, Is.EqualTo("audio/ogg"), "Opus bytes must carry the audio/ogg content-type");
|
||||
Assert.That(bytes, Is.EqualTo(OpusBytes), "The served bytes must be the Opus artifact, not the source");
|
||||
Assert.That(file.EnableRangeProcessing, Is.True, "Range processing must be enabled on the resolved Opus stream path");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,12 +81,13 @@ public class TrackFormatDeliveryTests
|
||||
|
||||
var result = await controller.GetTrack(entryKey, format: "opus");
|
||||
|
||||
var file = result as FileContentResult;
|
||||
Assert.That(file, Is.Not.Null, "The fallback still serves resolved bytes via the byte[] path");
|
||||
var file = result as FileStreamResult;
|
||||
Assert.That(file, Is.Not.Null, "The fallback still streams resolved bytes from disk (FileStreamResult)");
|
||||
var bytes = await ReadAllAsync(file!.FileStream);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(file!.ContentType, Is.EqualTo("audio/wav"), "Fallback content-type must be the lossless source's MIME");
|
||||
Assert.That(file.FileContents, Is.EqualTo(_sourceWav), "Fallback must serve the lossless source bytes");
|
||||
Assert.That(file.ContentType, Is.EqualTo("audio/wav"), "Fallback content-type must be the lossless source's MIME");
|
||||
Assert.That(bytes, Is.EqualTo(_sourceWav), "Fallback must serve the lossless source bytes");
|
||||
Assert.That(file.EnableRangeProcessing, Is.True, "Range processing stays enabled on the fallback path too");
|
||||
});
|
||||
}
|
||||
@@ -167,6 +169,18 @@ public class TrackFormatDeliveryTests
|
||||
|
||||
private byte[] _sourceWav = [];
|
||||
|
||||
// Drains a FileStreamResult's disk-backed stream to a byte[] and disposes it (read-path streaming serves
|
||||
// an open FileStream, not a buffered byte[]). Disposing also releases the handle before temp-dir teardown.
|
||||
private static async Task<byte[]> ReadAllAsync(Stream stream)
|
||||
{
|
||||
await using (stream)
|
||||
{
|
||||
using var ms = new MemoryStream();
|
||||
await stream.CopyToAsync(ms);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<FileDb> FreshDbAsync()
|
||||
{
|
||||
var db = await FileDb.FromAsync(_testDir);
|
||||
|
||||
Reference in New Issue
Block a user