dsh-sansheng-liubu/sansheng/test/task-delivery-concurrency.t...

19 lines
924 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import test from 'node:test'
import assert from 'node:assert/strict'
import { setupService } from './helpers.js'
test('taskDispatch:并发同任务只允许一个领取者发送', async () => {
const env = await setupService({ prompt: true })
const opened = await env.service.open({ path: '/delivery-concurrent', name: '并发投递项目' })
const projectId = opened.project.id
await env.service.enableSeat(projectId, 'gongbu')
const created = await env.service.taskCreate(projectId, { title: '并发任务', ownerSeatId: 'gongbu' })
const [a, b] = await Promise.all([
env.service.taskDispatch(projectId, created.task.id),
env.service.taskDispatch(projectId, created.task.id),
])
assert.equal(env.fake.calls.prompt.length, 1)
assert.equal([a, b].filter(item => item.delivered).length, 1)
assert.equal((await env.service.taskGet(projectId, created.task.id)).task.deliveryState, 'accepted')
})