Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Daqifi.Core.Tests/Daqifi.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
<PackageReference Include="coverlet.msbuild" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="coverlet.collector" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@
Assert.Single(samples);
Assert.NotNull(samples[0].AnalogTimestamps);
Assert.Equal(2, samples[0].AnalogTimestamps!.Count);
Assert.Equal(1000u, samples[0].AnalogTimestamps[0]);

Check warning on line 183 in src/Daqifi.Core.Tests/Device/SdCard/SdCardCsvFileParserTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
Assert.Equal(1001u, samples[0].AnalogTimestamps[1]);

Check warning on line 184 in src/Daqifi.Core.Tests/Device/SdCard/SdCardCsvFileParserTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}

[Fact]
Expand All @@ -201,9 +201,9 @@
Assert.NotNull(samples[0].AnalogTimestamps);
Assert.Equal(3, samples[0].AnalogTimestamps!.Count);
// All channels share the same timestamp in shared-ts mode
Assert.Equal(1746522255u, samples[0].AnalogTimestamps[0]);

Check warning on line 204 in src/Daqifi.Core.Tests/Device/SdCard/SdCardCsvFileParserTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
Assert.Equal(1746522255u, samples[0].AnalogTimestamps[1]);

Check warning on line 205 in src/Daqifi.Core.Tests/Device/SdCard/SdCardCsvFileParserTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
Assert.Equal(1746522255u, samples[0].AnalogTimestamps[2]);

Check warning on line 206 in src/Daqifi.Core.Tests/Device/SdCard/SdCardCsvFileParserTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}

// -------------------------------------------------------------------------
Expand Down Expand Up @@ -447,7 +447,7 @@
var parser = new global::Daqifi.Core.Device.SdCard.SdCardCsvFileParser();
var options = new global::Daqifi.Core.Device.SdCard.SdCardParseOptions
{
Progress = new Progress<global::Daqifi.Core.Device.SdCard.SdCardParseProgress>(p =>
Progress = new SynchronousProgress<global::Daqifi.Core.Device.SdCard.SdCardParseProgress>(p =>
{
progressCalls++;
lastProgress = p;
Expand All @@ -459,7 +459,7 @@

Assert.Equal(250, samples.Count);
Assert.True(progressCalls >= 2, $"Expected ≥2 progress callbacks, got {progressCalls}");
Assert.Equal(250, lastProgress.MessagesRead);

Check warning on line 462 in src/Daqifi.Core.Tests/Device/SdCard/SdCardCsvFileParserTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
Assert.True(lastProgress.BytesRead > 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,17 +485,14 @@ public async Task ParseAsync_ReportsProgressMonotonically()
var progressReports = new List<SdCardParseProgress>();
var options = new SdCardParseOptions
{
Progress = new Progress<SdCardParseProgress>(p => progressReports.Add(p))
Progress = new SynchronousProgress<SdCardParseProgress>(p => progressReports.Add(p))
};

// Act
var session = await _parser.ParseAsync(stream, "progress.bin", options);
// Enumerate samples to force full parse
await ToListAsync(session.Samples);

// Allow progress handler to execute (Progress<T> posts to SynchronizationContext)
await Task.Delay(100);

// Assert — at least one progress report
Assert.NotEmpty(progressReports);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,11 @@ public async Task ReceiveAsync_ProgressReporting_BytesReceivedIncreases()
var receiver = new SdCardFileReceiver(sourceStream, bufferSize: 100);

var progressReports = new System.Collections.Generic.List<SdCardTransferProgress>();
var progress = new Progress<SdCardTransferProgress>(p => progressReports.Add(p));
var progress = new SynchronousProgress<SdCardTransferProgress>(p => progressReports.Add(p));

// Act
await receiver.ReceiveAsync(destinationStream, "test.bin", progress);

// Allow progress callbacks to fire (they're posted to the sync context)
await Task.Delay(100);

// Assert — we should have received at least one progress report
Assert.NotEmpty(progressReports);
Assert.All(progressReports, p =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,16 @@ public async Task ParseAsync_ProgressReporting_CallsCallback()
);

var progressCalls = 0;
var lastProgress = default(global::Daqifi.Core.Device.SdCard.SdCardParseProgress);
var parser = new global::Daqifi.Core.Device.SdCard.SdCardJsonFileParser();
var options = new global::Daqifi.Core.Device.SdCard.SdCardParseOptions
{
FallbackTimestampFrequency = 100,
Progress = new Progress<global::Daqifi.Core.Device.SdCard.SdCardParseProgress>(p =>
Progress = new SynchronousProgress<global::Daqifi.Core.Device.SdCard.SdCardParseProgress>(p =>
{
progressCalls++;
lastProgress = p;
Assert.True(p.BytesRead >= 0);
Assert.Equal(250, p.MessagesRead);
})
};

Expand All @@ -272,6 +273,7 @@ public async Task ParseAsync_ProgressReporting_CallsCallback()
// Assert
Assert.Equal(250, samples.Count);
Assert.True(progressCalls >= 2); // At least 2 progress updates (100-line batches + final)
Assert.Equal(250, lastProgress.MessagesRead);
}

[Fact]
Expand Down
13 changes: 13 additions & 0 deletions src/Daqifi.Core.Tests/Device/SdCard/SynchronousProgress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace Daqifi.Core.Tests.Device.SdCard;

/// <summary>
/// A synchronous <see cref="IProgress{T}"/> implementation for tests.
/// Unlike <see cref="Progress{T}"/>, this invokes the callback inline on the
/// calling thread, avoiding race conditions in assertions.
/// </summary>
internal sealed class SynchronousProgress<T>(Action<T> handler) : IProgress<T>
{
public void Report(T value) => handler(value);
}
Loading