mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
setBase: the last call wins; an overtaken or disposed one changes nothing
A vector setBase awaited its style before changing anything, with no generation guard, so a slow earlier call landed over a later one, and one in flight at disposal rejected. Cesium and the stub now count calls like setPhotoreal and setTerrain, abort the overtaken style load, and resolve an overtaken call with imagery: [] and settled: false.
This commit is contained in:
1 parent
5fae3cf485
commit
72d8dd606d
6 files changed
+196
-7
No files matched your search
@@ -470,6 +470,82 @@ test('setBase replaces the imagery and says what it drew', async () => {
|
||||
await assert.rejects(port.setBase({ vector: { styleUrl: 'x' } }), /vector/);
|
||||
});
|
||||
|
||||
/** `globalThis.fetch` answering each URL when the test says, honouring aborts. */
|
||||
function heldFetch() {
|
||||
const held = [];
|
||||
const original = globalThis.fetch;
|
||||
const options = { honourAbort: true };
|
||||
globalThis.fetch = (url, { signal } = {}) =>
|
||||
new Promise((resolve, reject) => {
|
||||
if (options.honourAbort)
|
||||
signal?.addEventListener('abort', () => reject(signal.reason));
|
||||
held.push({
|
||||
url,
|
||||
signal,
|
||||
answer: (body) =>
|
||||
resolve({ ok: true, status: 200, json: async () => body }),
|
||||
});
|
||||
});
|
||||
return { held, options, restore: () => (globalThis.fetch = original) };
|
||||
}
|
||||
|
||||
const EMPTY_STYLE = { version: 8, sources: {}, layers: [] };
|
||||
|
||||
test('a slow vector setBase a later setBase supersedes changes nothing', async () => {
|
||||
const { held, options, restore } = heldFetch();
|
||||
try {
|
||||
const { port } = setup(new Set([...ALL, 'vectorBase']));
|
||||
const slow = port.setBase({
|
||||
vector: { styleUrl: 'https://s.invalid/a.json' },
|
||||
});
|
||||
const fast = await port.setBase({
|
||||
imagery: [{ kind: 'xyz', url: url('one') }],
|
||||
});
|
||||
assert.equal(held.length, 1);
|
||||
assert.equal(held[0].signal.aborted, true, 'its style load is aborted');
|
||||
const status = await slow;
|
||||
assert.deepEqual(status.imagery, []);
|
||||
assert.equal(status.settled, false);
|
||||
assert.deepEqual(port.imagery.list(), fast.imagery);
|
||||
|
||||
// One whose load ignores the abort and lands late changes nothing either.
|
||||
options.honourAbort = false;
|
||||
const late = port.setBase({
|
||||
vector: { styleUrl: 'https://s.invalid/b.json' },
|
||||
});
|
||||
const kept = await port.setBase({
|
||||
imagery: [{ kind: 'xyz', url: url('two') }],
|
||||
});
|
||||
held[1].answer(EMPTY_STYLE);
|
||||
assert.deepEqual((await late).imagery, []);
|
||||
assert.deepEqual(port.imagery.list(), kept.imagery);
|
||||
} finally {
|
||||
restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('a vector setBase in flight when the globe is disposed resolves, changing nothing', async () => {
|
||||
const { held, restore } = heldFetch();
|
||||
try {
|
||||
const { port, dispose } = setup(new Set([...ALL, 'vectorBase']));
|
||||
const before = await port.setBase({
|
||||
imagery: [{ kind: 'xyz', url: url('one') }],
|
||||
});
|
||||
const pending = port.setBase({
|
||||
vector: { styleUrl: 'https://s.invalid/a.json' },
|
||||
});
|
||||
dispose();
|
||||
const status = await pending;
|
||||
assert.deepEqual(status.imagery, []);
|
||||
assert.equal(status.settled, false);
|
||||
assert.deepEqual(port.imagery.list(), before.imagery);
|
||||
assert.equal(held[0].signal.aborted, true);
|
||||
assert.deepEqual((await port.setBase({ imagery: [] })).imagery, []);
|
||||
} finally {
|
||||
restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('globe visibility, settling and progress', () => {
|
||||
const { scene, port, tick } = setup();
|
||||
port.setGlobeVisible(false);
|
||||
|
||||
Reference in new issue
Block a user