statewire 0.22.0__tar.gz → 0.22.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {statewire-0.22.0 → statewire-0.22.1}/PKG-INFO +1 -1
- {statewire-0.22.0 → statewire-0.22.1}/pyproject.toml +1 -1
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/api.py +72 -4
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/ops.py +1 -0
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/protocol.py +3 -1
- statewire-0.22.1/tests/test_attach_fence.py +196 -0
- {statewire-0.22.0 → statewire-0.22.1}/.gitignore +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/README.md +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/examples/__init__.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/examples/demo_app.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/__init__.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/client.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/document.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/documents.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/langgraph.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/limits.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/metrics.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/state.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/src/statewire/testing.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/client_helpers.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/statewire_helpers.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/storage_probe.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_attach_guardrail.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_attached_hook.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_authorize.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_client.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_client_binding.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_client_ws.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_context.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_date_registry.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_departure.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_document.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_durable_admission.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_eviction.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_frames.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_gap_fill.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_idle.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_lanes.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_langgraph.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_lifespan.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_meta.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_observer.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_ops.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_protocol_negotiation.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_route_auth.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_start_session.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_state_proxy.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_statewire_hostable.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_storage_bridge.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_stream.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_testing.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_writer_lease.py +0 -0
- {statewire-0.22.0 → statewire-0.22.1}/tests/test_ws.py +0 -0
|
@@ -170,6 +170,7 @@ from statepatch import (
|
|
|
170
170
|
|
|
171
171
|
from . import metrics, ops
|
|
172
172
|
from .protocol import (
|
|
173
|
+
FENCE_VERSION,
|
|
173
174
|
GAP_FILL_VERSION,
|
|
174
175
|
VERSION,
|
|
175
176
|
WIRE_VERSION,
|
|
@@ -205,6 +206,7 @@ _HEADER_NAME = re.compile(r"[!#$%&'*+\-.^_`|~0-9A-Za-z]+")
|
|
|
205
206
|
|
|
206
207
|
CLIENT_ID_HEADER = ops.CLIENT_ID_HEADER
|
|
207
208
|
LEASE_HEADER = ops.LEASE_HEADER
|
|
209
|
+
ATTACHER_HEADER = ops.ATTACHER_HEADER
|
|
208
210
|
|
|
209
211
|
RESULT_CACHE_TTL = 30.0
|
|
210
212
|
TRAY_RETIRING_RETRY_MS = 1000
|
|
@@ -932,6 +934,12 @@ class _Lease:
|
|
|
932
934
|
handle: "StatewireAttach | None" = None
|
|
933
935
|
expires_at: float | None = None
|
|
934
936
|
expiry_timer: asyncio.TimerHandle | None = None
|
|
937
|
+
# the client-minted token every attach of one connection carries (2026-11-02)
|
|
938
|
+
attacher: str | None = None
|
|
939
|
+
# a later attach of the same attacher replaced this one: no frame is admitted under it again
|
|
940
|
+
retired: bool = False
|
|
941
|
+
admitting: int = 0
|
|
942
|
+
admitted: asyncio.Event = field(default_factory=asyncio.Event)
|
|
935
943
|
|
|
936
944
|
|
|
937
945
|
def _key_of(key: Sequence[str] | None) -> tuple[str, ...] | None:
|
|
@@ -2140,9 +2148,13 @@ class Statewire(PinnedAPI):
|
|
|
2140
2148
|
selection: Selection | None = None,
|
|
2141
2149
|
frame: _Frame | None = None,
|
|
2142
2150
|
received: float = 0.0,
|
|
2151
|
+
attacher: str | None = None,
|
|
2143
2152
|
) -> tuple[asyncio.Queue[Any], bytes, str]:
|
|
2144
2153
|
"""Register one attach and build its hello; ``frame``'s ephemeral
|
|
2145
|
-
statements are admitted first so their documents and answers ride it.
|
|
2154
|
+
statements are admitted first so their documents and answers ride it.
|
|
2155
|
+
``attacher`` names the connection: this client's earlier attaches of the
|
|
2156
|
+
same attacher are retired, and their admissions finish, before the hello
|
|
2157
|
+
reads a watermark."""
|
|
2146
2158
|
expires_at = (
|
|
2147
2159
|
None
|
|
2148
2160
|
if self.max_lease_lifetime is None
|
|
@@ -2156,7 +2168,18 @@ class Statewire(PinnedAPI):
|
|
|
2156
2168
|
if reserved_websocket:
|
|
2157
2169
|
assert self._pending_websockets > 0
|
|
2158
2170
|
pending_websockets = self._pending_websockets - int(reserved_websocket)
|
|
2159
|
-
|
|
2171
|
+
known = self._clients.get(client_id)
|
|
2172
|
+
replaced = [
|
|
2173
|
+
entry
|
|
2174
|
+
for entry in (known.leases.values() if known is not None else ())
|
|
2175
|
+
if attacher is not None
|
|
2176
|
+
and entry.attacher == attacher
|
|
2177
|
+
and entry.queue in self._subscribers
|
|
2178
|
+
]
|
|
2179
|
+
if (
|
|
2180
|
+
len(self._subscribers) - len(replaced) + pending_websockets
|
|
2181
|
+
>= self.max_subscribers
|
|
2182
|
+
):
|
|
2160
2183
|
raise HTTPException(
|
|
2161
2184
|
status_code=503, detail="stream subscriber limit reached"
|
|
2162
2185
|
)
|
|
@@ -2169,7 +2192,10 @@ class Statewire(PinnedAPI):
|
|
|
2169
2192
|
if expires_at is not None and time.monotonic() >= expires_at:
|
|
2170
2193
|
raise _LeaseExpired
|
|
2171
2194
|
if (
|
|
2172
|
-
len(self._subscribers)
|
|
2195
|
+
len(self._subscribers)
|
|
2196
|
+
- len(replaced)
|
|
2197
|
+
+ self._pending_websockets
|
|
2198
|
+
- int(reserved_websocket)
|
|
2173
2199
|
>= self.max_subscribers
|
|
2174
2200
|
):
|
|
2175
2201
|
raise HTTPException(
|
|
@@ -2202,6 +2228,10 @@ class Statewire(PinnedAPI):
|
|
|
2202
2228
|
client.tray = commands_tray
|
|
2203
2229
|
if client.principal is not _UNBOUND and client.principal != auth_result:
|
|
2204
2230
|
raise _PrincipalMismatch
|
|
2231
|
+
if attacher is not None:
|
|
2232
|
+
for entry in list(client.leases.values()):
|
|
2233
|
+
if entry.attacher == attacher and entry.queue in self._subscribers:
|
|
2234
|
+
await self._retire_lease(entry)
|
|
2205
2235
|
q: asyncio.Queue[Any] = asyncio.Queue(maxsize=self.stream_queue_size)
|
|
2206
2236
|
lease = _Lease(
|
|
2207
2237
|
secrets.token_urlsafe(16),
|
|
@@ -2217,6 +2247,7 @@ class Statewire(PinnedAPI):
|
|
|
2217
2247
|
client,
|
|
2218
2248
|
)
|
|
2219
2249
|
lease.expires_at = expires_at
|
|
2250
|
+
lease.attacher = attacher
|
|
2220
2251
|
contexts = self._validated_contexts(frame or _Frame([]), lease)
|
|
2221
2252
|
self._clients[client_id] = client
|
|
2222
2253
|
if client.principal is _UNBOUND:
|
|
@@ -2483,6 +2514,24 @@ class Statewire(PinnedAPI):
|
|
|
2483
2514
|
raise WebSocketException(code=1011, reason="authorization failed") from exc
|
|
2484
2515
|
return _Attach(resolved_auth, connection, client_id, frame)
|
|
2485
2516
|
|
|
2517
|
+
async def _retire_lease(self, lease: _Lease) -> None:
|
|
2518
|
+
lease.retired = True
|
|
2519
|
+
self._remove_subscriber(lease.queue)
|
|
2520
|
+
while not lease.queue.empty():
|
|
2521
|
+
lease.queue.get_nowait()
|
|
2522
|
+
lease.queue.put_nowait(
|
|
2523
|
+
(
|
|
2524
|
+
[
|
|
2525
|
+
ops.encode_envelope(
|
|
2526
|
+
{"fin": {"reason": "reconnect", "code": "replaced"}}
|
|
2527
|
+
)
|
|
2528
|
+
],
|
|
2529
|
+
True,
|
|
2530
|
+
)
|
|
2531
|
+
)
|
|
2532
|
+
while lease.admitting:
|
|
2533
|
+
await lease.admitted.wait()
|
|
2534
|
+
|
|
2486
2535
|
def _expire_lease(self, lease: _Lease) -> None:
|
|
2487
2536
|
self._remove_subscriber(lease.queue)
|
|
2488
2537
|
while not lease.queue.empty():
|
|
@@ -2595,6 +2644,11 @@ class Statewire(PinnedAPI):
|
|
|
2595
2644
|
selection=selection,
|
|
2596
2645
|
frame=attach.frame,
|
|
2597
2646
|
received=received,
|
|
2647
|
+
attacher=(
|
|
2648
|
+
attach.connection.headers.get(ATTACHER_HEADER)
|
|
2649
|
+
if selection.version >= FENCE_VERSION
|
|
2650
|
+
else None
|
|
2651
|
+
),
|
|
2598
2652
|
)
|
|
2599
2653
|
except (_Violation, _IdentityUnavailable, _PrincipalMismatch, _LeaseExpired):
|
|
2600
2654
|
raise
|
|
@@ -2829,6 +2883,20 @@ class Statewire(PinnedAPI):
|
|
|
2829
2883
|
|
|
2830
2884
|
async def _admit_frame(
|
|
2831
2885
|
self, client: _Client, frame: _Frame, received: float, lease: _Lease
|
|
2886
|
+
) -> tuple[str, int | None]:
|
|
2887
|
+
if lease.retired:
|
|
2888
|
+
raise _LeaseExpired
|
|
2889
|
+
lease.admitting += 1
|
|
2890
|
+
lease.admitted.clear()
|
|
2891
|
+
try:
|
|
2892
|
+
return await self._admit_frame_once(client, frame, received, lease)
|
|
2893
|
+
finally:
|
|
2894
|
+
lease.admitting -= 1
|
|
2895
|
+
if not lease.admitting:
|
|
2896
|
+
lease.admitted.set()
|
|
2897
|
+
|
|
2898
|
+
async def _admit_frame_once(
|
|
2899
|
+
self, client: _Client, frame: _Frame, received: float, lease: _Lease
|
|
2832
2900
|
) -> tuple[str, int | None]:
|
|
2833
2901
|
"""One admission law, every lane: absorbed statements answer from the
|
|
2834
2902
|
record, then the new suffix is admitted whole or the frame is refused
|
|
@@ -3525,7 +3593,7 @@ class Statewire(PinnedAPI):
|
|
|
3525
3593
|
websocket,
|
|
3526
3594
|
{
|
|
3527
3595
|
"reason": "reconnect",
|
|
3528
|
-
"code": "evicted",
|
|
3596
|
+
"code": "replaced" if lease.retired else "evicted",
|
|
3529
3597
|
"message": "attach is gone",
|
|
3530
3598
|
},
|
|
3531
3599
|
code=1008,
|
|
@@ -5,9 +5,11 @@ import re
|
|
|
5
5
|
from typing import Any, Callable, Mapping
|
|
6
6
|
|
|
7
7
|
VERSION = "2026-09-30"
|
|
8
|
-
WIRE_VERSION = "2026-11-
|
|
8
|
+
WIRE_VERSION = "2026-11-02"
|
|
9
9
|
# attach carries a results cursor; a re-sent seq at or below the watermark is a violation
|
|
10
10
|
GAP_FILL_VERSION = "2026-11-01"
|
|
11
|
+
# an attach names its attacher; a new attach retires the same attacher's earlier ones first
|
|
12
|
+
FENCE_VERSION = "2026-11-02"
|
|
11
13
|
TOKEN = re.compile(r"[A-Za-z*][A-Za-z0-9!#$%&'*+.^_`|~:/-]*")
|
|
12
14
|
|
|
13
15
|
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"""Contract: under wire 2026-11-02 every attach of one client connection carries
|
|
2
|
+
its `Statewire-Attacher` token, and a new attach first retires the client id's
|
|
3
|
+
earlier attaches of the same attacher: their admissions in progress finish
|
|
4
|
+
before the hello reads a watermark, and nothing is admitted under them again.
|
|
5
|
+
Another attacher (another tab on the same client id) is untouched. Earlier
|
|
6
|
+
wires keep the race: a frame on the replaced attach can land after the hello."""
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
from statewire_helpers import attach_of, post_frame, statewire_client
|
|
12
|
+
|
|
13
|
+
import statewire.api as api
|
|
14
|
+
from statewire import Statewire, command
|
|
15
|
+
from statewire.protocol import (
|
|
16
|
+
FENCE_VERSION,
|
|
17
|
+
GAP_FILL_VERSION,
|
|
18
|
+
VERSION,
|
|
19
|
+
Offer,
|
|
20
|
+
VersionRange,
|
|
21
|
+
headers,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
FENCE = headers(VersionRange(FENCE_VERSION), (Offer("default", VersionRange(VERSION)),))
|
|
25
|
+
GAP_FILL = headers(
|
|
26
|
+
VersionRange(GAP_FILL_VERSION), (Offer("default", VersionRange(VERSION)),)
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Host(Statewire):
|
|
31
|
+
async def lifespan(self):
|
|
32
|
+
self.state = {"count": 0}
|
|
33
|
+
yield
|
|
34
|
+
|
|
35
|
+
async def authorize(self, request):
|
|
36
|
+
return request.headers.get("x-user", "alice")
|
|
37
|
+
|
|
38
|
+
@command
|
|
39
|
+
async def inc(self):
|
|
40
|
+
self.state["count"] += 1
|
|
41
|
+
return self.state["count"]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def statement(seq):
|
|
45
|
+
return {"protocol": "default", "method": "inc", "params": [], "seq": seq}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def tab(negotiation, attacher, **extra):
|
|
49
|
+
return {**negotiation, "Statewire-Attacher": attacher, **extra}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@pytest.fixture
|
|
53
|
+
def held_first_admission(monkeypatch):
|
|
54
|
+
"""Holds the admission of seq 1 until `gate` is set; `entered` once it waits."""
|
|
55
|
+
gate, entered = asyncio.Event(), asyncio.Event()
|
|
56
|
+
original = api.Statewire._admit_frame_once
|
|
57
|
+
|
|
58
|
+
async def held(self, client, frame, received, lease):
|
|
59
|
+
if any(s["seq"] == 1 for s in frame.cmd) and not gate.is_set():
|
|
60
|
+
entered.set()
|
|
61
|
+
await gate.wait()
|
|
62
|
+
return await original(self, client, frame, received, lease)
|
|
63
|
+
|
|
64
|
+
monkeypatch.setattr(api.Statewire, "_admit_frame_once", held)
|
|
65
|
+
return gate, entered
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
async def hello_after_release(app, negotiation, gate, frame=None):
|
|
69
|
+
"""The hello of a new attach, with the held admission released mid-attach;
|
|
70
|
+
`waited`: the attach had not answered before the release."""
|
|
71
|
+
attach = attach_of(app, frame or {"headers": {}}, headers=negotiation)
|
|
72
|
+
entering = asyncio.create_task(attach.__aenter__())
|
|
73
|
+
await asyncio.sleep(0.05)
|
|
74
|
+
waited = not entering.done()
|
|
75
|
+
gate.set()
|
|
76
|
+
stream = await entering
|
|
77
|
+
try:
|
|
78
|
+
return waited, await stream.next_event()
|
|
79
|
+
finally:
|
|
80
|
+
await attach.__aexit__(None, None, None)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
async def test_a_reattach_retires_the_attacher_s_earlier_attach(held_first_admission):
|
|
84
|
+
gate, entered = held_first_admission
|
|
85
|
+
async with statewire_client(Host) as (app, client):
|
|
86
|
+
async with attach_of(
|
|
87
|
+
app, {"headers": {}}, headers=tab(FENCE, "tab-1")
|
|
88
|
+
) as first:
|
|
89
|
+
hello = await first.next_event()
|
|
90
|
+
assert hello["syn"]["version"] == FENCE_VERSION
|
|
91
|
+
replaced = first.headers["statewire-lease"]
|
|
92
|
+
posted = asyncio.create_task(
|
|
93
|
+
post_frame(client, {"cmd": [statement(1)]}, lease=replaced)
|
|
94
|
+
)
|
|
95
|
+
await entered.wait()
|
|
96
|
+
waited, hello = await hello_after_release(app, tab(FENCE, "tab-1"), gate)
|
|
97
|
+
assert waited
|
|
98
|
+
assert hello["syn"]["protocols"][0]["seq"] == 1
|
|
99
|
+
assert (await posted).status_code == 200
|
|
100
|
+
late = await post_frame(client, {"cmd": [statement(2)]}, lease=replaced)
|
|
101
|
+
assert late.status_code == 423
|
|
102
|
+
assert (await first.next_event())["fin"] == {
|
|
103
|
+
"reason": "reconnect",
|
|
104
|
+
"code": "replaced",
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
async def test_a_retry_whose_previous_hello_was_lost_still_waits(held_first_admission):
|
|
109
|
+
gate, entered = held_first_admission
|
|
110
|
+
async with statewire_client(Host) as (app, client):
|
|
111
|
+
async with attach_of(
|
|
112
|
+
app, {"headers": {}}, headers=tab(FENCE, "tab-1")
|
|
113
|
+
) as first:
|
|
114
|
+
await first.next_event()
|
|
115
|
+
lost = attach_of(app, {"cmd": [statement(1)]}, headers=tab(FENCE, "tab-1"))
|
|
116
|
+
lost_task = asyncio.create_task(lost.__aenter__())
|
|
117
|
+
await entered.wait()
|
|
118
|
+
waited, hello = await hello_after_release(app, tab(FENCE, "tab-1"), gate)
|
|
119
|
+
assert waited
|
|
120
|
+
assert hello["syn"]["protocols"][0]["seq"] == 1
|
|
121
|
+
await (await lost_task).__aexit__(None, None, None)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
async def test_another_attacher_on_the_client_id_is_untouched(held_first_admission):
|
|
125
|
+
gate, entered = held_first_admission
|
|
126
|
+
async with statewire_client(Host) as (app, client):
|
|
127
|
+
async with attach_of(
|
|
128
|
+
app, {"headers": {}}, headers=tab(FENCE, "tab-1")
|
|
129
|
+
) as first:
|
|
130
|
+
await first.next_event()
|
|
131
|
+
posted = asyncio.create_task(
|
|
132
|
+
post_frame(
|
|
133
|
+
client,
|
|
134
|
+
{"cmd": [statement(1)]},
|
|
135
|
+
lease=first.headers["statewire-lease"],
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
await entered.wait()
|
|
139
|
+
waited, hello = await hello_after_release(app, tab(FENCE, "tab-2"), gate)
|
|
140
|
+
assert not waited
|
|
141
|
+
assert (await posted).status_code == 200
|
|
142
|
+
second = await post_frame(
|
|
143
|
+
client, {"cmd": [statement(2)]}, lease=first.headers["statewire-lease"]
|
|
144
|
+
)
|
|
145
|
+
assert second.status_code == 200
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
async def test_without_the_fence_the_hello_can_predate_a_frame(held_first_admission):
|
|
149
|
+
gate, entered = held_first_admission
|
|
150
|
+
async with statewire_client(Host) as (app, client):
|
|
151
|
+
async with attach_of(
|
|
152
|
+
app, {"headers": {}}, headers=tab(GAP_FILL, "tab-1")
|
|
153
|
+
) as first:
|
|
154
|
+
await first.next_event()
|
|
155
|
+
posted = asyncio.create_task(
|
|
156
|
+
post_frame(
|
|
157
|
+
client,
|
|
158
|
+
{"cmd": [statement(1)]},
|
|
159
|
+
lease=first.headers["statewire-lease"],
|
|
160
|
+
)
|
|
161
|
+
)
|
|
162
|
+
await entered.wait()
|
|
163
|
+
waited, hello = await hello_after_release(app, tab(GAP_FILL, "tab-1"), gate)
|
|
164
|
+
assert not waited
|
|
165
|
+
assert hello["syn"]["protocols"][0]["seq"] == 0
|
|
166
|
+
assert (await posted).status_code == 200
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
async def test_another_principal_naming_the_attacher_retires_nothing():
|
|
170
|
+
async with statewire_client(Host) as (app, client):
|
|
171
|
+
async with attach_of(
|
|
172
|
+
app, {"headers": {}}, headers=tab(FENCE, "tab-1")
|
|
173
|
+
) as first:
|
|
174
|
+
await first.next_event()
|
|
175
|
+
async with attach_of(
|
|
176
|
+
app, {"headers": {}}, headers=tab(FENCE, "tab-1", **{"x-user": "bob"})
|
|
177
|
+
) as intruder:
|
|
178
|
+
assert intruder.status == 403
|
|
179
|
+
ok = await post_frame(
|
|
180
|
+
client, {"cmd": [statement(1)]}, lease=first.headers["statewire-lease"]
|
|
181
|
+
)
|
|
182
|
+
assert ok.status_code == 200
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
async def test_a_replacement_fits_under_the_subscriber_limit():
|
|
186
|
+
class OneAttach(Host):
|
|
187
|
+
max_subscribers = 1
|
|
188
|
+
|
|
189
|
+
async with statewire_client(OneAttach) as (app, client):
|
|
190
|
+
async with attach_of(app, {"headers": {}}, headers=tab(FENCE, "tab-1")) as first:
|
|
191
|
+
await first.next_event()
|
|
192
|
+
async with attach_of(
|
|
193
|
+
app, {"headers": {}}, headers=tab(FENCE, "tab-1")
|
|
194
|
+
) as second:
|
|
195
|
+
assert second.status == 200
|
|
196
|
+
assert "syn" in await second.next_event()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|