From 784cb47ceb905abacc3a9bd66d5818fb88ea95a4 Mon Sep 17 00:00:00 2001 From: Rory& Date: Tue, 3 Jun 2025 21:28:05 +0200 Subject: testFrontend: add activity for almost all endpoints --- testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs') diff --git a/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs b/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs index 7835f89..a2e133f 100644 --- a/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs +++ b/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs @@ -1,20 +1,23 @@ namespace SafeNSound.FakeUser; -public class RandomAlarmService(UserStore userStore): IHostedService { +public class RandomAlarmService(UserStore userStore) : IHostedService { private Task? _listenerTask; private readonly CancellationTokenSource _cts = new(); - + public async Task StartAsync(CancellationToken cancellationToken) { _listenerTask = Run(_cts.Token); } + private static readonly string[] validReasons = ["fall", "toilet"]; + private async Task Run(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { try { var user = userStore.GetRandomUser(); - if (Random.Shared.Next(100) > 90) { + var currentAlarm = await user.Client!.GetAlarm(); + if (currentAlarm is null) { await user.Client!.SetAlarm(new Sdk.AlarmDto { - Reason = "fall" + Reason = Random.Shared.GetItems(validReasons, 1).First() }); } else { @@ -25,7 +28,7 @@ public class RandomAlarmService(UserStore userStore): IHostedService { Console.WriteLine($"Error setting/deleting alarm: {ex.Message}"); } - await Task.Delay(TimeSpan.FromMilliseconds(100), cancellationToken); + await Task.Delay(TimeSpan.FromMilliseconds(250), cancellationToken); } } -- cgit 1.5.1