fix: v0.6.0 复查修正 — KVStore 快照损坏水位 bug(metaSeq 误跳日志)+ 快照损坏测试盲区修复(此前篡改未生效)+ metaSeq 回归测试 + KVStoreEngine 真实浏览器 e2e(3 用例)+ 版本/配置文档校准
This commit is contained in:
@@ -327,3 +327,82 @@ test.describe('OPFS 真实环境', () => {
|
||||
await run(page, 'close');
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('KVStoreEngine(disk 模式)真实环境', () => {
|
||||
test('写入 → 刷新页面 → 数据保留(KVStore 持久化)', async ({ page }) => {
|
||||
await openPage(page);
|
||||
await run(page, 'open', { name: 'e2e-kv-persist', mode: 'disk', diskEngine: 'opfs' });
|
||||
await run(page, 'createTable', {
|
||||
table: 'kvusers',
|
||||
columns: [
|
||||
{ name: 'id', type: 'string', primaryKey: true },
|
||||
{ name: 'name', type: 'string' },
|
||||
{ name: 'tag', type: 'string', index: true },
|
||||
],
|
||||
});
|
||||
for (let i = 0; i < 30; i++) {
|
||||
await run(page, 'insert', {
|
||||
table: 'kvusers',
|
||||
rows: [{ id: `u-${i}`, name: `User${i}`, tag: i % 2 === 0 ? 'even' : 'odd' }],
|
||||
});
|
||||
}
|
||||
expect(await run<{ count: number }>(page, 'count', { table: 'kvusers' })).toEqual({ count: 30 });
|
||||
|
||||
// 刷新:KVStore 快照/日志恢复
|
||||
await page.reload();
|
||||
await expect(page.locator('#status')).toHaveText('ready');
|
||||
await run(page, 'open', { name: 'e2e-kv-persist', mode: 'disk', diskEngine: 'opfs' });
|
||||
const res = await run<{ count: number }>(page, 'count', { table: 'kvusers' });
|
||||
expect(res.count).toBe(30);
|
||||
// 索引查询(重启重建)
|
||||
const evens = await run<{ rows: Record<string, unknown>[] }>(page, 'find', {
|
||||
table: 'kvusers', where: { tag: 'even' },
|
||||
});
|
||||
expect(evens.rows.length).toBe(15);
|
||||
await run(page, 'close');
|
||||
});
|
||||
|
||||
test('崩溃恢复:写入后强制终止 → 重开日志重放数据完整', async ({ page }) => {
|
||||
await openPage(page);
|
||||
await run(page, 'open', { name: 'e2e-kv-crash', mode: 'disk', diskEngine: 'opfs' });
|
||||
await run(page, 'createTable', {
|
||||
table: 'logs', columns: [{ name: 'id', type: 'string', primaryKey: true }],
|
||||
});
|
||||
const total = 40;
|
||||
for (let i = 0; i < total; i++) {
|
||||
await run(page, 'insert', { table: 'logs', rows: [{ id: `log-${i}` }] });
|
||||
}
|
||||
// 模拟崩溃:不 close
|
||||
await crashPage(page);
|
||||
|
||||
const page2 = await page.context().newPage();
|
||||
await openPage(page2);
|
||||
await run(page2, 'open', { name: 'e2e-kv-crash', mode: 'disk', diskEngine: 'opfs' });
|
||||
const res = await run<{ count: number }>(page2, 'count', { table: 'logs' });
|
||||
expect(res.count).toBe(total);
|
||||
await run(page2, 'close');
|
||||
await page2.close();
|
||||
});
|
||||
|
||||
test('事务 commit 原子性:多表写入后重启一致', async ({ page }) => {
|
||||
await openPage(page);
|
||||
await run(page, 'open', { name: 'e2e-kv-tx', mode: 'disk', diskEngine: 'opfs' });
|
||||
await run(page, 'createTable', {
|
||||
table: 't1', columns: [{ name: 'id', type: 'string', primaryKey: true }],
|
||||
});
|
||||
await run(page, 'createTable', {
|
||||
table: 't2', columns: [{ name: 'id', type: 'string', primaryKey: true }],
|
||||
});
|
||||
// 用 SQL 多语句触发原子写(事务)
|
||||
await run(page, 'query', { sql: "BEGIN; INSERT INTO t1 VALUES ('a'); INSERT INTO t2 VALUES ('b'); COMMIT;" });
|
||||
await crashPage(page);
|
||||
|
||||
const page2 = await page.context().newPage();
|
||||
await openPage(page2);
|
||||
await run(page2, 'open', { name: 'e2e-kv-tx', mode: 'disk', diskEngine: 'opfs' });
|
||||
expect(await run<{ count: number }>(page2, 'count', { table: 't1' })).toEqual({ count: 1 });
|
||||
expect(await run<{ count: number }>(page2, 'count', { table: 't2' })).toEqual({ count: 1 });
|
||||
await run(page2, 'close');
|
||||
await page2.close();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user