From 7c07eac480400851bc1ef6b15ce4d3130be462c3 Mon Sep 17 00:00:00 2001 From: hmmhmmhm Date: Tue, 13 Oct 2026 09:13:10 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=EB=B6=84=20=EA=B2=BD=EA=B3=84=EC=97=90?= =?UTF-8?q?=20=EC=9D=98=EC=A1=B4=ED=95=98=EB=8D=98=20=EC=86=8C=EB=B9=84?= =?UTF-8?q?=EC=9E=90=20=EC=98=88=EC=82=B0=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=95=88=EC=A0=95=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/relay/fairness.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/relay/fairness.test.ts b/tests/relay/fairness.test.ts index 0a6f3889..ac74801d 100644 --- a/tests/relay/fairness.test.ts +++ b/tests/relay/fairness.test.ts @@ -1,8 +1,10 @@ -import { afterEach, expect, it, vi } from 'vitest'; +import { afterEach, beforeEach, expect, it, vi } from 'vitest'; import { createOliveyoungRelay } from '../../scripts/relay/oliveyoung.js'; const request = (goodsNo: string, consumer = 'a'.repeat(64)) => new Request('http://localhost/v1/oliveyoung/stock-goods-info-v3', { method: 'POST', headers: { authorization: 'Bearer test', 'x-relay-consumer': consumer }, body: JSON.stringify({ goodsNo }), }); +// 같은 분의 예산 검증이 실제 분 경계를 넘는 실행 속도에 의존하지 않도록 고정합니다. +beforeEach(() => vi.spyOn(Date, 'now').mockReturnValue(0)); afterEach(() => vi.restoreAllMocks()); it('한 소비자의 느린 요청이 공용 슬롯을 독점하지 못한다', async () => { let finish!: (value: { status: string }) => void; @@ -20,7 +22,6 @@ it('한 소비자의 느린 요청이 공용 슬롯을 독점하지 못한다', expect((await Promise.all([first, second, other])).map(r => r.status)).toEqual([200, 200, 200]); }); it('캐시와 공유 작업은 분당 예산을 소비하지 않으며 다음 분에 복구한다', async () => { - vi.spyOn(Date, 'now').mockReturnValue(0); const run = vi.fn().mockResolvedValue({ status: 'SUCCESS' }); const relay = createOliveyoungRelay('test', run); for (let i = 0; i < 240; i++) expect((await relay(request(String(i)))).status).toBe(200);