mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Implements tests for commit 4e13b23f16
Covers the normalized audio cache with integration tests for the cache paths, the coordinator, the reader lease, the reservation, the lease stream, the output size tracker and the startup initializer, and unit tests for the playback format catalog and the transcoding toolchain status, with fixtures for the index DTOs and the transcoding settings. Makes the array based asynchronous overloads of the lease stream adapt to the memory based overloads of the inner stream.
This commit is contained in:
1 parent
cf3855ec12
commit
d61a114d80
13 files changed
+3011
-2
No files matched your search
+66
@@ -0,0 +1,66 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="TranscodingSettingsDto"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TranscodingSettingsDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="TranscodingSettingsDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="ffmpegPath">Optional file name or path of the ffmpeg binary.</param>
|
||||
/// <param name="maxConcurrentJobs">Optional maximum number of normalization jobs that may run at the same time.</param>
|
||||
/// <param name="maxConcurrentJobsPerUser">Optional maximum number of normalization jobs a single user may have running at the same time.</param>
|
||||
/// <param name="maxCacheBytes">Optional maximum total size of the normalized audio cache, in bytes.</param>
|
||||
/// <param name="jobTimeoutSeconds">Optional maximum duration of a single normalization job, in seconds.</param>
|
||||
/// <param name="evictionGraceSeconds">Optional period during which a cache entry is protected from eviction, in seconds.</param>
|
||||
/// <param name="cacheDirectory">
|
||||
/// Optional directory where normalized audio is cached. When it is not supplied, a generated directory is used. When
|
||||
/// <paramref name="includeCacheDirectory"/> is <see langword="false"/>, the property stays <see langword="null"/>, which makes the pipeline use the
|
||||
/// default temporary directory.
|
||||
/// </param>
|
||||
/// <param name="includeCacheDirectory">Whether to generate the optional cache directory, defaulting to <see langword="true"/>.</param>
|
||||
/// <returns>A configured <see cref="TranscodingSettingsDto"/> instance.</returns>
|
||||
public TranscodingSettingsDto Create(
|
||||
string? ffmpegPath = null,
|
||||
int? maxConcurrentJobs = null,
|
||||
int? maxConcurrentJobsPerUser = null,
|
||||
long? maxCacheBytes = null,
|
||||
int? jobTimeoutSeconds = null,
|
||||
int? evictionGraceSeconds = null,
|
||||
string? cacheDirectory = null,
|
||||
bool includeCacheDirectory = true)
|
||||
{
|
||||
return new TranscodingSettingsDto
|
||||
{
|
||||
FfmpegPath = ffmpegPath ?? _faker.System.FileName("exe"),
|
||||
MaxConcurrentJobs = maxConcurrentJobs ?? _faker.Random.Int(1, 16),
|
||||
MaxConcurrentJobsPerUser = maxConcurrentJobsPerUser ?? _faker.Random.Int(1, 8),
|
||||
MaxCacheBytes = maxCacheBytes ?? _faker.Random.Long(1_000_000_000, 8_589_934_592),
|
||||
JobTimeoutSeconds = jobTimeoutSeconds ?? _faker.Random.Int(60, 3600),
|
||||
EvictionGraceSeconds = evictionGraceSeconds ?? _faker.Random.Int(0, 600),
|
||||
CacheDirectory = includeCacheDirectory ? cacheDirectory ?? _faker.System.DirectoryPath() : null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="TranscodingSettingsDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="TranscodingSettingsDto"/> instances.</returns>
|
||||
public List<TranscodingSettingsDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Common.Models.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="NormalizedTrackIndexDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal class NormalizedTrackIndexDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly NormalizedTrackSegmentIndexDtoFixture _normalizedTrackSegmentIndexDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="NormalizedTrackIndexDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="version">Optional version of the index layout.</param>
|
||||
/// <param name="trackId">Optional Id of the track the cached audio belongs to.</param>
|
||||
/// <param name="mode">Optional way the audio is delivered.</param>
|
||||
/// <param name="container">Optional container of the delivered audio.</param>
|
||||
/// <param name="codec">Optional codec of the delivered audio.</param>
|
||||
/// <param name="segmentDurationSeconds">Optional duration of each segment, in seconds.</param>
|
||||
/// <param name="durationInSeconds">Optional duration of the produced and cached audio, in seconds.</param>
|
||||
/// <param name="segments">
|
||||
/// Optional segments that make up the delivered audio, in playback order. A caller can supply an explicit list, including an empty one; when it is not
|
||||
/// supplied a random bounded list is generated.
|
||||
/// </param>
|
||||
/// <returns>The created <see cref="NormalizedTrackIndexDto"/>.</returns>
|
||||
public NormalizedTrackIndexDto Create(
|
||||
int? version = null,
|
||||
Guid? trackId = null,
|
||||
PlaybackDeliveryMode? mode = null,
|
||||
string? container = null,
|
||||
string? codec = null,
|
||||
int? segmentDurationSeconds = null,
|
||||
int? durationInSeconds = null,
|
||||
IReadOnlyList<NormalizedTrackSegmentIndexDto>? segments = null)
|
||||
{
|
||||
return new NormalizedTrackIndexDto(
|
||||
version ?? _faker.Random.Int(1, 10),
|
||||
trackId ?? _faker.Random.Guid(),
|
||||
mode ?? _faker.PickRandom(PlaybackDeliveryMode.DirectPlay, PlaybackDeliveryMode.Remux, PlaybackDeliveryMode.Transcode),
|
||||
container ?? _faker.PickRandom("MP4", "OGG", "WAV", "FLAC"),
|
||||
codec ?? _faker.PickRandom("AAC", "VORBIS", "PCM", "FLAC"),
|
||||
segmentDurationSeconds ?? _faker.Random.Int(1, 60),
|
||||
durationInSeconds ?? _faker.Random.Int(1, 100_000),
|
||||
segments ?? [.. _normalizedTrackSegmentIndexDtoFixture.CreateMany(_faker.Random.Int(1, 5))]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="NormalizedTrackIndexDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="NormalizedTrackIndexDto"/> instances.</returns>
|
||||
public List<NormalizedTrackIndexDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Common.Models.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Playback;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="NormalizedTrackSegmentIndexDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal class NormalizedTrackSegmentIndexDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="NormalizedTrackSegmentIndexDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="index">Optional zero based position of the segment in the delivered audio.</param>
|
||||
/// <param name="startSeconds">Optional time, in seconds from the start of the track, at which the segment starts.</param>
|
||||
/// <param name="durationSeconds">Optional duration of the segment, in seconds.</param>
|
||||
/// <param name="fileName">Optional file name of the segment inside the cache entry.</param>
|
||||
/// <param name="length">Optional length of the segment, in bytes.</param>
|
||||
/// <returns>The created <see cref="NormalizedTrackSegmentIndexDto"/>.</returns>
|
||||
public NormalizedTrackSegmentIndexDto Create(
|
||||
int? index = null,
|
||||
decimal? startSeconds = null,
|
||||
decimal? durationSeconds = null,
|
||||
string? fileName = null,
|
||||
long? length = null)
|
||||
{
|
||||
return new NormalizedTrackSegmentIndexDto(
|
||||
index ?? _faker.Random.Int(0, 10_000),
|
||||
startSeconds ?? _faker.Random.Decimal(0m, 100_000m),
|
||||
durationSeconds ?? _faker.Random.Decimal(1m, 600m),
|
||||
fileName ?? $"segment{_faker.Random.Int(0, 10_000):D6}{_faker.PickRandom(".m4s", ".mp4", ".ts")}",
|
||||
length ?? _faker.Random.Long(1, 100_000_000)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="NormalizedTrackSegmentIndexDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="NormalizedTrackSegmentIndexDto"/> instances.</returns>
|
||||
public List<NormalizedTrackSegmentIndexDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(segmentIndex => Create(index: segmentIndex))];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user