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.

Add regression test to autoscaled pool

Ondra Urban6f89520d0253
diff --git a/test/autoscaling/autoscaled_pool.js b/test/autoscaling/autoscaled_pool.js
index d44e99037..cb5c42cd2 100644
--- a/test/autoscaling/autoscaled_pool.js
+++ b/test/autoscaling/autoscaled_pool.js
@@ -348,6 +348,31 @@ describe('AutoscaledPool', () => {
await pool.run();
expect(finished).to.be.eql(false);
});
+
+ it('should only finish after tasks complete', async () => {
+ let started = false;
+ let completed = false;
+
+ const pool = new AutoscaledPool({
+ runTaskFunction: async () => {
+ started = true;
+ await delayPromise(100);
+ completed = true;
+ },
+
+ isFinishedFunction: async () => {
+ return started;
+ },
+
+ isTaskReadyFunction: async () => {
+ return !started;
+ },
+ });
+
+ await pool.run();
+ expect(started).to.be.eql(true);
+ expect(completed).to.be.eql(true);
+ });
});
/* eslint-enable no-underscore-dangle */