Skip to content

Commit 8622e13

Browse files
authored
Expand CI coverage across Windows and multi-target tests (#2702)
* Expand CI matrix with Windows multi-target tests * Fix build for linux and windows * Refactor CI workflow to unify build output packaging for Linux and Windows, and add test project build step for target frameworks. * Disabling windows build for now
1 parent a540b2a commit 8622e13

File tree

12 files changed

+360
-101
lines changed

12 files changed

+360
-101
lines changed

.github/workflows/ci.yml

Lines changed: 182 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ on:
44
pull_request:
55

66
jobs:
7-
build:
7+
build-linux:
8+
name: Build (Linux)
89
runs-on: ubuntu-latest
910

1011
steps:
@@ -24,13 +25,190 @@ jobs:
2425
- name: Build
2526
run: dotnet build LiteDB.sln --configuration Release --no-restore /p:DefineConstants=TESTING
2627

27-
- name: Test
28+
- name: Package build outputs
29+
run: tar -czf tests-build-linux.tar.gz LiteDB/bin/Release LiteDB/obj/Release LiteDB.Tests/bin/Release LiteDB.Tests/obj/Release
30+
31+
- name: Upload linux test build
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: tests-build-linux
35+
path: tests-build-linux.tar.gz
36+
37+
# build-windows:
38+
# name: Build (Windows)
39+
# runs-on: windows-latest
40+
41+
# steps:
42+
# - name: Check out repository
43+
# uses: actions/checkout@v4
44+
# with:
45+
# fetch-depth: 0
46+
47+
# - name: Set up .NET SDK
48+
# uses: actions/setup-dotnet@v4
49+
# with:
50+
# dotnet-version: 8.0.x
51+
52+
# - name: Restore
53+
# run: dotnet restore LiteDB.sln
54+
55+
# - name: Build
56+
# run: dotnet build LiteDB.sln --configuration Release --no-restore /p:DefineConstants=TESTING
57+
58+
# - name: Package build outputs
59+
# shell: pwsh
60+
# run: Compress-Archive -Path "LiteDB\bin\Release","LiteDB\obj\Release","LiteDB.Tests\bin\Release","LiteDB.Tests\obj\Release" -DestinationPath tests-build-windows.zip
61+
62+
# - name: Upload windows test build
63+
# uses: actions/upload-artifact@v4
64+
# with:
65+
# name: tests-build-windows
66+
# path: tests-build-windows.zip
67+
68+
test-linux:
69+
name: Test (Linux ${{ matrix.display }})
70+
runs-on: ubuntu-latest
71+
needs: build-linux
72+
strategy:
73+
fail-fast: false
74+
matrix:
75+
include:
76+
- display: .NET 8
77+
sdk: |
78+
8.0.x
79+
framework: net8.0
80+
include-prerelease: false
81+
- display: .NET 9
82+
sdk: |
83+
9.0.x
84+
8.0.x
85+
framework: net8.0
86+
include-prerelease: true
87+
- display: .NET 10
88+
sdk: |
89+
10.0.x
90+
8.0.x
91+
framework: net8.0
92+
include-prerelease: true
93+
94+
steps:
95+
- name: Check out repository
96+
uses: actions/checkout@v4
97+
with:
98+
fetch-depth: 0
99+
100+
- name: Set up .NET SDK ${{ matrix.display }}
101+
uses: actions/setup-dotnet@v4
102+
with:
103+
dotnet-version: ${{ matrix.sdk }}
104+
include-prerelease: ${{ matrix.include-prerelease }}
105+
106+
- name: Download build artifacts
107+
uses: actions/download-artifact@v4
108+
with:
109+
name: tests-build-linux
110+
111+
- name: Extract build artifacts
112+
run: tar -xzf tests-build-linux.tar.gz
113+
114+
- name: Build test project for target framework
115+
run: >-
116+
dotnet build LiteDB.Tests/LiteDB.Tests.csproj
117+
--configuration Release
118+
--framework ${{ matrix.framework }}
119+
--no-dependencies
120+
121+
- name: Run tests
28122
timeout-minutes: 5
29-
run: dotnet test LiteDB.sln --configuration Release --no-build --verbosity normal --settings tests.runsettings --logger "trx;LogFileName=TestResults.trx" --logger "console;verbosity=detailed" /p:DefineConstants=TESTING
123+
run: >-
124+
dotnet test LiteDB.Tests/LiteDB.Tests.csproj
125+
--configuration Release
126+
--no-build
127+
--framework ${{ matrix.framework }}
128+
--verbosity normal
129+
--settings tests.runsettings
130+
--logger "trx;LogFileName=TestResults.trx"
131+
--logger "console;verbosity=detailed"
132+
133+
# test-windows:
134+
# name: Test (Windows ${{ matrix.display }})
135+
# runs-on: windows-latest
136+
# needs: build-windows
137+
# strategy:
138+
# fail-fast: false
139+
# matrix:
140+
# include:
141+
# - display: .NET Framework 4.6.1
142+
# sdk: |
143+
# 8.0.x
144+
# framework: net461
145+
# include-prerelease: false
146+
# - display: .NET Framework 4.8.1
147+
# sdk: |
148+
# 8.0.x
149+
# framework: net481
150+
# include-prerelease: false
151+
# - display: .NET 8
152+
# sdk: |
153+
# 8.0.x
154+
# framework: net8.0
155+
# include-prerelease: false
156+
# - display: .NET 9
157+
# sdk: |
158+
# 9.0.x
159+
# 8.0.x
160+
# framework: net8.0
161+
# include-prerelease: true
162+
# - display: .NET 10
163+
# sdk: |
164+
# 10.0.x
165+
# 8.0.x
166+
# framework: net8.0
167+
# include-prerelease: true
168+
169+
# steps:
170+
# - name: Check out repository
171+
# uses: actions/checkout@v4
172+
# with:
173+
# fetch-depth: 0
174+
175+
# - name: Set up .NET SDK ${{ matrix.display }}
176+
# uses: actions/setup-dotnet@v4
177+
# with:
178+
# dotnet-version: ${{ matrix.sdk }}
179+
# include-prerelease: ${{ matrix.include-prerelease }}
180+
181+
# - name: Download build artifacts
182+
# uses: actions/download-artifact@v4
183+
# with:
184+
# name: tests-build-windows
185+
186+
# - name: Extract build artifacts
187+
# shell: pwsh
188+
# run: Expand-Archive -Path tests-build-windows.zip -DestinationPath . -Force
189+
190+
# - name: Build test project for target framework
191+
# run: >-
192+
# dotnet build LiteDB.Tests/LiteDB.Tests.csproj
193+
# --configuration Release
194+
# --framework ${{ matrix.framework }}
195+
# --no-dependencies
196+
197+
# - name: Run tests
198+
# timeout-minutes: 10
199+
# run: >-
200+
# dotnet test LiteDB.Tests/LiteDB.Tests.csproj
201+
# --configuration Release
202+
# --no-build
203+
# --framework ${{ matrix.framework }}
204+
# --verbosity normal
205+
# --settings tests.runsettings
206+
# --logger "trx;LogFileName=TestResults.trx"
207+
# --logger "console;verbosity=detailed"
30208

31209
repro-runner:
32210
runs-on: ubuntu-latest
33-
needs: build
211+
needs: build-linux
34212

35213
steps:
36214
- name: Check out repository
@@ -55,11 +233,9 @@ jobs:
55233
- name: Validate manifests
56234
run: dotnet run --project LiteDB.ReproRunner/LiteDB.ReproRunner.Cli -- validate
57235

58-
# Execute every repro and emit a JSON summary that downstream automation can inspect.
59236
- name: Run repro suite
60237
run: dotnet run --project LiteDB.ReproRunner/LiteDB.ReproRunner.Cli -- run --all --report repro-summary.json
61238

62-
# Publish the summary so other jobs or manual reviewers can review the latest outcomes.
63239
- name: Upload repro summary
64240
uses: actions/upload-artifact@v4
65241
with:

LiteDB.Tests/Database/Upgrade_Tests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using LiteDB.Tests.Utils;
66
using FluentAssertions;
77
using Xunit;
8-
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel;
9-
108
namespace LiteDB.Tests.Database
119
{
1210
public class Upgrade_Tests

LiteDB.Tests/Engine/Rebuild_Tests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ private static IEnumerable<Zip> CreateSyntheticZipData(int totalCount, string su
116116
}
117117

118118
var payload = new byte[payloadLength];
119-
Array.Fill(payload, (byte)(i % 256));
119+
for (var j = 0; j < payload.Length; j++)
120+
{
121+
payload[j] = (byte)(i % 256);
122+
}
120123

121124
yield return new Zip
122125
{

LiteDB.Tests/Engine/Transactions_Tests.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public void Transaction_Rollback_Should_Skip_ReadOnly_Buffers_From_Safepoint()
252252
}
253253

254254
var engine = GetLiteEngine(db);
255-
var monitor = engine.GetMonitor();
255+
var monitor = GetTransactionMonitor(engine);
256256
var transaction = monitor.GetThreadTransaction();
257257

258258
transaction.Should().NotBeNull();
@@ -314,7 +314,7 @@ public void Transaction_Rollback_Should_Discard_Writable_Dirty_Pages()
314314
}
315315

316316
var engine = GetLiteEngine(db);
317-
var monitor = engine.GetMonitor();
317+
var monitor = GetTransactionMonitor(engine);
318318
var transaction = monitor.GetThreadTransaction();
319319

320320
transaction.Should().NotBeNull();
@@ -399,6 +399,26 @@ private static LiteEngine GetLiteEngine(LiteDatabase database)
399399
return engine;
400400
}
401401

402+
private static TransactionMonitor GetTransactionMonitor(LiteEngine engine)
403+
{
404+
var getter = typeof(LiteEngine).GetMethod("GetMonitor", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
405+
406+
if (getter != null && getter.ReturnType == typeof(TransactionMonitor))
407+
{
408+
return (TransactionMonitor)(getter.Invoke(engine, Array.Empty<object>()) ?? throw new InvalidOperationException("LiteEngine monitor accessor returned null."));
409+
}
410+
411+
var monitorField = typeof(LiteEngine).GetField("_monitor", BindingFlags.Instance | BindingFlags.NonPublic)
412+
?? throw new InvalidOperationException("Unable to locate LiteEngine monitor field.");
413+
414+
if (monitorField.GetValue(engine) is not TransactionMonitor monitor)
415+
{
416+
throw new InvalidOperationException("LiteEngine monitor instance is not available.");
417+
}
418+
419+
return monitor;
420+
}
421+
402422
private static void SetMonitorFreePages(TransactionMonitor monitor, int value)
403423
{
404424
var freePagesField = typeof(TransactionMonitor).GetField("_freePages", BindingFlags.Instance | BindingFlags.NonPublic)

LiteDB.Tests/Issues/Issue2127_Tests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ public void InsertItemBackToBack_Test()
5454
var liteDbContent = File.ReadAllText(copiedLiteDbPath, Encoding.UTF8);
5555
liteDbContent += File.ReadAllText(copiedLiteDbLogPath, Encoding.UTF8);
5656

57-
Assert.True(liteDbContent.Contains(item1.SomeProperty, StringComparison.OrdinalIgnoreCase), $"Could not find item 1 property. {item1.SomeProperty}, Iteration: {i}");
58-
Assert.True(liteDbContent.Contains(item2.SomeProperty, StringComparison.OrdinalIgnoreCase), $"Could not find item 2 property. {item2.SomeProperty}, Iteration: {i}");
57+
Assert.True(
58+
liteDbContent.IndexOf(item1.SomeProperty, StringComparison.OrdinalIgnoreCase) >= 0,
59+
$"Could not find item 1 property. {item1.SomeProperty}, Iteration: {i}");
60+
Assert.True(
61+
liteDbContent.IndexOf(item2.SomeProperty, StringComparison.OrdinalIgnoreCase) >= 0,
62+
$"Could not find item 2 property. {item2.SomeProperty}, Iteration: {i}");
5963
}
6064
}
6165
}

LiteDB.Tests/Issues/Issue2298_Tests.cs

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,58 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5+
#if NETCOREAPP
56
using System.Text.Json;
7+
#endif
68
using System.Threading.Tasks;
79

810
using LiteDB.Tests.Utils;
911
using Xunit;
1012

11-
namespace LiteDB.Tests.Issues;
12-
13-
public class Issue2298_Tests
13+
namespace LiteDB.Tests.Issues
1414
{
15-
public struct Mass
15+
public class Issue2298_Tests
1616
{
17-
public enum Units
18-
{ Pound, Kilogram }
17+
#if !NETCOREAPP
18+
[Fact(Skip = "System.Text.Json is not supported on this target framework for this scenario.")]
19+
public void We_Dont_Need_Ctor()
20+
{
21+
}
22+
#else
23+
public struct Mass
24+
{
25+
public enum Units
26+
{ Pound, Kilogram }
1927

20-
public Mass(double value, Units unit)
21-
{ Value = value; Unit = unit; }
28+
public Mass(double value, Units unit)
29+
{ Value = value; Unit = unit; }
2230

23-
public double Value { get; init; }
24-
public Units Unit { get; init; }
25-
}
31+
public double Value { get; init; }
32+
public Units Unit { get; init; }
33+
}
2634

27-
public class QuantityRange<T>
28-
{
29-
public QuantityRange(double min, double max, Enum unit)
30-
{ Min = min; Max = max; Unit = unit; }
35+
public class QuantityRange<T>
36+
{
37+
public QuantityRange(double min, double max, Enum unit)
38+
{ Min = min; Max = max; Unit = unit; }
3139

32-
public double Min { get; init; }
33-
public double Max { get; init; }
34-
public Enum Unit { get; init; }
35-
}
40+
public double Min { get; init; }
41+
public double Max { get; init; }
42+
public Enum Unit { get; init; }
43+
}
3644

37-
public static QuantityRange<Mass> MassRangeBuilder(BsonDocument document)
38-
{
39-
var doc = JsonDocument.Parse(document.ToString()).RootElement;
40-
var min = doc.GetProperty(nameof(QuantityRange<Mass>.Min)).GetDouble();
41-
var max = doc.GetProperty(nameof(QuantityRange<Mass>.Max)).GetDouble();
42-
var unit = Enum.Parse<Mass.Units>(doc.GetProperty(nameof(QuantityRange<Mass>.Unit)).GetString());
45+
public static QuantityRange<Mass> MassRangeBuilder(BsonDocument document)
46+
{
47+
var doc = JsonDocument.Parse(document.ToString()).RootElement;
48+
var min = doc.GetProperty(nameof(QuantityRange<Mass>.Min)).GetDouble();
49+
var max = doc.GetProperty(nameof(QuantityRange<Mass>.Max)).GetDouble();
50+
var unit = Enum.Parse<Mass.Units>(doc.GetProperty(nameof(QuantityRange<Mass>.Unit)).GetString());
4351

44-
var restored = new QuantityRange<Mass>(min, max, unit);
45-
return restored;
46-
}
52+
var restored = new QuantityRange<Mass>(min, max, unit);
53+
return restored;
54+
}
4755

48-
[Fact]
56+
[Fact]
4957
public void We_Dont_Need_Ctor()
5058
{
5159
BsonMapper.Global.RegisterType<QuantityRange<Mass>>(
@@ -64,4 +72,7 @@ public void We_Dont_Need_Ctor()
6472
collection.Insert(range);
6573
var restored = collection.FindAll().First();
6674
}
67-
}
75+
76+
#endif
77+
}
78+
}

0 commit comments

Comments
 (0)