Skip to content

Commit

Permalink
fix: not the timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Aug 9, 2024
1 parent c61e2d6 commit 53d5365
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions tests/token-queue/image-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,41 @@ describe('Image cache', () => {
ENV.IMAGE_CACHE_GCS_OBJECT_NAME_PREFIX = 'prefix/';
});

test('throws image fetch timeout error', async () => {
ENV.METADATA_FETCH_TIMEOUT_MS = 50;
const server = createTimeoutServer(100);
const serverReady = waiter();
server.listen(9999, 'localhost', () => serverReady.finish());
await serverReady;

try {
await expect(
processImageCache('http://localhost:9999/', contract, tokenNumber)
).rejects.toThrow(MetadataTimeoutError);
} finally {
const serverDone = waiter();
server.close(() => serverDone.finish());
await serverDone;
}
});

// test('throws rate limit error', async () => {
// console.log('A');
// const server = createTestResponseServer('rate limit exceeded', 429);
// test('throws image fetch timeout error', async () => {
// ENV.METADATA_FETCH_TIMEOUT_MS = 50;
// const server = createTimeoutServer(100);
// const serverReady = waiter();
// server.listen(9999, 'localhost', () => serverReady.finish());
// await serverReady;
// console.log('B');

// try {
// console.log('C');
// await expect(
// processImageCache('http://localhost:9999/', contract, tokenNumber)
// ).rejects.toThrow(TooManyRequestsHttpError);
// console.log('D');
// ).rejects.toThrow(MetadataTimeoutError);
// } finally {
// console.log('E');
// const serverDone = waiter();
// server.close(() => serverDone.finish());
// await serverDone;
// console.log('F');
// }
// });

test('throws rate limit error', async () => {
const server = createTestResponseServer('rate limit exceeded', 429);
const serverReady = waiter();
server.listen(9999, 'localhost', () => serverReady.finish());
await serverReady;

try {
await expect(
processImageCache('http://localhost:9999/', contract, tokenNumber)
).rejects.toThrow(TooManyRequestsHttpError);
} finally {
const serverDone = waiter();
server.close(() => serverDone.finish());
await serverDone;
}
});

test('throws other server errors', async () => {
const server = createTestResponseServer('not found', 404);
const serverReady = waiter();
Expand All @@ -77,12 +71,12 @@ describe('Image cache', () => {
}
});

// test('ignores data: URL', async () => {
// const url = 'data:123456';
// await expect(processImageCache(url, contract, tokenNumber)).resolves.toStrictEqual([
// 'data:123456',
// ]);
// });
test('ignores data: URL', async () => {
const url = 'data:123456';
await expect(processImageCache(url, contract, tokenNumber)).resolves.toStrictEqual([
'data:123456',
]);
});

// test('throws upload error', async () => {
// const server = createTestResponseServer('success');
Expand Down

0 comments on commit 53d5365

Please sign in to comment.