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;
@ -239,109 +240,112 @@ public sealed class ApiWebServerFixture : WebHostFixture
public void ResetAndSeedActivityGraph() public void ResetAndSeedActivityGraph()
{ {
Services.GetRequiredService<RecordingMessageDelivery>().Clear(); lock (_resetLock)
using var scope = Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
ResetDatabase(db);
db.Database.EnsureCreated();
var user = new ApplicationUser
{ {
Id = "alice", Services.GetRequiredService<RecordingMessageDelivery>().Clear();
UserName = "alice", using var scope = Services.CreateScope();
Email = "alice@example.test", var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
EmailConfirmed = true,
FullName = "Alice",
};
db.Users.Add(user);
var location = new Location ResetDatabase(db);
{ db.Database.EnsureCreated();
Address = "1 rue du Test",
Latitude = 48.8566,
Longitude = 2.3522,
};
db.Add(location);
db.SaveChanges();
var activity = new Activity var user = new ApplicationUser
{ {
Code = "dev", Id = "alice",
Name = "Dev", UserName = "alice",
Hidden = false, Email = "alice@example.test",
DateCreated = DateTime.UtcNow, EmailConfirmed = true,
DateModified = DateTime.UtcNow, FullName = "Alice",
}; };
db.Activities.Add(activity); db.Users.Add(user);
db.Activities.Add(new Activity var location = new Location
{ {
Code = "ghost", Address = "1 rue du Test",
Name = "Ghost", Latitude = 48.8566,
Hidden = false, Longitude = 2.3522,
DateCreated = DateTime.UtcNow, };
DateModified = DateTime.UtcNow, db.Add(location);
}); db.SaveChanges();
var performer = new PerformerProfile var activity = new Activity
{ {
PerformerId = "alice", Code = "dev",
SIREN = "123456789", Name = "Dev",
OrganizationAddressId = location.Id, Hidden = false,
AcceptNotifications = true, DateCreated = DateTime.UtcNow,
AcceptPublicContact = true, DateModified = DateTime.UtcNow,
Active = true, };
Rate = 5, db.Activities.Add(activity);
WebSite = "https://alice.dev",
};
db.Performers.Add(performer);
db.UserActivities.Add(new UserActivity db.Activities.Add(new Activity
{ {
UserId = "alice", Code = "ghost",
DoesCode = "dev", Name = "Ghost",
Weight = 100, Hidden = false,
}); DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow,
});
db.Users.Add(new ApplicationUser var performer = new PerformerProfile
{ {
Id = "bob", PerformerId = "alice",
UserName = "bob", SIREN = "123456789",
Email = "bob@example.test", OrganizationAddressId = location.Id,
EmailConfirmed = true, AcceptNotifications = true,
FullName = "Bob", AcceptPublicContact = true,
}); Active = true,
Rate = 5,
WebSite = "https://alice.dev",
};
db.Performers.Add(performer);
db.Activities.Add(new Activity db.UserActivities.Add(new UserActivity
{ {
Code = "declared-only", UserId = "alice",
Name = "Declared Only", DoesCode = "dev",
Hidden = false, Weight = 100,
DateCreated = DateTime.UtcNow, });
DateModified = DateTime.UtcNow,
});
db.Performers.Add(new PerformerProfile db.Users.Add(new ApplicationUser
{ {
PerformerId = "bob", Id = "bob",
SIREN = "987654321", UserName = "bob",
OrganizationAddressId = location.Id, Email = "bob@example.test",
AcceptNotifications = false, EmailConfirmed = true,
AcceptPublicContact = false, FullName = "Bob",
Active = false, });
Rate = 0,
WebSite = "",
});
db.UserActivities.Add(new UserActivity db.Activities.Add(new Activity
{ {
UserId = "bob", Code = "declared-only",
DoesCode = "declared-only", Name = "Declared Only",
Weight = 10, Hidden = false,
}); DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow,
});
db.SaveChanges(); db.Performers.Add(new PerformerProfile
{
PerformerId = "bob",
SIREN = "987654321",
OrganizationAddressId = location.Id,
AcceptNotifications = false,
AcceptPublicContact = false,
Active = false,
Rate = 0,
WebSite = "",
});
db.UserActivities.Add(new UserActivity
{
UserId = "bob",
DoesCode = "declared-only",
Weight = 10,
});
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();
} }