162abdc97c
- Add Prettier 3 with prettier-plugin-organize-imports (sorts/removes unused imports) - Add ESLint 10 flat config with typescript-eslint + eslint-plugin-vue + eslint-config-prettier - Add root scripts: format, format:check, lint, lint:fix - Reformat 257 files across admin-web, ops-web, desktop-client, packages - Remove unused locals/exports flagged by --noUnusedLocals/--noUnusedParameters - Fix duplicate localTabLabel key, surrogate-pair regex u-flag, NBSP literal in regex - Skip server/ (Go) and apps/browser-extension/ (deprecated per ADR) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import {
|
|
enqueuePublishTask,
|
|
getPublishSchedulerSnapshot,
|
|
initPublishScheduler,
|
|
notePublishTaskActivated,
|
|
notePublishTaskCompleted,
|
|
selectNextPublishTask,
|
|
} from './publish-scheduler'
|
|
|
|
describe('publish scheduler', () => {
|
|
beforeEach(() => {
|
|
vi.useFakeTimers()
|
|
vi.setSystemTime(new Date('2026-04-24T00:00:00.000Z'))
|
|
initPublishScheduler()
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
initPublishScheduler()
|
|
})
|
|
|
|
it('skips same-platform queued tasks while selecting an allowed platform', () => {
|
|
enqueuePublishTask({
|
|
taskId: 'toutiao-active',
|
|
platform: 'toutiao',
|
|
routing: 'rabbitmq-primary',
|
|
})
|
|
notePublishTaskActivated('toutiao-active', 'toutiao')
|
|
enqueuePublishTask({ taskId: 'toutiao-next', platform: 'toutiao', routing: 'rabbitmq-primary' })
|
|
enqueuePublishTask({ taskId: 'zhihu-next', platform: 'zhihu', routing: 'rabbitmq-primary' })
|
|
|
|
const selected = selectNextPublishTask({
|
|
maxConcurrency: 2,
|
|
activeCount: 1,
|
|
})
|
|
|
|
expect(selected?.taskId).toBe('zhihu-next')
|
|
expect(getPublishSchedulerSnapshot().leasingCount).toBe(1)
|
|
})
|
|
|
|
it('holds same-platform tasks during completion cooldown', () => {
|
|
enqueuePublishTask({ taskId: 'first', platform: 'toutiao', routing: 'rabbitmq-primary' })
|
|
expect(selectNextPublishTask({ maxConcurrency: 2, activeCount: 0 })?.taskId).toBe('first')
|
|
notePublishTaskActivated('first', 'toutiao')
|
|
notePublishTaskCompleted('first', 'toutiao')
|
|
|
|
enqueuePublishTask({ taskId: 'second', platform: 'toutiao', routing: 'rabbitmq-primary' })
|
|
|
|
expect(selectNextPublishTask({ maxConcurrency: 2, activeCount: 0 })).toBeNull()
|
|
|
|
vi.advanceTimersByTime(6_001)
|
|
|
|
expect(selectNextPublishTask({ maxConcurrency: 2, activeCount: 0 })?.taskId).toBe('second')
|
|
})
|
|
})
|