|
6 | 6 | * Licensed under the MIT License. See LICENSE file in the project root for full license information. |
7 | 7 | */ |
8 | 8 |
|
| 9 | +using System; |
9 | 10 | using PerformanceMonitor.Common; |
10 | 11 | using Xunit; |
11 | 12 |
|
@@ -81,6 +82,102 @@ public void DecideConnection_AlreadyDisconnectedAtFirstSighting_StaysSilent_ButI |
81 | 82 | Assert.Equal(AgConnectionDecision.Reconnected, AgAlertPolicy.DecideConnection("DISCONNECTED", "CONNECTED")); |
82 | 83 | } |
83 | 84 |
|
| 85 | + /* ---------------- #2426: the disconnect re-fire ---------------- */ |
| 86 | + |
| 87 | + private static readonly DateTime Noon = new(2026, 8, 20, 12, 0, 0, DateTimeKind.Utc); |
| 88 | + |
| 89 | + [Theory] |
| 90 | + [InlineData("CONNECTED", "DISCONNECTED", AgConnectionDecision.Disconnected)] |
| 91 | + [InlineData("DISCONNECTED", "CONNECTED", AgConnectionDecision.Reconnected)] |
| 92 | + [InlineData("DISCONNECTED", "DISCONNECTED", AgConnectionDecision.None)] |
| 93 | + [InlineData("CONNECTED", "CONNECTED", AgConnectionDecision.None)] |
| 94 | + [InlineData(null, "DISCONNECTED", AgConnectionDecision.None)] |
| 95 | + [InlineData("CONNECTED", null, AgConnectionDecision.None)] |
| 96 | + public void DecideConnection_RefireOff_IsTheEdgeOnlyOverloadExactly( |
| 97 | + string? previous, string? current, AgConnectionDecision expected) |
| 98 | + { |
| 99 | + /* The shipped default, and the whole matrix rather than one case: null, zero and a negative all |
| 100 | + mean OFF, and off has to be byte-for-byte the two-argument behavior or an upgrade would start |
| 101 | + re-alerting on a knob nobody set. */ |
| 102 | + Assert.Equal(expected, AgAlertPolicy.DecideConnection(previous, current, null, null, Noon)); |
| 103 | + Assert.Equal(expected, AgAlertPolicy.DecideConnection(previous, current, TimeSpan.Zero, null, Noon)); |
| 104 | + Assert.Equal(expected, AgAlertPolicy.DecideConnection(previous, current, TimeSpan.FromMinutes(-5), null, Noon)); |
| 105 | + } |
| 106 | + |
| 107 | + [Fact] |
| 108 | + public void DecideConnection_StillDisconnected_WaitsOutTheWindow_ThenSaysItAgain() |
| 109 | + { |
| 110 | + var refire = TimeSpan.FromMinutes(10); |
| 111 | + |
| 112 | + /* Announced at noon: inside the window there is nothing new to say. */ |
| 113 | + Assert.Equal( |
| 114 | + AgConnectionDecision.None, |
| 115 | + AgAlertPolicy.DecideConnection("DISCONNECTED", "DISCONNECTED", refire, Noon, Noon.AddMinutes(9))); |
| 116 | + |
| 117 | + /* At the boundary, and still hours later — the point of the knob is that a week-long outage does |
| 118 | + not read like a blip. */ |
| 119 | + Assert.Equal( |
| 120 | + AgConnectionDecision.StillDisconnected, |
| 121 | + AgAlertPolicy.DecideConnection("DISCONNECTED", "DISCONNECTED", refire, Noon, Noon.AddMinutes(10))); |
| 122 | + Assert.Equal( |
| 123 | + AgConnectionDecision.StillDisconnected, |
| 124 | + AgAlertPolicy.DecideConnection("DISCONNECTED", "DISCONNECTED", refire, Noon, Noon.AddHours(8))); |
| 125 | + } |
| 126 | + |
| 127 | + [Fact] |
| 128 | + public void DecideConnection_ARealEdgeOutranksARefire() |
| 129 | + { |
| 130 | + var refire = TimeSpan.FromMinutes(10); |
| 131 | + |
| 132 | + /* The edge that OPENS the outage announces as Disconnected even though the window is trivially due |
| 133 | + on it, or the caller would have two reasons to announce the same sweep. */ |
| 134 | + Assert.Equal( |
| 135 | + AgConnectionDecision.Disconnected, |
| 136 | + AgAlertPolicy.DecideConnection("CONNECTED", "DISCONNECTED", refire, null, Noon)); |
| 137 | + |
| 138 | + /* And a recovery is a recovery whatever the clock says. */ |
| 139 | + Assert.Equal( |
| 140 | + AgConnectionDecision.Reconnected, |
| 141 | + AgAlertPolicy.DecideConnection("DISCONNECTED", "CONNECTED", refire, Noon.AddHours(-9), Noon)); |
| 142 | + } |
| 143 | + |
| 144 | + [Fact] |
| 145 | + public void DecideConnection_NoStampIsDueNow_SoARestartMidOutageStillReAnnounces() |
| 146 | + { |
| 147 | + var refire = TimeSpan.FromMinutes(10); |
| 148 | + |
| 149 | + /* Both apps hold this edge state in memory, so a restart during a week-long outage sees a replica |
| 150 | + already DISCONNECTED with no record of it ever having been announced. Rule 1's silent baseline |
| 151 | + would make that silence permanent, which is the exact failure the knob exists to prevent — so |
| 152 | + with re-fire ON, and only then, a first sighting announces. */ |
| 153 | + Assert.Equal( |
| 154 | + AgConnectionDecision.StillDisconnected, |
| 155 | + AgAlertPolicy.DecideConnection(null, "DISCONNECTED", refire, null, Noon)); |
| 156 | + Assert.Equal( |
| 157 | + AgConnectionDecision.StillDisconnected, |
| 158 | + AgAlertPolicy.DecideConnection("DISCONNECTED", "DISCONNECTED", refire, null, Noon)); |
| 159 | + |
| 160 | + /* With it off, rule 1 governs unchanged. */ |
| 161 | + Assert.Equal( |
| 162 | + AgConnectionDecision.None, |
| 163 | + AgAlertPolicy.DecideConnection(null, "DISCONNECTED", null, null, Noon)); |
| 164 | + } |
| 165 | + |
| 166 | + [Fact] |
| 167 | + public void DecideConnection_ARefireStillNeedsAnExactDisconnected() |
| 168 | + { |
| 169 | + var refire = TimeSpan.FromMinutes(10); |
| 170 | + |
| 171 | + /* Same rule the edge follows, and it matters more here: a re-fire pages repeatedly, so a state |
| 172 | + string the product never learned to interpret must not become a standing page. */ |
| 173 | + Assert.Equal( |
| 174 | + AgConnectionDecision.None, |
| 175 | + AgAlertPolicy.DecideConnection("SOMETHING_NEW", "SOMETHING_NEW", refire, null, Noon)); |
| 176 | + Assert.Equal( |
| 177 | + AgConnectionDecision.None, |
| 178 | + AgAlertPolicy.DecideConnection("CONNECTED", null, refire, null, Noon)); |
| 179 | + } |
| 180 | + |
84 | 181 | /* ---------------- suspension ---------------- */ |
85 | 182 |
|
86 | 183 | [Theory] |
|
0 commit comments