Windows 0.3.0 clean next-generation source delta; no private history or other platform changes
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal static class TailnetReadinessSelfTest
|
||||
{
|
||||
internal static int Run()
|
||||
{
|
||||
var checks = new Dictionary<string, bool>();
|
||||
var policy = new TailnetReadinessPolicy();
|
||||
var current = new TailnetReadinessPolicy.Context(1, 10, true, false, true, false, true);
|
||||
bool Begin(long now, out TailnetReadinessPolicy.ProbeTicket ticket) => policy.TryBegin(current, now, out ticket);
|
||||
TailnetReadinessPolicy.Result Complete(TailnetReadinessPolicy.ProbeTicket ticket, long now, bool reachable)
|
||||
=> policy.Observe(ticket, current, now, reachable);
|
||||
checks["public_authorized_session_can_probe_without_physical_network_change"] = Begin(0, out var first);
|
||||
checks["no_concurrent_readiness_probe"] = !Begin(0, out _);
|
||||
checks["one_tcp_success_is_not_stable_readiness"] = Complete(first, 100, true) == TailnetReadinessPolicy.Result.Confirming && !policy.IsReady;
|
||||
var second = default(TailnetReadinessPolicy.ProbeTicket);
|
||||
checks["monotonic_thirty_second_cadence"] = !Begin(30_099, out _) && Begin(30_100, out second);
|
||||
checks["second_success_announces_readiness_once"] = Complete(second, 30_200, true) == TailnetReadinessPolicy.Result.BecameReady && policy.IsReady;
|
||||
checks["already_ready_probe_is_not_new_notification"] = Begin(60_200, out var third)
|
||||
&& Complete(third, 60_300, true) == TailnetReadinessPolicy.Result.Ready;
|
||||
checks["failed_probe_clears_ready_state"] = Begin(90_300, out var failed)
|
||||
&& Complete(failed, 90_400, false) == TailnetReadinessPolicy.Result.NotReady && !policy.IsReady;
|
||||
checks["first_failure_backoff_thirty_seconds"] = policy.NextDue == 120_400 && !Begin(120_399, out _);
|
||||
checks["second_failure_backoff_sixty_seconds"] = Begin(120_400, out failed)
|
||||
&& Complete(failed, 120_500, false) == TailnetReadinessPolicy.Result.NotReady && policy.NextDue == 180_500;
|
||||
checks["third_failure_backoff_bounded_two_minutes"] = Begin(180_500, out failed)
|
||||
&& Complete(failed, 180_600, false) == TailnetReadinessPolicy.Result.NotReady && policy.NextDue == 300_600;
|
||||
checks["failure_backoff_does_not_grow_unbounded"] = Begin(300_600, out failed)
|
||||
&& Complete(failed, 300_700, false) == TailnetReadinessPolicy.Result.NotReady && policy.NextDue == 420_700;
|
||||
checks["recovery_restarts_two_success_hysteresis"] = Begin(420_700, out first)
|
||||
&& Complete(first, 420_800, true) == TailnetReadinessPolicy.Result.Confirming
|
||||
&& Begin(450_800, out second) && Complete(second, 450_900, true) == TailnetReadinessPolicy.Result.BecameReady;
|
||||
|
||||
policy.Reset();
|
||||
checks["reset_invalidates_ticket"] = Complete(second, 500_000, true) == TailnetReadinessPolicy.Result.Ignore && !policy.IsReady;
|
||||
checks["fresh_session_can_probe_immediately"] = Begin(500_000, out first);
|
||||
current = current with { Epoch = 2 };
|
||||
checks["session_epoch_fences_late_success"] = Complete(first, 500_100, true) == TailnetReadinessPolicy.Result.Ignore && !policy.IsReady;
|
||||
checks["old_ticket_does_not_consume_new_ticket"] = Begin(500_200, out second)
|
||||
&& Complete(first, 500_300, true) == TailnetReadinessPolicy.Result.Ignore
|
||||
&& Complete(second, 500_400, true) == TailnetReadinessPolicy.Result.Confirming;
|
||||
checks["core_change_fences_old_ticket"] = Begin(530_400, out first)
|
||||
&& policy.Observe(first, current with { CoreId = 11 }, 530_500, true) == TailnetReadinessPolicy.Result.Ignore;
|
||||
current = current with { CoreId = 11 };
|
||||
checks["disconnect_fences_late_success"] = Begin(530_600, out first)
|
||||
&& policy.Observe(first, current with { Wanted = false }, 530_700, true) == TailnetReadinessPolicy.Result.Ignore;
|
||||
checks["grant_withdrawal_fences_late_success"] = Begin(530_800, out first)
|
||||
&& policy.Observe(first, current with { HasAuthorizedCandidate = false }, 530_900, true) == TailnetReadinessPolicy.Result.Ignore;
|
||||
checks["tailnet_connection_fences_old_public_probe"] = Begin(531_000, out first)
|
||||
&& policy.Observe(first, current with { UsesTailnet = true }, 531_100, true) == TailnetReadinessPolicy.Result.Ignore;
|
||||
checks["dead_core_fences_old_probe"] = Begin(531_200, out first)
|
||||
&& policy.Observe(first, current with { Running = false }, 531_300, true) == TailnetReadinessPolicy.Result.Ignore;
|
||||
checks["busy_session_does_not_start_probe"] = !policy.TryBegin(current with { Busy = true }, 531_400, out _);
|
||||
checks["busy_completion_is_ignored_not_announced"] = Begin(531_500, out first)
|
||||
&& policy.Observe(first, current with { Busy = true }, 531_600, true) == TailnetReadinessPolicy.Result.Ignore && !policy.IsReady;
|
||||
foreach (var state in new[] {
|
||||
current with { Wanted = false }, current with { CoreId = null }, current with { Running = false },
|
||||
current with { UsesTailnet = true }, current with { HasAuthorizedCandidate = false } })
|
||||
checks["ineligible_state_" + checks.Count] = !policy.TryBegin(state, 600_000, out _);
|
||||
|
||||
var passed = checks.Values.All(v => v);
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "tailnet-readiness-self-test.json"),
|
||||
JsonSerializer.Serialize(new { kind = "advisory_tailnet_readiness", network_modified = false,
|
||||
transport_switched = false, proxy_authenticated = false, checks, passed },
|
||||
new JsonSerializerOptions { WriteIndented = true }));
|
||||
return passed ? 0 : 84;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user