diff --git a/backend-tests/ToxiproxyAgentProvisioningIntegrationTests.cs b/backend-tests/ToxiproxyAgentProvisioningIntegrationTests.cs index f9001d0..326ab83 100644 --- a/backend-tests/ToxiproxyAgentProvisioningIntegrationTests.cs +++ b/backend-tests/ToxiproxyAgentProvisioningIntegrationTests.cs @@ -37,6 +37,7 @@ public sealed class ToxiproxyAgentProvisioningIntegrationTests await using var toxiproxy = new ToxiproxyBuilder( "ghcr.io/shopify/toxiproxy:2.12.0") .WithNetwork(network) + .WithNetworkAliases("toxiproxy") .Build(); await network.CreateAsync(); @@ -100,22 +101,6 @@ public sealed class ToxiproxyAgentProvisioningIntegrationTests "toxiproxy-approval")); Assert.True(approved.Ok); - gateway.BeforeCreateAsync = async cancellationToken => - { - using var toxicResponse = await toxiproxyAdmin.PostAsJsonAsync( - "/proxies/openclaw/toxics", - new - { - name = "delay-create-response", - type = "latency", - stream = "downstream", - toxicity = 1.0, - attributes = new { latency = 1500, jitter = 0 } - }, - cancellationToken); - toxicResponse.EnsureSuccessStatusCode(); - }; - Assert.True(await service.ProcessNextAsync()); Assert.False(await service.ProcessNextAsync()); @@ -159,6 +144,7 @@ public sealed class ToxiproxyAgentProvisioningIntegrationTests import re import threading import time + import urllib.request agents = {} lock = threading.Lock() @@ -205,8 +191,24 @@ public sealed class ToxiproxyAgentProvisioningIntegrationTests with lock: agents[agent_id] = created - # The mutation is committed before the response. Toxiproxy - # blocks downstream bytes, recreating an uncertain dispatch. + # Install the downstream fault only after the mutation is + # committed. This distinguishes an uncertain response from a + # request that never crossed the dispatch boundary. + toxic = json.dumps({ + "name": "delay-create-response", + "type": "latency", + "stream": "downstream", + "toxicity": 1.0, + "attributes": {"latency": 1500, "jitter": 0} + }).encode("utf-8") + request = urllib.request.Request( + "http://toxiproxy:8474/proxies/openclaw/toxics", + data=toxic, + headers={"Content-Type": "application/json"}, + method="POST") + with urllib.request.urlopen(request, timeout=2): + pass + time.sleep(0.1) self.send_json(200, { "ok": True, @@ -229,7 +231,6 @@ internal sealed class ToxiproxyHttpGatewayConnector(Uri endpoint) private int createCalls; public int CreateCalls => Volatile.Read(ref createCalls); - public Func? BeforeCreateAsync { get; set; } public GatewayConnectionState ConnectionState => GatewayConnectionState.Connected; public string? GatewayVersion => "2026.7.1"; public string? RequiredVersion => "2026.7.1"; @@ -289,8 +290,6 @@ internal sealed class ToxiproxyHttpGatewayConnector(Uri endpoint) break; case "agents.create": Interlocked.Increment(ref createCalls); - if (BeforeCreateAsync is not null) - await BeforeCreateAsync(timeoutSource.Token); response = await client.PostAsJsonAsync( "/agents/create", JsonSerializer.SerializeToNode(parameters),