Improve application responsiveness and background processing
This commit is contained in:
@@ -5,7 +5,7 @@ import { join } from 'node:path';
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import {
|
||||
getUploadFileProgress, hashUploadedFiles, MAX_UPLOAD_CHUNK_BYTES,
|
||||
receiveUploadChunk, UploadOffsetError, validateUploadPlan, withUploadLock
|
||||
receiveUploadChunk, UploadOffsetError, validateUploadPlan, withUploadLock, withUploadFileLock
|
||||
} from '../../src/lib/server/game-files/uploads.js';
|
||||
import { manifestChecksum, verifyGameFile } from '../../src/lib/server/game-files/storage.js';
|
||||
|
||||
@@ -22,6 +22,22 @@ beforeEach(async () => {
|
||||
});
|
||||
afterEach(async () => { await rm(directory, { recursive: true, force: true }); });
|
||||
|
||||
it('allows independent files together, serializes same-file offsets, and makes publication a barrier', async () => {
|
||||
let release!: () => void;
|
||||
const blocked = new Promise<void>(resolve => { release = resolve; });
|
||||
const order: string[] = [];
|
||||
const first = withUploadFileLock(root, 'a', async () => { order.push('a1'); await blocked; });
|
||||
const same = withUploadFileLock(root, 'a', async () => { order.push('a2'); });
|
||||
const other = withUploadFileLock(root, 'b', async () => { order.push('b'); });
|
||||
const publish = withUploadLock(root, async () => { order.push('publish'); });
|
||||
const later = withUploadFileLock(root, 'c', async () => { order.push('c'); });
|
||||
await other;
|
||||
expect(order).toEqual(['a1', 'b']);
|
||||
release();
|
||||
await Promise.all([first, same, publish, later]);
|
||||
expect(order).toEqual(['a1', 'b', 'a2', 'publish', 'c']);
|
||||
});
|
||||
|
||||
describe('browser folder upload plans', () => {
|
||||
it('preserves folder structure and source identity while sorting canonical paths', () => {
|
||||
expect(validateUploadPlan([{ path: 'zone/map.ff', size: 10, lastModified: 100 }, { path: 'main/data.iwd', size: 0 }])).toEqual([
|
||||
|
||||
Reference in New Issue
Block a user