release: v0.6.0 — 完全移除 IndexedDB,自研 KVStore 事务存储引擎(多key原子写/快照日志恢复/CRC自愈)+ KVStoreEngine + 旧库迁移工具 + 10万级压力验证 + 崩溃注入e2e
This commit is contained in:
@@ -10,8 +10,10 @@
|
||||
import { AriaEngine } from '../src/engine/aria/index';
|
||||
import { createSchema } from '../src/table/schema';
|
||||
import { LSM } from '../src/engine/aria/index/lsm';
|
||||
import { OPFSEngine } from '../src/engine/opfs';
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import { installOPFSMock } from './helpers/opfs-mock';
|
||||
|
||||
beforeEach(() => { installOPFSMock(new Map()); });
|
||||
|
||||
let idbCounter = 0;
|
||||
function uniqueDB(): string {
|
||||
@@ -56,7 +58,7 @@ describe('P0 — close 后无残留后台任务', () => {
|
||||
it('close 后立即 reopen 不被旧后台任务污染', async () => {
|
||||
const dbName = uniqueDB();
|
||||
const engine = new AriaEngine({
|
||||
storageBackend: 'indexeddb',
|
||||
storageBackend: 'opfs',
|
||||
bufferPoolPages: 4,
|
||||
memtableSizeThreshold: 32 * 1024,
|
||||
checkpointInterval: 100000,
|
||||
@@ -162,47 +164,4 @@ describe('P1 — 提交顺序与 close 等待', () => {
|
||||
await engine.close();
|
||||
});
|
||||
|
||||
it('OPFS close 等待挂起写完成(文件完整)', async () => {
|
||||
// mock OPFS(跨实例共享)
|
||||
const files = new Map<string, string>();
|
||||
const dirMock = {
|
||||
getDirectoryHandle: async (_n: string, _o?: any) => dirMock as any,
|
||||
getFileHandle: async (name: string, opts?: any) => {
|
||||
if (opts?.create) {
|
||||
return {
|
||||
createWritable: async () => ({
|
||||
write: async (d: string) => {
|
||||
// 模拟慢 I/O
|
||||
await new Promise((r) => setTimeout(r, 30));
|
||||
files.set(name, d);
|
||||
},
|
||||
close: async () => {},
|
||||
}),
|
||||
};
|
||||
}
|
||||
if (!files.has(name)) throw new Error('Not found');
|
||||
return { getFile: async () => ({ text: async () => files.get(name)!, arrayBuffer: async () => new ArrayBuffer(0) }) };
|
||||
},
|
||||
removeEntry: async (n: string) => { files.delete(n); },
|
||||
};
|
||||
(dirMock as any).entries = () => ({
|
||||
[Symbol.asyncIterator]: async function* () {
|
||||
for (const [k] of files) yield [k];
|
||||
},
|
||||
});
|
||||
const nav = (globalThis as any).navigator || {};
|
||||
nav.storage = { getDirectory: async () => dirMock };
|
||||
(globalThis as any).navigator = nav;
|
||||
|
||||
const engine = new OPFSEngine();
|
||||
await engine.open('opfs-close', 1);
|
||||
await engine.createTable(createSchema('t', { id: { type: 'string', primaryKey: true } }));
|
||||
// 写入不等待(写 I/O 30ms 挂起)
|
||||
const p = engine.insert('t', [{ id: '1' }]);
|
||||
// 立即 close:必须等待挂起写完成
|
||||
await engine.close();
|
||||
await p;
|
||||
// 文件完整(修复前 close 不等写 → 可能读到旧/空文件)
|
||||
expect(files.get('t.json')).toContain('"1"');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user