Skip to content

Commit 349ecd0

Browse files
committed
CS-11264 fix CI: fast-path reconciler.mounted + insert registry row in test
The 2c65f87 follow-up moved _realm-auth's registry-presence check to `knownByUrl + DB probe` (mirroring multiRealmAuthorization). That's correct for production but missed two test-mode realities that multiRealmAuthorization handles by checking `realms[]` first: 1. `registerExistingMounts` (used by runTestRealmServer and the legacy pre-Phase-3 boot path) puts realms into `reconciler.mounted` but DELIBERATELY does NOT put them in `knownByUrl` — so the reconcile-time unmount phase doesn't tear legacy mounts down when they're absent from realm_registry. Test 258 ("creates session rooms when missing") trips this: testRealm is in `mounted` but not `knownByUrl` and not in the DB, so the handler skipped it and returned an empty sessions map. 2. The new regression test (259) asserts `knownByUrl.has(...)` as a precondition, but the test fixture's testRealm never gets a realm_registry row inserted, so that precondition was always false — the test was checking a state that never existed in test mode. Fixes: - `handle-realm-auth.ts`: add `reconciler.mounted` as the first fast-path in the lookup order, mirroring multiRealmAuthorization exactly. A realm currently mounted on this process is authoritatively present — the registry probe is the slow fallback for cases where it isn't. - `realm-auth-test.ts`: in test 259, insert a `realm_registry` row via `insertSourceRealmInRegistry` and call `testingOnlyReconcile()` before eviction. The test now exercises the "registry row exists, realm absent from realms[] and reconciler.mounted" path it claims to.
1 parent bd90109 commit 349ecd0

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

packages/realm-server/handlers/handle-realm-auth.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,27 @@ export default function handleRealmAuth({
5656
// the mount happens later, when the holder actually hits a realm
5757
// endpoint and findOrMountRealm/lookupOrMount runs there.
5858
//
59-
// Same lookup order as multiRealmAuthorization (CS-11238): in-memory
60-
// reconciler.knownByUrl first, then a single batched probe against
61-
// realm_registry for any URLs not yet reflected in this process
62-
// (e.g. a freshly-published row from a peer instance between NOTIFY
63-
// and the next reconcile pass).
59+
// Mirrors multiRealmAuthorization's three-step lookup order
60+
// (CS-11238):
61+
// 1. reconciler.mounted — covers realms currently mounted on
62+
// this process, including the mid-start window AND legacy-
63+
// registered mounts from registerExistingMounts that have
64+
// no realm_registry row (test fixtures and the pre-Phase-3
65+
// boot path use this — the reconciler intentionally does
66+
// not put them in knownByUrl so the unmount phase doesn't
67+
// tear them down).
68+
// 2. reconciler.knownByUrl — in-memory mirror of realm_registry,
69+
// refreshed at boot, on NOTIFY, and by the safety-net poll.
70+
// 3. Direct realm_registry probe — covers the gap between a
71+
// peer instance's INSERT+NOTIFY and this instance's next
72+
// reconcile pass.
6473
let registeredUrls = new Set<string>();
6574
let urlsToProbe: string[] = [];
6675
for (let realmUrl of accessibleRealmUrls) {
67-
if (reconciler.knownByUrl.has(realmUrl)) {
76+
if (
77+
reconciler.mounted.has(realmUrl) ||
78+
reconciler.knownByUrl.has(realmUrl)
79+
) {
6880
registeredUrls.add(realmUrl);
6981
} else {
7082
urlsToProbe.push(realmUrl);

packages/realm-server/tests/realm-auth-test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
testRealmHref,
1414
} from './helpers';
1515
import { createJWT as createRealmServerJWT } from '../utils/jwt';
16+
import { insertSourceRealmInRegistry } from '../lib/realm-registry-writes';
1617
import type { RealmServer } from '../server';
1718

1819
module(basename(__filename), function () {
@@ -120,6 +121,21 @@ module(basename(__filename), function () {
120121
});
121122
sinon.stub(MatrixClient.prototype, 'joinRoom').resolves();
122123

124+
// Bring the test fixture's realm into the realm_registry so the
125+
// post-restart state we're simulating is faithful: in production
126+
// every realm has a registry row, but runTestRealmServer
127+
// legacy-registers its testRealm into reconciler.mounted without
128+
// inserting (registerExistingMounts deliberately bypasses
129+
// knownByUrl to preserve legacy mounts across reconcile passes).
130+
// Insert + reconcile so reconciler.knownByUrl reflects the row,
131+
// matching what a real boot would have done.
132+
await insertSourceRealmInRegistry(dbAdapter, {
133+
url: testRealmHref,
134+
diskId: 'node-test_realm/test',
135+
ownerUsername: 'node-test_realm',
136+
});
137+
await testRealmServer.testingOnlyReconcile();
138+
123139
// Simulate the post-restart state: registry row + knownByUrl
124140
// entry are present (reconciler boot has reflected the registry),
125141
// but neither realms[] nor reconciler.mounted holds an active

0 commit comments

Comments
 (0)