mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
4 years ago
|
export const tests = []
|
||
|
const t = (f) => tests.push(f)
|
||
|
|
||
|
const fail = (q) =>
|
||
|
q.then(
|
||
|
(v) => Promise.reject('should fail'),
|
||
|
(e) => e.message,
|
||
|
)
|
||
|
|
||
|
t(async ({ eq, ctx }) => eq(await retry(0, ctx.failNTimes(0))(ctx.r), [ctx.r]))
|
||
|
t(async ({ eq, ctx }) => eq(await retry(3, ctx.failNTimes(3))(ctx.r), [ctx.r]))
|
||
|
t(async ({ eq, ctx }) =>
|
||
|
eq(await retry(10, ctx.failNTimes(5))(ctx.r, ctx.r), [ctx.r, ctx.r]),
|
||
|
)
|
||
|
t(async ({ eq, ctx }) =>
|
||
|
eq(await fail(retry(3, ctx.failNTimes(9))(ctx.r)), `x:${ctx.r}`),
|
||
|
)
|
||
|
|
||
|
t(async ({ eq, ctx }) => eq(await timeout(2, ctx.delayed(0))(ctx.r), [ctx.r]))
|
||
|
t(async ({ eq, ctx }) =>
|
||
|
eq(await timeout(2, ctx.delayed(0))(ctx.r, ctx.r), [ctx.r, ctx.r]),
|
||
|
)
|
||
|
t(async ({ eq, ctx }) =>
|
||
|
eq(await fail(timeout(2, ctx.delayed(4))(ctx.r)), 'timeout'),
|
||
|
)
|
||
|
|
||
|
Object.freeze(tests)
|
||
|
|
||
|
export const setup = () => ({
|
||
|
r: Math.random().toString(36).slice(2),
|
||
|
failNTimes: (n) => async (...v) =>
|
||
|
--n < 0 ? v : Promise.reject(Error(`x:${v}`)),
|
||
|
delayed: (delay) => (...v) => new Promise((s) => setTimeout(s, delay, v)),
|
||
|
})
|