|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Text; |
| 4 | +using Akka.Actor; |
| 5 | +using Akka.Cluster.HealthCheck; |
| 6 | +using Akka.HealthCheck; |
| 7 | +using Akka.HealthCheck.Liveness; |
| 8 | +using Akka.HealthCheck.Readiness; |
| 9 | +using Akka.TestKit.Xunit2; |
| 10 | +using FluentAssertions; |
| 11 | +using Xunit; |
| 12 | +using Xunit.Abstractions; |
| 13 | + |
| 14 | +namespace WebCrawler.Shared.DevOps.Tests |
| 15 | +{ |
| 16 | + public class ActorSystemStartupSpecs : TestKit |
| 17 | + { |
| 18 | + public ActorSystemStartupSpecs(ITestOutputHelper helper) |
| 19 | + : base(Akka.Configuration.Config.Empty.ApplyOpsConfig(), output: helper) { } |
| 20 | + |
| 21 | + [Fact(DisplayName = "Instrumented ActorSystem should start HealthChecks automatically")] |
| 22 | + public void ActorSystem_should_start_HealthChecks_automatically() |
| 23 | + { |
| 24 | + /* |
| 25 | + * Without explicitly invoking the AkkaHealthCheck extension, we should see |
| 26 | + * that the actors responsible for publishing that information have already |
| 27 | + * started and begun broadcasting readiness / liveness status in the background |
| 28 | + * since we enable the extension via the `akka.extensions` HOCON |
| 29 | + */ |
| 30 | + |
| 31 | + // Liveness |
| 32 | + AwaitAssert(() => |
| 33 | + { |
| 34 | + Sys.ActorSelection("/system/healthcheck-live").Tell(GetCurrentLiveness.Instance); |
| 35 | + ExpectMsg<LivenessStatus>(TimeSpan.FromMilliseconds(30)); |
| 36 | + }, TimeSpan.FromSeconds(3), TimeSpan.FromMilliseconds(40)); |
| 37 | + |
| 38 | + // Readiness |
| 39 | + AwaitAssert(() => |
| 40 | + { |
| 41 | + Sys.ActorSelection("/system/healthcheck-readiness").Tell(GetCurrentReadiness.Instance); |
| 42 | + ExpectMsg<ReadinessStatus>(TimeSpan.FromMilliseconds(30)); |
| 43 | + }, TimeSpan.FromSeconds(3), TimeSpan.FromMilliseconds(40)); |
| 44 | + |
| 45 | + // should be running with the Akka.Cluster healthcheck probe |
| 46 | + //AkkaHealthCheck.For(Sys).ReadinessProvider.Should().BeOfType<ClusterReadinessProbeProvider>(); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments