tests: bring the slow mesh and fixed-rate cases in line with one line per pair and adaptive probing
The mesh test expects the single line of a pair, dialed by the smaller id. Tests that send at a fixed rate pin adaptive to false, so the admission limit follows that rate.
This commit is contained in:
1 parent
5822285a88
commit
70fc033789
2 files changed
+20
-18
No files matched your search
@@ -119,6 +119,7 @@ public sealed class AgentHarness : IAsyncDisposable
|
||||
bool enabled = kind != "connect";
|
||||
if (rateHz is { } hz && kind != "connect")
|
||||
{
|
||||
parameters["adaptive"] = false; // 固定频率:用例按这个速率发包,限速也按它算
|
||||
parameters["rate_hz"] = hz;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,18 +10,21 @@ public sealed class AgentMeshTests : IClassFixture<BackendFixture>
|
||||
|
||||
public AgentMeshTests(BackendFixture backend) => _backend = backend;
|
||||
|
||||
/// <summary>两个都监听的 Agent 只有一条线路:id 较小的拨出,上下行都在这一条连接上测。</summary>
|
||||
[Fact]
|
||||
public async Task ListeningAgents_MeasureBothDirections_AndReportThroughTheirBackendLinks()
|
||||
public async Task ListeningAgents_ShareOneLine_DialedBySmallerId_AndReportThroughTheirBackendLinks()
|
||||
{
|
||||
await using AgentHarness a = await AgentHarness.StartAsync(_backend);
|
||||
await using AgentHarness b = await AgentHarness.StartAsync(_backend);
|
||||
await a.OverrideLineTasksAsync(rateHz: 30);
|
||||
await b.OverrideLineTasksAsync(rateHz: 30);
|
||||
await using AgentHarness first = await AgentHarness.StartAsync(_backend);
|
||||
await using AgentHarness second = await AgentHarness.StartAsync(_backend);
|
||||
(AgentHarness dialer, AgentHarness listener) = string.CompareOrdinal(first.Id, second.Id) < 0 ? (first, second) : (second, first);
|
||||
await dialer.OverrideLineTasksAsync(rateHz: 30);
|
||||
await listener.OverrideLineTasksAsync(rateHz: 30);
|
||||
await BackendFixture.EventuallyAsync(
|
||||
() => Task.FromResult(a.App.Dialer.IsConnected(b.Id) && b.App.Dialer.IsConnected(a.Id)),
|
||||
TimeSpan.FromSeconds(30), "both listening agents should establish outgoing measurement sessions");
|
||||
() => Task.FromResult(dialer.App.Dialer.IsConnected(listener.Id)),
|
||||
TimeSpan.FromSeconds(30), "the agent with the smaller id should establish the outgoing measurement session");
|
||||
Assert.False(listener.App.Dialer.IsConnected(dialer.Id)); // 反方向不再拨
|
||||
|
||||
using HttpResponseMessage retry = await _backend.Admin.PostAsync($"/api/admin/links/{a.Id}/{b.Id}/retry", null);
|
||||
using HttpResponseMessage retry = await _backend.Admin.PostAsync($"/api/admin/links/{dialer.Id}/{listener.Id}/retry", null);
|
||||
Assert.Equal(HttpStatusCode.Accepted, retry.StatusCode);
|
||||
JsonNode result = JsonNode.Parse(await retry.Content.ReadAsStringAsync())!;
|
||||
Assert.True(result["queued"]!.GetValue<bool>());
|
||||
@@ -29,18 +32,16 @@ public sealed class AgentMeshTests : IClassFixture<BackendFixture>
|
||||
await BackendFixture.EventuallyAsync(async () =>
|
||||
{
|
||||
JsonNode matrix = await _backend.GetJsonAsync(_backend.Admin, "/api/admin/links");
|
||||
return matrix["items"]!.AsArray().Count(i =>
|
||||
((i!["dialer_id"]!.GetValue<string>() == a.Id && i["listener_id"]!.GetValue<string>() == b.Id)
|
||||
|| (i["dialer_id"]!.GetValue<string>() == b.Id && i["listener_id"]!.GetValue<string>() == a.Id))
|
||||
&& i["connected"]!.GetValue<bool>()) == 2;
|
||||
}, TimeSpan.FromSeconds(30), "each agent heartbeat should report its outgoing connection");
|
||||
JsonNode[] pair = [.. matrix["items"]!.AsArray().Select(i => i!).Where(i =>
|
||||
(i["dialer_id"]!.GetValue<string>() == dialer.Id && i["listener_id"]!.GetValue<string>() == listener.Id)
|
||||
|| (i["dialer_id"]!.GetValue<string>() == listener.Id && i["listener_id"]!.GetValue<string>() == dialer.Id))];
|
||||
return pair.Length == 1 && pair[0]["connected"]!.GetValue<bool>();
|
||||
}, TimeSpan.FromSeconds(30), "the dialer's heartbeat should report its outgoing connection, and the pair should have a single line");
|
||||
|
||||
await BackendFixture.EventuallyAsync(async () =>
|
||||
{
|
||||
JsonNode left = await _backend.GetJsonAsync(_backend.Admin, $"/api/admin/raw/chunks?agent_id={a.Id}");
|
||||
JsonNode right = await _backend.GetJsonAsync(_backend.Admin, $"/api/admin/raw/chunks?agent_id={b.Id}");
|
||||
return left["items"]!.AsArray().Any(c => c!["kind"]!.GetValue<string>() == "udp_echo" && c["series"]!.GetValue<string>() == "line:" + b.Id)
|
||||
&& right["items"]!.AsArray().Any(c => c!["kind"]!.GetValue<string>() == "udp_echo" && c["series"]!.GetValue<string>() == "line:" + a.Id);
|
||||
}, TimeSpan.FromSeconds(40), "both directed lines should persist measured packet data");
|
||||
JsonNode chunks = await _backend.GetJsonAsync(_backend.Admin, $"/api/admin/raw/chunks?agent_id={listener.Id}");
|
||||
return chunks["items"]!.AsArray().Any(c => c!["kind"]!.GetValue<string>() == "udp_echo" && c["series"]!.GetValue<string>() == "line:" + dialer.Id);
|
||||
}, TimeSpan.FromSeconds(40), "the line should persist measured packet data");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user