Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.returns(Promise.resolve());
Apify.events.emit(ACTOR_EVENT_NAMES_EX.PERSIST_STATE);
await delayPromise(1);
expect(requestList.isStatePersisted).to.be.eql(true);
// Do some other changes and persist it again.
const request2 = await requestList.fetchNextRequest();
expect(requestList.isStatePersisted).to.be.eql(false);
await requestList.markRequestHandled(request2);
expect(requestList.isStatePersisted).to.be.eql(false);
mock.expects('setValue')
.once()
.withArgs(PERSIST_STATE_KEY, requestList.getState())
.returns(Promise.resolve());
Apify.events.emit(ACTOR_EVENT_NAMES_EX.PERSIST_STATE);
await delayPromise(1);
expect(requestList.isStatePersisted).to.be.eql(true);
// Reclaim event doesn't change the state.
await requestList.reclaimRequest(request1);
expect(requestList.isStatePersisted).to.be.eql(true);
// Now initiate new request list from saved state and check that it's same as state
// of original request list.
mock.expects('getValue')
.once()
.withArgs(PERSIST_STATE_KEY)
.returns(Promise.resolve(requestList.getState()));
const requestList2 = new Apify.RequestList(opts);
await requestList2.initialize();
expect(requestList2.getState()).to.be.eql(requestList.getState());
it('should not handle tasks added after isFinishedFunction returned true', async () => {
const isFinished = async () => count > 10;
let count = 0;
// Run the pool and close it after 3s.
const pool = new AutoscaledPool({
minConcurrency: 3,
runTaskFunction: async () => delayPromise(1).then(() => { count++; }),
isFinishedFunction: async () => isFinished(),
isTaskReadyFunction: async () => !await isFinished(),
});
pool.maybeRunIntervalMillis = 5;
await pool.run();
await delayPromise(10);
// Check finished tasks.
expect(count).to.be.within(11, 13);
});
Apify.main(async () => {
await delayPromise(10); // Here must be short sleep to get following line to later tick
expect(isWsConnected).to.be.eql(true);
Apify.events.on('name-1', data => eventsReceived.push(data));
await delayPromise(1000);
});
Apify.main(async () => {
await delayPromise(10); // Here must be short sleep to get following line to later tick
expect(isWsConnected).to.be.eql(true);
Apify.events.on('name-1', data => eventsReceived.push(data));
await delayPromise(1000);
});
handleRequestFunction: async () => {
await delayPromise(1);
count++;
},
maxRequestsPerCrawl: 40,
userFunc: async () => {
await delayPromise(20);
throw new Error('Test exception II');
},
exitCode: 91,
cheerioCrawler._requestFunction = async () => {
await delayPromise(300);
return 'Body';
};
runTaskFunction: async () => {
await delayPromise(1);
if (counter === 10) { isTaskReady = false; setTimeout(() => { isTaskReady = true; }, 10); }
if (counter === 19) { isTaskReady = false; isFinished = true; }
counter++;
finished.push(Date.now());
},
isFinishedFunction: async () => isFinished,
const handlePageFunction = async ({ request }) => {
await delayPromise(3000);
processed.push(request);
};
runTaskFunction: async () => {
started = true;
await delayPromise(100);
completed = true;
},