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:
build:
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:
image: pazof/yavsc-build-env:debian13-dotnet10-android36-jdk21-v5
steps:
@ -51,6 +65,9 @@ jobs:
echo "🏗️ Building the solution..."
cd /src/_src && dotnet build --verbosity normal
- 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: |
echo "🚀 Lancement des tests..."
cd /src/_src && dotnet test \

View file

@ -9,6 +9,20 @@ on:
jobs:
production-deploy:
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:
# 1. Récupération du code
- name: Check out the repo
@ -33,6 +47,8 @@ jobs:
- name: Test
env:
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=$?
- uses: actions/upload-artifact@v7
with:

View file

@ -34,6 +34,18 @@ public class AndroidAppLaunchTests
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())
{
_output.WriteLine($"[skip] {PackageName} not installed on any device");
@ -60,6 +72,68 @@ public class AndroidAppLaunchTests
|| 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()
{
try
@ -74,7 +148,13 @@ public class AndroidAppLaunchTests
using var proc = Process.Start(startInfo);
if (proc is null) return false;
var stdout = proc.StandardOutput.ReadToEnd();
proc.WaitForExit(5000);
_ = proc.StandardError.ReadToEnd();
if (!proc.WaitForExit(5000))
{
proc.Kill(entireProcessTree: true);
return false;
}
return stdout
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
.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 readonly object _sqliteLock = new();
private static readonly object _resetLock = new();
private static readonly object _npgsqlLock = new();
private static string? _sharedNpgsqlConnectionString;
@ -239,109 +240,112 @@ public sealed class ApiWebServerFixture : WebHostFixture
public void ResetAndSeedActivityGraph()
{
Services.GetRequiredService<RecordingMessageDelivery>().Clear();
using var scope = Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
ResetDatabase(db);
db.Database.EnsureCreated();
var user = new ApplicationUser
lock (_resetLock)
{
Id = "alice",
UserName = "alice",
Email = "alice@example.test",
EmailConfirmed = true,
FullName = "Alice",
};
db.Users.Add(user);
Services.GetRequiredService<RecordingMessageDelivery>().Clear();
using var scope = Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
var location = new Location
{
Address = "1 rue du Test",
Latitude = 48.8566,
Longitude = 2.3522,
};
db.Add(location);
db.SaveChanges();
ResetDatabase(db);
db.Database.EnsureCreated();
var activity = new Activity
{
Code = "dev",
Name = "Dev",
Hidden = false,
DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow,
};
db.Activities.Add(activity);
var user = new ApplicationUser
{
Id = "alice",
UserName = "alice",
Email = "alice@example.test",
EmailConfirmed = true,
FullName = "Alice",
};
db.Users.Add(user);
db.Activities.Add(new Activity
{
Code = "ghost",
Name = "Ghost",
Hidden = false,
DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow,
});
var location = new Location
{
Address = "1 rue du Test",
Latitude = 48.8566,
Longitude = 2.3522,
};
db.Add(location);
db.SaveChanges();
var performer = new PerformerProfile
{
PerformerId = "alice",
SIREN = "123456789",
OrganizationAddressId = location.Id,
AcceptNotifications = true,
AcceptPublicContact = true,
Active = true,
Rate = 5,
WebSite = "https://alice.dev",
};
db.Performers.Add(performer);
var activity = new Activity
{
Code = "dev",
Name = "Dev",
Hidden = false,
DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow,
};
db.Activities.Add(activity);
db.UserActivities.Add(new UserActivity
{
UserId = "alice",
DoesCode = "dev",
Weight = 100,
});
db.Activities.Add(new Activity
{
Code = "ghost",
Name = "Ghost",
Hidden = false,
DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow,
});
db.Users.Add(new ApplicationUser
{
Id = "bob",
UserName = "bob",
Email = "bob@example.test",
EmailConfirmed = true,
FullName = "Bob",
});
var performer = new PerformerProfile
{
PerformerId = "alice",
SIREN = "123456789",
OrganizationAddressId = location.Id,
AcceptNotifications = true,
AcceptPublicContact = true,
Active = true,
Rate = 5,
WebSite = "https://alice.dev",
};
db.Performers.Add(performer);
db.Activities.Add(new Activity
{
Code = "declared-only",
Name = "Declared Only",
Hidden = false,
DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow,
});
db.UserActivities.Add(new UserActivity
{
UserId = "alice",
DoesCode = "dev",
Weight = 100,
});
db.Performers.Add(new PerformerProfile
{
PerformerId = "bob",
SIREN = "987654321",
OrganizationAddressId = location.Id,
AcceptNotifications = false,
AcceptPublicContact = false,
Active = false,
Rate = 0,
WebSite = "",
});
db.Users.Add(new ApplicationUser
{
Id = "bob",
UserName = "bob",
Email = "bob@example.test",
EmailConfirmed = true,
FullName = "Bob",
});
db.UserActivities.Add(new UserActivity
{
UserId = "bob",
DoesCode = "declared-only",
Weight = 10,
});
db.Activities.Add(new Activity
{
Code = "declared-only",
Name = "Declared Only",
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)
@ -473,48 +477,19 @@ public sealed class ApiWebServerFixture : WebHostFixture
Taints = new List<HairTaintInstance>(),
};
db.HairPrestation.AddRange(prestation1, prestation2);
db.SaveChanges();
db.HairCutQueries.Add(new HairCutQuery
var prestation3 = new HairPrestation
{
ActivityCode = "brush",
ClientId = "alice",
PerformerId = "alice",
Consent = true,
UserCreated = "alice",
UserModified = "alice",
DateCreated = DateTime.UtcNow,
DateModified = DateTime.UtcNow,
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,
});
Gender = HairCutGenders.Man,
Length = HairLength.Short,
Cut = true,
Shampoo = true,
Dressing = HairDressings.Brushing,
Tech = HairTechnos.NoTech,
Cares = false,
Taints = new List<HairTaintInstance>(),
};
db.HairPrestation.AddRange(prestation1, prestation2, prestation3);
db.SaveChanges();
}