use Npgsql @CI
Some checks failed
Dotnet build and test / build (pull_request) Failing after 11s

This commit is contained in:
Paul Schneider 2026-11-09 21:20:26 +00:00
commit 47b2a1bd27
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
4 changed files with 220 additions and 132 deletions

View file

@ -26,6 +26,20 @@ on:
jobs: jobs:
build: build:
runs-on: docker runs-on: docker
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U postgres -d postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=5
container: container:
image: pazof/yavsc-build-env:debian13-dotnet10-android36-jdk21-v5 image: pazof/yavsc-build-env:debian13-dotnet10-android36-jdk21-v5
steps: steps:
@ -51,6 +65,9 @@ jobs:
echo "🏗️ Building the solution..." echo "🏗️ Building the solution..."
cd /src/_src && dotnet build --verbosity normal cd /src/_src && dotnet build --verbosity normal
- name: Test - name: Test
env:
YAVSC_API_TEST_DB_PROVIDER: npgsql
YAVSC_API_TEST_NPGSQL_ADMIN_CONNECTION: Host=postgres;Port=5432;Database=postgres;Username=postgres;Password=postgres;Include Error Detail=true
run: | run: |
echo "🚀 Lancement des tests..." echo "🚀 Lancement des tests..."
cd /src/_src && dotnet test \ cd /src/_src && dotnet test \

View file

@ -9,6 +9,20 @@ on:
jobs: jobs:
production-deploy: production-deploy:
runs-on: ubuntu-26.04 runs-on: ubuntu-26.04
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U postgres -d postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps: steps:
# 1. Récupération du code # 1. Récupération du code
- name: Check out the repo - name: Check out the repo
@ -33,6 +47,8 @@ jobs:
- name: Test - name: Test
env: env:
TEST_FAILED: "" TEST_FAILED: ""
YAVSC_API_TEST_DB_PROVIDER: npgsql
YAVSC_API_TEST_NPGSQL_ADMIN_CONNECTION: Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=postgres;Include Error Detail=true
run: make test || export TEST_FAILED=$? run: make test || export TEST_FAILED=$?
- uses: actions/upload-artifact@v7 - uses: actions/upload-artifact@v7
with: with:

View file

@ -34,6 +34,18 @@ public class AndroidAppLaunchTests
return; return;
} }
if (!HasAdb())
{
_output.WriteLine("[skip] adb not available on this machine");
return;
}
if (!HasConnectedDevice())
{
_output.WriteLine("[skip] no Android device/emulator connected via adb");
return;
}
if (!IsPackageInstalledOnAnyDevice()) if (!IsPackageInstalledOnAnyDevice())
{ {
_output.WriteLine($"[skip] {PackageName} not installed on any device"); _output.WriteLine($"[skip] {PackageName} not installed on any device");
@ -60,6 +72,68 @@ public class AndroidAppLaunchTests
|| Environment.GetEnvironmentVariable("CI_NAME") is { Length: > 0 }; || Environment.GetEnvironmentVariable("CI_NAME") is { Length: > 0 };
} }
private static bool HasAdb()
{
try
{
var startInfo = new ProcessStartInfo("adb", "version")
{
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
};
using var proc = Process.Start(startInfo);
if (proc is null) return false;
var _ = proc.StandardOutput.ReadToEnd();
var __ = proc.StandardError.ReadToEnd();
if (!proc.WaitForExit(2000))
{
proc.Kill(entireProcessTree: true);
return false;
}
return proc.ExitCode == 0;
}
catch
{
return false;
}
}
private static bool HasConnectedDevice()
{
try
{
var startInfo = new ProcessStartInfo("adb", "devices")
{
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
};
using var proc = Process.Start(startInfo);
if (proc is null) return false;
var stdout = proc.StandardOutput.ReadToEnd();
_ = proc.StandardError.ReadToEnd();
if (!proc.WaitForExit(2000))
{
proc.Kill(entireProcessTree: true);
return false;
}
return stdout
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
.Skip(1)
.Any(line => line.Contains("device", StringComparison.OrdinalIgnoreCase)
&& !line.Contains("offline", StringComparison.OrdinalIgnoreCase));
}
catch
{
return false;
}
}
private static bool IsPackageInstalledOnAnyDevice() private static bool IsPackageInstalledOnAnyDevice()
{ {
try try
@ -74,7 +148,13 @@ public class AndroidAppLaunchTests
using var proc = Process.Start(startInfo); using var proc = Process.Start(startInfo);
if (proc is null) return false; if (proc is null) return false;
var stdout = proc.StandardOutput.ReadToEnd(); var stdout = proc.StandardOutput.ReadToEnd();
proc.WaitForExit(5000); _ = proc.StandardError.ReadToEnd();
if (!proc.WaitForExit(5000))
{
proc.Kill(entireProcessTree: true);
return false;
}
return stdout return stdout
.Split('\n', StringSplitOptions.RemoveEmptyEntries) .Split('\n', StringSplitOptions.RemoveEmptyEntries)
.Any(line => line.Trim().Equals($"package:{PackageName}", StringComparison.Ordinal)); .Any(line => line.Trim().Equals($"package:{PackageName}", StringComparison.Ordinal));

View file

@ -35,6 +35,7 @@ public sealed class ApiWebServerFixture : WebHostFixture
private static SqliteConnection? _sharedSqliteConnection; private static SqliteConnection? _sharedSqliteConnection;
private static readonly object _sqliteLock = new(); private static readonly object _sqliteLock = new();
private static readonly object _resetLock = new();
private static readonly object _npgsqlLock = new(); private static readonly object _npgsqlLock = new();
private static string? _sharedNpgsqlConnectionString; private static string? _sharedNpgsqlConnectionString;
@ -238,6 +239,8 @@ public sealed class ApiWebServerFixture : WebHostFixture
} }
public void ResetAndSeedActivityGraph() public void ResetAndSeedActivityGraph()
{
lock (_resetLock)
{ {
Services.GetRequiredService<RecordingMessageDelivery>().Clear(); Services.GetRequiredService<RecordingMessageDelivery>().Clear();
using var scope = Services.CreateScope(); using var scope = Services.CreateScope();
@ -343,6 +346,7 @@ public sealed class ApiWebServerFixture : WebHostFixture
db.SaveChanges(); db.SaveChanges();
} }
}
private static void ResetDatabase(ApplicationDbContext db) private static void ResetDatabase(ApplicationDbContext db)
{ {
@ -473,48 +477,19 @@ public sealed class ApiWebServerFixture : WebHostFixture
Taints = new List<HairTaintInstance>(), Taints = new List<HairTaintInstance>(),
}; };
db.HairPrestation.AddRange(prestation1, prestation2); var prestation3 = new HairPrestation
db.SaveChanges();
db.HairCutQueries.Add(new HairCutQuery
{ {
ActivityCode = "brush", Gender = HairCutGenders.Man,
ClientId = "alice", Length = HairLength.Short,
PerformerId = "alice", Cut = true,
Consent = true, Shampoo = true,
UserCreated = "alice", Dressing = HairDressings.Brushing,
UserModified = "alice", Tech = HairTechnos.NoTech,
DateCreated = DateTime.UtcNow, Cares = false,
DateModified = DateTime.UtcNow, Taints = new List<HairTaintInstance>(),
EventDate = DateTime.UtcNow.AddDays(3), };
Location = location,
PrestationId = prestation1.Id,
Prestation = prestation1,
AdditionalInfo = "Coupe test",
Status = Yavsc.QueryStatus.Inserted,
Description = "Haircut seed",
});
db.HairMultiCutQueries.Add(new HairMultiCutQuery
{
ActivityCode = "mbrush",
ClientId = "alice",
PerformerId = "alice",
Consent = true,
UserCreated = "alice",
UserModified = "alice",
DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow,
EventDate = DateTime.UtcNow.AddDays(4),
Location = location,
Prestations = new List<HairPrestationCollectionItem>
{
new() { PrestationId = prestation1.Id, Prestation = prestation1 },
new() { PrestationId = prestation2.Id, Prestation = prestation2 },
},
Status = Yavsc.QueryStatus.Inserted,
});
db.HairPrestation.AddRange(prestation1, prestation2, prestation3);
db.SaveChanges(); db.SaveChanges();
} }