fix: Uhrzeit-Wraparound-Flakiness in MissingTeachingTime-Tests
CI / build-and-test (push) Canceled after 0s
CI / build-and-test (push) Canceled after 0s
TimeOnly.FromDateTime(DateTime.Now).AddHours(+-2) wickelt bei Mitternacht um (TimeOnly hat keinen Datumsanteil) - je nach Ausfuehrungsuhrzeit (ca. 22:00-02:00) landete "+2 Stunden" zeitlich vor statt nach "jetzt" oder umgekehrt, wodurch zwei Tests zufaellig rot wurden statt das eigentliche Verhalten (Wartezeit nach Unterrichtsende) zu pruefen. Per Gegenprobe auf unveraendertem main bestaetigt: dieselbe Flakiness besteht dort bereits. DashboardViewModel erhaelt einen optionalen Func<DateTime>? now-Konstruktorparameter (Default DateTime.Now, gleiches Muster wie die bereits bestehenden optionalen annualPlanEvents/ schoolWeather-Parameter) und nutzt ihn statt direkter DateTime.Now-Aufrufe in Load() und LoadMissingTeachingTime. Die beiden betroffenen Tests injizieren jetzt einen festen Referenzzeitpunkt (ein Feiertags-freier Dienstag im September) und sind damit unabhaengig von der tatsaechlichen Ausfuehrungsuhrzeit deterministisch gruen. Details siehe TODO.md, Abschnitt 9 (Dashboard).
This commit is contained in:
@@ -40,6 +40,7 @@ public partial class DashboardViewModel : ObservableObject
|
||||
private readonly SchoolWeatherService? _schoolWeather;
|
||||
private readonly UntisHubService _untisHub;
|
||||
private readonly WebUntisIntegrationService _webUntis;
|
||||
private readonly Func<DateTime> _now;
|
||||
|
||||
private const int OpenExcuseMaxAgeDays = 21;
|
||||
private const int SupportPlanDueWithinDays = 14;
|
||||
@@ -178,7 +179,8 @@ public partial class DashboardViewModel : ObservableObject
|
||||
ISubstitutionEntryRepository substitutions, ITimeEntryRepository timeEntries,
|
||||
UntisHubService untisHub, WebUntisIntegrationService webUntis,
|
||||
IAnnualPlanEventRepository? annualPlanEvents = null,
|
||||
AnnualPlanSyncService? annualPlanSync = null, SchoolWeatherService? schoolWeather = null)
|
||||
AnnualPlanSyncService? annualPlanSync = null, SchoolWeatherService? schoolWeather = null,
|
||||
Func<DateTime>? now = null)
|
||||
{
|
||||
_groups = groups; _subjects = subjects; _lessons = lessons; _exams = exams; _tasks = tasks;
|
||||
_examResults = examResults; _grades = grades; _reportGrades = reportGrades; _memberships = memberships;
|
||||
@@ -193,6 +195,11 @@ public partial class DashboardViewModel : ObservableObject
|
||||
_schoolWeather = schoolWeather;
|
||||
_untisHub = untisHub;
|
||||
_webUntis = webUntis;
|
||||
// Testbare Uhr statt direkter DateTime.Now-Aufrufe (siehe Load()/LoadMissingTeachingTime):
|
||||
// TimeOnly.AddHours()/AddMinutes() wickelt bei Mitternacht um, ohne injizierbares "jetzt"
|
||||
// waeren Tests fuer "kurz vor/nach Ablauf einer Wartezeit" je nach Ausfuehrungsuhrzeit
|
||||
// zufaellig rot oder gruen (siehe TODO.md, Abschnitt 9, Nachtrag Uhrzeit-Wraparound).
|
||||
_now = now ?? (() => DateTime.Now);
|
||||
if (annualPlanSync is not null)
|
||||
{
|
||||
annualPlanSync.DataChanged += () => Avalonia.Threading.Dispatcher.UIThread.Post(LoadCalendar);
|
||||
@@ -222,7 +229,7 @@ public partial class DashboardViewModel : ObservableObject
|
||||
|
||||
private void Load()
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
var now = _now();
|
||||
var today = DateOnly.FromDateTime(now);
|
||||
CurrentDate = now.ToString("dddd, d. MMMM yyyy", De);
|
||||
CurrentSchoolYear = _sy.CurrentSchoolYear();
|
||||
@@ -433,7 +440,7 @@ public partial class DashboardViewModel : ObservableObject
|
||||
.SelectMany(y => _publicHolidays.GetHolidays(y, _calendarSettings.State))
|
||||
.Select(h => h.Date).ToHashSet();
|
||||
var schoolHolidays = _schoolHolidays.GetAll();
|
||||
var nowTime = TimeOnly.FromDateTime(DateTime.Now);
|
||||
var nowTime = TimeOnly.FromDateTime(_now());
|
||||
|
||||
var items = new List<MissingTeachingTimeItem>();
|
||||
for (var date = firstDay; date <= today; date = date.AddDays(1))
|
||||
|
||||
Reference in New Issue
Block a user