Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace delay with setTimeout #23123

Merged
2 changes: 0 additions & 2 deletions lib/config/presets/npm/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import * as httpMock from '../../../../test/http-mock';
import { GlobalConfig } from '../../global';
import * as npm from '.';

jest.mock('delay');

describe('config/presets/npm/index', () => {
beforeEach(() => {
GlobalConfig.reset();
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/crate/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import delay from 'delay';
import { setTimeout } from 'timers/promises';
import fs from 'fs-extra';
import _simpleGit, { SimpleGit } from 'simple-git';
import { DirectoryResult, dir } from 'tmp-promise';
Expand Down Expand Up @@ -30,7 +30,7 @@ function setupGitMocks(delayMs?: number): { mockClone: jest.Mock<any, any> } {
.mockImplementation(
async (_registryUrl: string, clonePath: string, _opts) => {
if (delayMs && delayMs > 0) {
await delay(delayMs);
await setTimeout(delayMs);
}

const path = `${clonePath}/my/pk/mypkg`;
Expand Down
2 changes: 0 additions & 2 deletions lib/modules/datasource/npm/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { NpmDatasource, setNpmrc } from '.';

const datasource = NpmDatasource.id;

jest.mock('delay');

let npmResponse: any;

describe('modules/datasource/npm/index', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/platform/azure/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('modules/platform/azure/index', () => {
jest.mock('../../../util/git');
jest.mock('../../../util/host-rules');
jest.mock('../../../logger');
jest.mock('delay');

hostRules = require('../../../util/host-rules');
require('../../../util/sanitize').sanitize = jest.fn((input) => input);
azure = await import('.');
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/platform/azure/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTimeout } from 'timers/promises';
import is from '@sindresorhus/is';
import {
GitPullRequest,
Expand All @@ -8,7 +9,6 @@ import {
GitVersionDescriptor,
PullRequestStatus,
} from 'azure-devops-node-api/interfaces/GitInterfaces.js';
import delay from 'delay';
import JSON5 from 'json5';
import {
REPOSITORY_ARCHIVED,
Expand Down Expand Up @@ -752,7 +752,7 @@ export async function mergePr({
`Updated PR to closed status but change has not taken effect yet. Retrying...`
);

await delay(sleepMs);
await setTimeout(sleepMs);
pr = await azureApiGit.getPullRequestById(pullRequestId, config.project);
isClosed = pr.status === PullRequestStatus.Completed;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/platform/bitbucket-server/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('modules/platform/bitbucket-server/index', () => {
beforeEach(async () => {
// reset module
jest.resetModules();
jest.mock('delay');

jest.mock('../../../util/git');
jest.mock('../../../util/host-rules');
hostRules = require('../../../util/host-rules');
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/platform/bitbucket-server/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import delay from 'delay';
import { setTimeout } from 'timers/promises';
import JSON5 from 'json5';
import type { PartialDeep } from 'type-fest';
import {
Expand Down Expand Up @@ -349,7 +349,7 @@ export async function getBranchPr(branchName: string): Promise<BbsPr | null> {
// istanbul ignore next
export async function refreshPr(number: number): Promise<void> {
// wait for pr change propagation
await delay(1000);
await setTimeout(1000);
// refresh cache
await getPr(number, true);
}
Expand Down
2 changes: 0 additions & 2 deletions lib/modules/platform/github/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import * as github from '.';

const githubApiHost = 'https://api.github.com';

jest.mock('delay');

jest.mock('../../../util/host-rules');
jest.mock('../../../util/http/queue');
const hostRules: jest.Mocked<typeof _hostRules> = mocked(_hostRules);
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/platform/github/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// TODO: types (#7154)
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import URL from 'node:url';
import { setTimeout } from 'timers/promises';
import is from '@sindresorhus/is';
import delay from 'delay';
import JSON5 from 'json5';
import { DateTime } from 'luxon';
import semver from 'semver';
Expand Down Expand Up @@ -338,7 +338,7 @@ export async function createFork(
}
logger.info({ forkedRepo: forkedRepo.full_name }, 'Created forked repo');
logger.debug(`Sleeping 30s after creating fork`);
await delay(30000);
await setTimeout(30000);
return forkedRepo;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/modules/platform/gitlab/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('modules/platform/gitlab/index', () => {
jest.mock('../../../logger');
logger = (await import('../../../logger')).logger as never;
jest.mock('../../../util/host-rules');
jest.mock('delay');

hostRules = require('../../../util/host-rules');
jest.mock('../../../util/git');
git = require('../../../util/git');
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import URL from 'node:url';
import { setTimeout } from 'timers/promises';
import is from '@sindresorhus/is';
import delay from 'delay';
import JSON5 from 'json5';
import semver from 'semver';
import {
Expand Down Expand Up @@ -617,7 +617,7 @@ async function tryPrAutomerge(
if (body.merge_status === desiredStatus && body.pipeline !== null) {
break;
}
await delay(500 * attempt);
await setTimeout(500 * attempt);
}

await gitlabApi.putJson(
Expand Down Expand Up @@ -866,7 +866,7 @@ export async function setBranchStatus({
}
try {
// give gitlab some time to create pipelines for the sha
await delay(1000);
await setTimeout(1000);

await gitlabApi.postJson(url, { body: options });

Expand Down
2 changes: 1 addition & 1 deletion lib/util/git/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { setNoVerify } from '.';
jest.mock('./conflicts-cache');
jest.mock('./behind-base-branch-cache');
jest.mock('./modified-cache');
jest.mock('delay');

jest.mock('../cache/repository');
const behindBaseCache = mocked(_behindBaseCache);
const conflictsCache = mocked(_conflictsCache);
Expand Down
4 changes: 2 additions & 2 deletions lib/util/git/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import URL from 'node:url';
import { setTimeout } from 'timers/promises';
import is from '@sindresorhus/is';
import delay from 'delay';
import fs from 'fs-extra';
// TODO: check if bug is fixed (#7154)
// eslint-disable-next-line import/no-named-as-default
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function gitRetry<T>(gitFunc: () => Promise<T>): Promise<T> {

const nextDelay = delayFactor ^ ((round - 1) * delaySeconds);
logger.trace({ nextDelay }, `Delay next round`);
await delay(1000 * nextDelay);
await setTimeout(1000 * nextDelay);

round++;
}
Expand Down