Skip to content

Commit 82ede12

Browse files
Copilotd2dyno1
andauthored
Fix flaky cache statistics test
Agent-Logs-Url: https://github.com/securefolderfs-community/SecureFolderFS/sessions/a546110b-189b-4498-8f4a-511e0a60aea2 Co-authored-by: d2dyno1 <53011783+d2dyno1@users.noreply.github.com>
1 parent 00ef614 commit 82ede12

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

tests/SecureFolderFS.Tests/FileSystemTests/FileSystemCacheTests.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System;
12
using System.Text;
3+
using System.Threading;
24
using FluentAssertions;
35
using NUnit.Framework;
46
using OwlCore.Storage;
@@ -38,12 +40,12 @@ public async Task Write_SmallStreamedFile_Then_WriteAgain_Ensure_CacheHit_NoThro
3840

3941
var cacheHits = 0;
4042
var cacheMisses = 0;
41-
_storageRoot.Options.FileSystemStatistics.ChunkCache = new Progress<CacheAccessType>(x =>
43+
_storageRoot.Options.FileSystemStatistics.ChunkCache = new InlineProgress<CacheAccessType>(x =>
4244
{
4345
if (x == CacheAccessType.CacheHit)
44-
cacheHits++;
46+
Interlocked.Increment(ref cacheHits);
4547
else if (x == CacheAccessType.CacheMiss)
46-
cacheMisses++;
48+
Interlocked.Increment(ref cacheMisses);
4749
});
4850

4951
// Act
@@ -66,5 +68,17 @@ public async Task Write_SmallStreamedFile_Then_WriteAgain_Ensure_CacheHit_NoThro
6668
Encoding.UTF8.GetString(buffer).Should().BeEquivalentTo(dataString + dataString);
6769
cacheMisses.Should().Be(1);
6870
}
71+
72+
private sealed class InlineProgress<T> : IProgress<T>
73+
{
74+
private readonly Action<T> _handler;
75+
76+
public InlineProgress(Action<T> handler)
77+
{
78+
_handler = handler ?? throw new ArgumentNullException(nameof(handler));
79+
}
80+
81+
public void Report(T value) => _handler(value);
82+
}
6983
}
70-
}
84+
}

0 commit comments

Comments
 (0)