Files
geo/apps/desktop-client/src/main/publish-scheduler.test.ts
T
root 162abdc97c
Backend CI / Backend (push) Has been cancelled
Frontend CI / Frontend (push) Failing after 1m39s
chore(frontend): introduce prettier + eslint and prune unused code
- 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>
2026-05-01 20:39:09 +08:00

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')
})
})