1 files changed, 8 insertions, 5 deletions
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);
}
}
|