Windows 0.3.1 clean monitor source delta; no private history or other platform changes
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace UCVL.VPNPlus;
|
||||
|
||||
internal static class ChartFreshnessSelfTest
|
||||
{
|
||||
internal static int Run()
|
||||
{
|
||||
var checks = new Dictionary<string, bool>();
|
||||
string? error = null;
|
||||
try
|
||||
{
|
||||
var at = new DateTimeOffset(2026, 10, 22, 12, 0, 0, TimeSpan.FromHours(8));
|
||||
var now = at;
|
||||
var timeline = new TrafficChartTimeline(() => now);
|
||||
var minute = TimeSpan.FromMinutes(1);
|
||||
checks["empty_history_has_no_fabricated_zero_sample"] = timeline.PointCount == 0
|
||||
&& timeline.Visible(minute).Length == 0 && !timeline.HasFreshSample && timeline.LastSampleAt is null;
|
||||
checks["injected_clock_controls_initial_axis"] = timeline.End == at;
|
||||
checks["measured_zero_is_valid_not_missing"] = timeline.Add(0, 0) && timeline.HasFreshSample
|
||||
&& timeline.PointCount == 1 && timeline.Visible(minute)[0].Up == 0;
|
||||
now = at.AddSeconds(5);
|
||||
checks["valid_sample_preserves_fractional_rates"] = timeline.Add(123.5, 987.25)
|
||||
&& timeline.Visible(minute)[^1] is { Up: 123.5, Down: 987.25 };
|
||||
var beforeGap = timeline.Visible(minute);
|
||||
var previousSegment = beforeGap[^1].Segment;
|
||||
now = at.AddSeconds(10);
|
||||
timeline.MarkUnavailable();
|
||||
checks["missing_reader_advances_axis_without_zero_point"] = timeline.End == now
|
||||
&& timeline.PointCount == 2 && !timeline.HasFreshSample && timeline.LastSampleAt == at.AddSeconds(5);
|
||||
now = at.AddSeconds(15);
|
||||
timeline.MarkUnavailable();
|
||||
timeline.AdvanceClock();
|
||||
checks["repeated_missing_ticks_do_not_add_or_change_values"] = timeline.PointCount == 2
|
||||
&& timeline.Visible(minute).SequenceEqual(beforeGap);
|
||||
now = at.AddSeconds(20);
|
||||
checks["recovery_adds_only_real_sample"] = timeline.Add(12, 34) && timeline.PointCount == 3 && timeline.HasFreshSample;
|
||||
var recovered = timeline.Visible(minute);
|
||||
checks["recovery_starts_new_curve_segment"] = recovered[^1].Segment != previousSegment;
|
||||
checks["recovery_does_not_rewrite_prior_samples_or_accumulate_gap"] = recovered.Take(2).SequenceEqual(beforeGap)
|
||||
&& recovered[^1].Up == 12 && recovered[^1].Down == 34;
|
||||
now = at.AddSeconds(25);
|
||||
checks["subsequent_good_samples_share_recovered_segment"] = timeline.Add(56, 78)
|
||||
&& timeline.Visible(minute)[^1].Segment == recovered[^1].Segment;
|
||||
var latest = timeline.LastSampleAt;
|
||||
var latestCount = timeline.PointCount;
|
||||
checks["duplicate_timestamp_cannot_double_count_display_sample"] = !timeline.Add(900, 800, now)
|
||||
&& timeline.PointCount == latestCount && timeline.LastSampleAt == latest;
|
||||
checks["late_sample_cannot_move_axis_or_replace_current_sample"] = !timeline.Add(900, 800, at.AddSeconds(1))
|
||||
&& timeline.PointCount == latestCount && timeline.End == now && timeline.HasFreshSample;
|
||||
timeline.AdvanceClock(at.AddMinutes(-1));
|
||||
checks["backwards_clock_does_not_rewind_axis"] = timeline.End == now;
|
||||
|
||||
var unannounced = new TrafficChartTimeline(() => now);
|
||||
unannounced.Add(1, 2, at);
|
||||
unannounced.Add(3, 4, at.AddSeconds(5));
|
||||
var segment = unannounced.Visible(minute)[^1].Segment;
|
||||
now = at.AddSeconds(20);
|
||||
unannounced.AdvanceClock();
|
||||
checks["fifteen_second_age_boundary_is_still_fresh"] = unannounced.HasFreshSample;
|
||||
now = at.AddSeconds(21);
|
||||
unannounced.AdvanceClock();
|
||||
checks["silent_reader_stalls_become_unavailable_after_deadline"] = !unannounced.HasFreshSample
|
||||
&& unannounced.PointCount == 2 && unannounced.End == now;
|
||||
now = at.AddSeconds(25);
|
||||
unannounced.Add(5, 6);
|
||||
checks["silent_gap_recovery_does_not_bridge_line"] = unannounced.HasFreshSample
|
||||
&& unannounced.Visible(minute)[^1].Segment != segment;
|
||||
var noTick = new TrafficChartTimeline(() => now);
|
||||
noTick.Add(7, 8, at);
|
||||
noTick.Add(9, 10, at.AddSeconds(20));
|
||||
checks["large_timestamp_gap_breaks_line_even_without_missing_tick"] = noTick.Visible(minute)
|
||||
.Select(point => point.Segment).Distinct().Count() == 2;
|
||||
|
||||
foreach (var (label, up, down) in new[]
|
||||
{
|
||||
("negative_up", -1d, 1d), ("negative_down", 1d, -1d),
|
||||
("nan_up", double.NaN, 1d), ("nan_down", 1d, double.NaN),
|
||||
("positive_infinity", double.PositiveInfinity, 1d), ("negative_infinity", 1d, double.NegativeInfinity)
|
||||
})
|
||||
{
|
||||
var invalid = new TrafficChartTimeline(() => now);
|
||||
invalid.Add(11, 22, at);
|
||||
now = at.AddSeconds(5);
|
||||
checks[label + "_is_missing_not_fake_zero"] = !invalid.Add(up, down) && invalid.PointCount == 1
|
||||
&& !invalid.HasFreshSample && invalid.Visible(minute)[0] is { Up: 11, Down: 22 };
|
||||
now = at.AddSeconds(10);
|
||||
invalid.Add(33, 44);
|
||||
checks[label + "_recovery_breaks_curve"] = invalid.Visible(minute)[0].Segment
|
||||
!= invalid.Visible(minute)[1].Segment;
|
||||
}
|
||||
|
||||
var history = new TrafficChartTimeline(() => now);
|
||||
for (var i = 0; i <= 720; i++) history.Add(i, i * 2, at.AddSeconds(i * 5));
|
||||
checks["actual_five_second_samples_keep_one_hour_inclusive"] = history.PointCount == 721;
|
||||
checks["period_selection_only_filters_actual_samples"] = history.Visible(minute).Length == 13
|
||||
&& history.Visible(TimeSpan.FromMinutes(5)).Length == 61
|
||||
&& history.Visible(TimeSpan.FromMinutes(15)).Length == 181
|
||||
&& history.Visible(TimeSpan.FromMinutes(60)).Length == 721 && history.PointCount == 721;
|
||||
now = at.AddHours(1).AddSeconds(5);
|
||||
history.AdvanceClock();
|
||||
checks["retention_prunes_while_sampling_is_stopped"] = history.PointCount == 720
|
||||
&& history.Visible(TimeSpan.FromMinutes(60))[0].Time == at.AddSeconds(5);
|
||||
now = at.AddHours(1).AddMinutes(2);
|
||||
history.MarkUnavailable();
|
||||
checks["selected_window_expires_without_new_samples"] = history.Visible(minute).Length == 0 && !history.HasFreshSample;
|
||||
now = at.AddHours(2).AddSeconds(1);
|
||||
history.AdvanceClock();
|
||||
checks["whole_history_expires_without_synthetic_points"] = history.PointCount == 0
|
||||
&& history.Visible(TimeSpan.FromHours(1)).Length == 0 && history.LastSampleAt == at.AddHours(1);
|
||||
checks["axis_continues_after_history_is_empty"] = history.End == now;
|
||||
history.Add(99, 88);
|
||||
checks["post_expiry_recovery_is_one_actual_point"] = history.PointCount == 1 && history.HasFreshSample
|
||||
&& history.Visible(minute)[0] is { Up: 99, Down: 88 };
|
||||
history.Reset();
|
||||
checks["reset_discards_old_sample_segment_and_freshness"] = history.PointCount == 0 && !history.HasFreshSample
|
||||
&& history.LastSampleAt is null && history.End == now;
|
||||
history.Add(0, 0);
|
||||
checks["zero_after_reset_is_real_sample_in_initial_segment"] = history.PointCount == 1
|
||||
&& history.Visible(minute)[0].Segment == 0 && history.HasFreshSample;
|
||||
|
||||
var bounded = new TrafficChartTimeline(() => at);
|
||||
for (var i = 0; i < 4000; i++) bounded.Add(i, i, at.AddMilliseconds(i));
|
||||
checks["high_frequency_history_remains_bounded"] = bounded.PointCount == 3600;
|
||||
}
|
||||
catch (Exception exception) { error = exception.ToString(); }
|
||||
var passed = error is null && checks.Count >= 35 && checks.Values.All(value => value);
|
||||
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "chart-freshness-self-test.json"),
|
||||
JsonSerializer.Serialize(new
|
||||
{
|
||||
passed, checks, error,
|
||||
scope = "pure presentation-history clock and missing-sample policy; not a real-window, network-throughput or cumulative-accounting acceptance",
|
||||
network_modified = false, installed_client_modified = false, credentials_loaded = false,
|
||||
untested = new[] { "physical multi-monitor DPI transitions", "live resize frame latency", "production tray/occlusion pixel stability" }
|
||||
}, new JsonSerializerOptions { WriteIndented = true }));
|
||||
return passed ? 0 : 29;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user