Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

1.1 KB
Raw Blame
import { rm } from 'node:fs/promises';
import { resolve } from 'node:path';

import { FileSystemStorageBackend } from '@crawlee/fs-storage';

describe('FileSystemStorageBackend extendRequestProcessingTime', () => {
    const tmpLocation = resolve(import.meta.dirname, './tmp/prolong-request-lock');

    afterEach(async () => {
        await rm(tmpLocation, { force: true, recursive: true });
    });

    test('extends the lock on a fetched request, false for one never locked', async () => {
        const storage = new FileSystemStorageBackend({
            localDataDirectory: tmpLocation,
        });
        const queue = await storage.createRequestQueueBackend({
            name: 'default',
        });
        await queue.addBatchOfRequests([{ url: 'http://example.com/1', uniqueKey: '1' }]);

        const locked = await queue.fetchNextRequest();
        expect(locked).toBeDefined();

        expect(await queue.extendRequestProcessingTime!(locked!.id!, 30)).toBe(true);
        expect(await queue.extendRequestProcessingTime!('no-such-request', 30)).toBe(false);

        await queue.drop();
    });
});