fix: flush durable outboxes after reconnect (Closes #927)
This commit is contained in:
1 parent
76eed47487
commit
64e764b996
6 files changed
+92
-7
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
RECONNECT = ROOT / "frontend" / "reconnect-outboxes.js"
|
||||
|
||||
|
||||
def run_node(script: str) -> dict:
|
||||
result = subprocess.run(
|
||||
["node", "-e", script], cwd=ROOT, text=True, capture_output=True, check=True
|
||||
)
|
||||
return json.loads(result.stdout)
|
||||
|
||||
|
||||
def test_successful_reconnect_restores_identity_and_flushes_unchanged_outboxes():
|
||||
result = run_node(
|
||||
f"""
|
||||
const createReconnectOutboxes = require({json.dumps(str(RECONNECT))});
|
||||
const calls = [];
|
||||
const reconnect = createReconnectOutboxes({{
|
||||
refresh: async () => ({{context:{{user:{{login:'timmy'}}}}}}),
|
||||
restoreIdentity: login => calls.push(['identity', login]),
|
||||
flushIssue: () => calls.push(['issue']),
|
||||
flushAuthored: () => calls.push(['authored']),
|
||||
flushNotificationReads: () => calls.push(['notification-read']),
|
||||
}});
|
||||
reconnect().then(result => process.stdout.write(JSON.stringify({{result, calls}})));
|
||||
"""
|
||||
)
|
||||
|
||||
assert result == {
|
||||
"result": True,
|
||||
"calls": [
|
||||
["identity", "timmy"],
|
||||
["issue"],
|
||||
["authored"],
|
||||
["notification-read"],
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def test_dashboard_uses_reconnect_flush_after_live_identity_refresh():
|
||||
index = (ROOT / "frontend" / "index.html").read_text()
|
||||
dashboard = (ROOT / "frontend" / "dashboard.js").read_text()
|
||||
|
||||
assert '<script src="static/reconnect-outboxes.js"></script>' in index
|
||||
assert "const reconnectOutboxes = createReconnectOutboxes({" in dashboard
|
||||
assert "restoreIdentity: login => { activeFlushLogin = login; confirmedOwnerLogin = login; }" in dashboard
|
||||
assert "window.addEventListener('online', reconnectOutboxes);" in dashboard
|
||||
@@ -930,6 +930,7 @@ def test_install_precaches_complete_subpath_scoped_app_shell():
|
||||
"/dashboard/static/draft-capacity-dialog.js",
|
||||
"/dashboard/static/outbox-coordinator.js",
|
||||
"/dashboard/static/issue-outbox.js",
|
||||
"/dashboard/static/reconnect-outboxes.js",
|
||||
"/dashboard/static/authored-outbox.js",
|
||||
"/dashboard/static/offline-issue-close.js",
|
||||
"/dashboard/static/offline-issue-blocker.js",
|
||||
|
||||
Reference in new issue
Block a user