Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/realm-server/tests/atomic-endpoints-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,11 @@ module(basename(import.meta.filename), function () {
},
],
};
// The follow-up GET is credential-less, so it doesn't share this
// authenticated write's read-your-writes principal and won't wait
// on its indexing — make the write itself synchronous instead.
let response = await request
.post('/_atomic')
.post('/_atomic?waitForIndex=true')
.set('Accept', SupportedMimeType.JSONAPI)
.set(
'Authorization',
Expand Down Expand Up @@ -394,8 +397,11 @@ module(basename(import.meta.filename), function () {
],
};

// Synchronous write for the same reason as the single-instance
// test: the credential-less GETs below don't wait on this
// authenticated write's indexing.
let response = await request
.post('/_atomic')
.post('/_atomic?waitForIndex=true')
.set('Accept', SupportedMimeType.JSONAPI)
.set(
'Authorization',
Expand Down Expand Up @@ -697,8 +703,10 @@ module(basename(import.meta.filename), function () {
},
],
};
// Synchronous write: the credential-less card+json GET below
// doesn't wait on this authenticated write's indexing.
let response = await request
.post('/_atomic')
.post('/_atomic?waitForIndex=true')
.set('Accept', SupportedMimeType.JSONAPI)
.set(
'Authorization',
Expand Down Expand Up @@ -775,8 +783,10 @@ module(basename(import.meta.filename), function () {
},
],
};
// Synchronous write: the credential-less card+json GET below
// doesn't wait on this authenticated write's indexing.
let response = await request
.post('/_atomic')
.post('/_atomic?waitForIndex=true')
.set('Accept', SupportedMimeType.JSONAPI)
.set(
'Authorization',
Expand Down
19 changes: 16 additions & 3 deletions packages/realm-server/tests/card-source-endpoints-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,11 +935,20 @@ module(basename(import.meta.filename), function () {
}
let id = maybeId;

// modify field
// modify field. The +source POST indexes deferred, and only an
// identified reader waits on their own pending indexing (a
// credential-less read never waits — anonymous writes are
// unsupported), so this write and the read that depends on it
// authenticate as the same user; authorization still comes from
// the realm's public write permission.
{
let response = await request
.post('/test-card.gts')
.set('Accept', 'application/vnd.card+source').send(`
.set('Accept', 'application/vnd.card+source')
.set(
'Authorization',
`Bearer ${createJWT(testRealm, 'john', ['read', 'write'])}`,
).send(`
import { contains, field, CardDef } from '@cardstack/base/card-api';
import StringField from '@cardstack/base/string';

Expand All @@ -956,7 +965,11 @@ module(basename(import.meta.filename), function () {
{
let response = await request
.get(new URL(id).pathname)
.set('Accept', 'application/vnd.card+json');
.set('Accept', 'application/vnd.card+json')
.set(
'Authorization',
`Bearer ${createJWT(testRealm, 'john', ['read', 'write'])}`,
);

assert.strictEqual(response.status, 200, 'HTTP 200 status');
let json = response.body;
Expand Down
19 changes: 19 additions & 0 deletions packages/realm-server/tests/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,7 @@ export async function createRealm({
fullIndexOnStartup,
mediaCacheAdapter,
screenshotSyncWaitMs,
readIndexDrainBudgetMs,
}: {
dir: string;
definitionLookup: DefinitionLookup;
Expand Down Expand Up @@ -1304,6 +1305,9 @@ export async function createRealm({
// Shrinks the `_screenshot/` route's on-demand sync-wait budget so tests
// can exercise the 503 + Retry-After path without holding real time.
screenshotSyncWaitMs?: number;
// Shrinks the card read endpoints' read-your-writes indexing-drain budget
// so tests can exercise the bounded-wait path without holding real time.
readIndexDrainBudgetMs?: number;
}): Promise<{ realm: Realm; adapter: RealmAdapter }> {
await insertPermissions(dbAdapter, new URL(realmURL), permissions);

Expand Down Expand Up @@ -1386,6 +1390,9 @@ export async function createRealm({
{
...(fullIndexOnStartup ? { fullIndexOnStartup: true as const } : {}),
...(screenshotSyncWaitMs !== undefined ? { screenshotSyncWaitMs } : {}),
...(readIndexDrainBudgetMs !== undefined
? { readIndexDrainBudgetMs }
: {}),
},
);
if (worker) {
Expand Down Expand Up @@ -1435,6 +1442,7 @@ export async function runTestRealmServer({
},
prerenderer: providedPrerenderer,
mediaCacheAdapter,
readIndexDrainBudgetMs,
}: {
testRealmDir: string;
realmsRootPath: string;
Expand All @@ -1458,6 +1466,7 @@ export async function runTestRealmServer({
};
prerenderer?: Prerenderer;
mediaCacheAdapter?: MediaCacheAdapter;
readIndexDrainBudgetMs?: number;
}) {
stripTlsEnvVars();
let prerenderer = providedPrerenderer ?? (await getTestPrerenderer());
Expand Down Expand Up @@ -1499,6 +1508,7 @@ export async function runTestRealmServer({
audioSizeLimitBytes,
videoSizeLimitBytes,
mediaCacheAdapter,
readIndexDrainBudgetMs,
});

await testRealm.logInToMatrix();
Expand Down Expand Up @@ -2165,6 +2175,7 @@ type InternalPermissionedRealmSetupOptions = {
audioSizeLimitBytes?: number;
videoSizeLimitBytes?: number;
mediaCacheAdapter?: MediaCacheAdapter;
readIndexDrainBudgetMs?: number;
};

async function startPermissionedRealmFixture(
Expand All @@ -2184,6 +2195,7 @@ async function startPermissionedRealmFixture(
audioSizeLimitBytes,
videoSizeLimitBytes,
mediaCacheAdapter,
readIndexDrainBudgetMs,
}: InternalPermissionedRealmSetupOptions,
): Promise<{
testRealmServer: Awaited<ReturnType<typeof runTestRealmServer>>;
Expand Down Expand Up @@ -2254,6 +2266,7 @@ async function startPermissionedRealmFixture(
videoSizeLimitBytes,
prerenderer,
mediaCacheAdapter,
readIndexDrainBudgetMs,
});

let request = supertest(testRealmServer.testRealmHttpServer);
Expand Down Expand Up @@ -2323,6 +2336,7 @@ export function setupPermissionedRealm(
audioSizeLimitBytes,
videoSizeLimitBytes,
mediaCacheAdapter,
readIndexDrainBudgetMs,
}: {
permissions: RealmPermissions;
realmURL?: URL;
Expand Down Expand Up @@ -2352,6 +2366,7 @@ export function setupPermissionedRealm(
audioSizeLimitBytes?: number;
videoSizeLimitBytes?: number;
mediaCacheAdapter?: MediaCacheAdapter;
readIndexDrainBudgetMs?: number;
},
) {
let testRealmServer: Awaited<ReturnType<typeof runTestRealmServer>>;
Expand Down Expand Up @@ -2382,6 +2397,7 @@ export function setupPermissionedRealm(
audioSizeLimitBytes,
videoSizeLimitBytes,
mediaCacheAdapter,
readIndexDrainBudgetMs,
});
testRealmServer = server;

Expand Down Expand Up @@ -2436,6 +2452,9 @@ function permissionedRealmTemplateCacheKey(
fileSizeLimitBytes: options.fileSizeLimitBytes ?? null,
audioSizeLimitBytes: options.audioSizeLimitBytes ?? null,
videoSizeLimitBytes: options.videoSizeLimitBytes ?? null,
// `readIndexDrainBudgetMs` is deliberately absent: it tunes request-time
// wait behavior on the live realm and leaves no trace in the template
// database, so keying on it would only fragment the template cache.
prerenderer: prerendererCacheKeyPart(options.prerenderer),
});
}
Expand Down
Loading
Loading