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
69 changes: 52 additions & 17 deletions .github/workflows/gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,69 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
dotnet-version: |
3.1.x
6.0.x
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-restore --verbosity normal /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov --logger "trx;LogFileName=results.trx"
- name: Publish NuGet artifacts
uses: actions/upload-artifact@v3

- name: Test (4.8)
run: dotnet test --no-restore --verbosity normal -f net48 --logger "trx;LogFileName=results4.trx"
- name: Generate unit test report (4.8)
uses: phoenix-actions/test-reporting@v8
id: unit-test-report-win48
if: success() || failure()
with:
name: NuGet package
path: BitFaster.Caching/bin/Release/
- name: Publish coverage report to coveralls.io
name: test results (win net4.8)
path: BitFaster.Caching.UnitTests/TestResults/results4.trx
reporter: dotnet-trx
only-summary: 'true'

- name: Test (3.1)
run: dotnet test --no-restore --verbosity normal -f netcoreapp3.1 /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov --logger "trx;LogFileName=results3.trx"
- name: Generate unit test report (3.1)
uses: phoenix-actions/test-reporting@v8
id: unit-test-report-win3
if: success() || failure()
with:
name: test results (win net3.1)
path: BitFaster.Caching.UnitTests/TestResults/results3.trx
reporter: dotnet-trx
only-summary: 'true'
- name: Publish coverage report to coveralls.io (3.1)
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: BitFaster.Caching.UnitTests/TestResults/coverage.info
flag-name: win
path-to-lcov: BitFaster.Caching.UnitTests/TestResults/coverage.netcoreapp3.1.info
flag-name: win3
parallel: true
- name: Generate unit test report

- name: Test (6.0)
run: dotnet test --no-restore --verbosity normal -f net6.0 /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov --logger "trx;LogFileName=results6.trx"
- name: Generate unit test report (6.0)
uses: phoenix-actions/test-reporting@v8
id: unit-test-report-win
id: unit-test-report-win6
if: success() || failure()
with:
name: test results (win)
path: BitFaster.Caching.UnitTests/TestResults/results.trx
name: test results (win net6.0)
path: BitFaster.Caching.UnitTests/TestResults/results6.trx
reporter: dotnet-trx
only-summary: 'true'
- name: Publish coverage report to coveralls.io (6.0)
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: BitFaster.Caching.UnitTests/TestResults/coverage.net6.0.info
flag-name: win6
parallel: true

- name: Publish NuGet artifacts
uses: actions/upload-artifact@v3
with:
name: NuGet package
path: BitFaster.Caching/bin/Release/

mac:

Expand All @@ -66,20 +101,20 @@ jobs:
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-restore --verbosity normal /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov --logger "trx;LogFileName=results.trx"
run: dotnet test --no-restore --verbosity normal -f net6.0 /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov --logger "trx;LogFileName=results.trx"
- name: Publish coverage report to coveralls.io
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: BitFaster.Caching.UnitTests/TestResults/coverage.info
path-to-lcov: BitFaster.Caching.UnitTests/TestResults/coverage.net6.0.info
flag-name: mac
parallel: true
- name: Generate unit test report
uses: phoenix-actions/test-reporting@v8
id: unit-test-report-mac
if: success() || failure()
with:
name: test results (mac)
name: test results (mac net6.0)
path: BitFaster.Caching.UnitTests/TestResults/results.trx
reporter: dotnet-trx
only-summary: 'true'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net48;netcoreapp3.1;net6.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,6 +20,10 @@
</PackageReference>
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net48'">
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BitFaster.Caching\BitFaster.Caching.csproj" />
Expand Down
9 changes: 8 additions & 1 deletion BitFaster.Caching.UnitTests/Intrinsics.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#if NETCOREAPP3_1_OR_GREATER
using System.Runtime.Intrinsics.X86;
#endif
using Xunit;

namespace BitFaster.Caching.UnitTests
Expand All @@ -8,8 +9,14 @@ public static class Intrinsics
{
public static void SkipAvxIfNotSupported<I>()
{
#if NETCOREAPP3_1_OR_GREATER
// when we are trying to test Avx2, skip the test if it's not supported
Skip.If(typeof(I) == typeof(DetectIsa) && !Avx2.IsSupported);
#else
Skip.If(true);
#endif
}
}
}


10 changes: 5 additions & 5 deletions BitFaster.Caching.UnitTests/Lru/ConcurrentTLruTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task WhenItemIsExpiredItIsRemoved()
{
lru.GetOrAdd(1, valueFactory.Create);

await Task.Delay(timeToLive * ttlWaitMlutiplier);
await Task.Delay(timeToLive.MultiplyBy(ttlWaitMlutiplier));

lru.TryGet(1, out var value).Should().BeFalse();
}
Expand All @@ -68,7 +68,7 @@ public async Task WhenItemIsUpdatedTtlIsExtended()
{
lru.GetOrAdd(1, valueFactory.Create);

await Task.Delay(timeToLive * ttlWaitMlutiplier);
await Task.Delay(timeToLive.MultiplyBy(ttlWaitMlutiplier));

lru.TryUpdate(1, "3");

Expand Down Expand Up @@ -134,7 +134,7 @@ public async Task WhenItemsAreExpiredExpireRemovesExpiredItems()
lru.AddOrUpdate(8, "8");
lru.AddOrUpdate(9, "9");

await Task.Delay(timeToLive * ttlWaitMlutiplier);
await Task.Delay(timeToLive.MultiplyBy(ttlWaitMlutiplier));

lru.Policy.ExpireAfterWrite.Value.TrimExpired();

Expand All @@ -152,7 +152,7 @@ public async Task WhenCacheHasExpiredAndFreshItemsExpireRemovesOnlyExpiredItems(
lru.AddOrUpdate(5, "5");
lru.AddOrUpdate(6, "6");

await Task.Delay(timeToLive * ttlWaitMlutiplier);
await Task.Delay(timeToLive.MultiplyBy(ttlWaitMlutiplier));

lru.GetOrAdd(1, valueFactory.Create);
lru.GetOrAdd(2, valueFactory.Create);
Expand All @@ -170,7 +170,7 @@ public async Task WhenItemsAreExpiredTrimRemovesExpiredItems()
lru.AddOrUpdate(2, "2");
lru.AddOrUpdate(3, "3");

await Task.Delay(timeToLive * ttlWaitMlutiplier);
await Task.Delay(timeToLive.MultiplyBy(ttlWaitMlutiplier));

lru.Policy.Eviction.Value.Trim(1);

Expand Down
2 changes: 1 addition & 1 deletion BitFaster.Caching.UnitTests/Lru/FastConcurrentTLruTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task WhenItemsAreExpiredExpireRemovesExpiredItems()
lru.AddOrUpdate(2, "2");
lru.AddOrUpdate(3, "3");

await Task.Delay(ttl * 2);
await Task.Delay(ttl.MultiplyBy(2));

lru.Policy.ExpireAfterWrite.Value.TrimExpired();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using FluentAssertions;
#if NETCOREAPP3_1_OR_GREATER

using FluentAssertions;
using FluentAssertions.Extensions;
using BitFaster.Caching.Lru;
using System;
Expand Down Expand Up @@ -157,3 +159,5 @@ private LongTickCountLruItem<int, int> CreateItem(bool wasAccessed, bool isExpir
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BitFaster.Caching.Scheduler;
Expand Down Expand Up @@ -36,8 +33,8 @@ public async Task WhenWorkIsScheduledItIsRun()
{
bool run = false;

TaskCompletionSource tcs = new TaskCompletionSource();
scheduler.Run(() => { Volatile.Write(ref run, true); tcs.SetResult(); });
var tcs = new TaskCompletionSource<bool>();
scheduler.Run(() => { Volatile.Write(ref run, true); tcs.SetResult(true); });
await tcs.Task;

Volatile.Read(ref run).Should().BeTrue();
Expand All @@ -58,8 +55,8 @@ public async Task WhenWorkDoesNotThrowLastExceptionIsEmpty()
[Fact]
public async Task WhenWorkThrowsLastExceptionIsPopulated()
{
TaskCompletionSource tcs = new TaskCompletionSource();
scheduler.Run(() => { tcs.SetResult(); throw new InvalidCastException(); });
var tcs = new TaskCompletionSource<bool>();
scheduler.Run(() => { tcs.SetResult(true); throw new InvalidCastException(); });

await tcs.Task;
await scheduler.WaitForExceptionAsync();
Expand All @@ -71,14 +68,14 @@ public async Task WhenWorkThrowsLastExceptionIsPopulated()
[Fact]
public void WhenBacklogExceededTasksAreDropped()
{
TaskCompletionSource tcs = new TaskCompletionSource();
var tcs = new TaskCompletionSource<bool>();

for (int i = 0; i < BackgroundThreadScheduler.MaxBacklog * 2; i++)
{
scheduler.Run(() => { tcs.Task.Wait(); });
}

tcs.SetResult();
tcs.SetResult(true);

scheduler.RunCount.Should().BeCloseTo(BackgroundThreadScheduler.MaxBacklog, 1);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BitFaster.Caching.Scheduler;
Expand Down Expand Up @@ -30,8 +27,8 @@ public async Task WhenWorkIsScheduledItIsRun()
{
bool run = false;

TaskCompletionSource tcs = new TaskCompletionSource();
scheduler.Run(() => { Volatile.Write(ref run, true); tcs.SetResult(); });
var tcs = new TaskCompletionSource<bool>();
scheduler.Run(() => { Volatile.Write(ref run, true); tcs.SetResult(true); });

await tcs.Task;

Expand All @@ -41,10 +38,10 @@ public async Task WhenWorkIsScheduledItIsRun()
[Fact]
public async Task WhenWorkDoesNotThrowLastExceptionIsEmpty()
{
TaskCompletionSource tcs = new TaskCompletionSource();
var tcs = new TaskCompletionSource<bool>();
scheduler.RunCount.Should().Be(0);

scheduler.Run(() => { tcs.SetResult(); });
scheduler.Run(() => { tcs.SetResult(true); });

await tcs.Task;

Expand All @@ -54,9 +51,9 @@ public async Task WhenWorkDoesNotThrowLastExceptionIsEmpty()
[Fact]
public async Task WhenWorkThrowsLastExceptionIsPopulated()
{
TaskCompletionSource tcs = new TaskCompletionSource();
var tcs = new TaskCompletionSource<bool>();
scheduler.Run(() => { throw new InvalidCastException(); });
scheduler.Run(() => { tcs.SetResult(); });
scheduler.Run(() => { tcs.SetResult(true); });

await tcs.Task;
await scheduler.WaitForExceptionAsync();
Expand Down
13 changes: 13 additions & 0 deletions BitFaster.Caching.UnitTests/TimeSpanExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace BitFaster.Caching.UnitTests
{
internal static class TimeSpanExtensions
{
// .NET Framework has no TimeSpan operator*
public static TimeSpan MultiplyBy(this TimeSpan multiplicand, int multiplier)
{
return TimeSpan.FromTicks(multiplicand.Ticks * multiplier);
}
}
}