Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe-granet committed Nov 23, 2024
1 parent 825b3bb commit 200551a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 9 deletions.
14 changes: 7 additions & 7 deletions docs/usage/self-hosted-experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ If set to any value, Renovate will stop using the Docker Hub API (`https://hub.d

If set, Renovate will terminate the whole process group of a terminated child process spawned by Renovate.

## `RENOVATE_X_GITLAB_AUTO_MERGEABLE_CHECK_ATTEMPS`

If set to an positive integer, Renovate will use this as the number of attempts to check if a merge request on GitLab is mergeable before trying to automerge.
The formula for the delay between attempts is `RENOVATE_X_GITLAB_MERGE_REQUEST_DELAY * attempt * attempt` milliseconds.

Default value: `5` (attempts results in max. 13.75 seconds timeout).

## `RENOVATE_X_GITLAB_BRANCH_STATUS_CHECK_ATTEMPS`

If set to an positive integer, Renovate will use this as the number of attempts to check branch status before trying to add status check.
Expand All @@ -58,13 +65,6 @@ Can be useful for slow-running, self-hosted GitLab instances that don't react fa

Default value: `1000` (milliseconds).

## `RENOVATE_X_GITLAB_AUTO_MERGEABLE_CHECK_ATTEMPS`

If set to an positive integer, Renovate will use this as the number of attempts to check if a merge request on GitLab is mergeable before trying to automerge.
The formula for the delay between attempts is `RENOVATE_X_GITLAB_MERGE_REQUEST_DELAY * attempt * attempt` milliseconds.

Default value: `5` (attempts results in max. 13.75 seconds timeout).

## `RENOVATE_X_GITLAB_MERGE_REQUEST_DELAY`

If set, Renovate will use this as a delay to proceed with an automerge.
Expand Down
65 changes: 63 additions & 2 deletions lib/modules/platform/gitlab/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,10 @@ describe('modules/platform/gitlab/index', () => {
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, [])
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, []);

await expect(
Expand Down Expand Up @@ -1098,6 +1102,10 @@ describe('modules/platform/gitlab/index', () => {
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, [])
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, []);

await gitlab.setBranchStatus({
Expand All @@ -1108,7 +1116,7 @@ describe('modules/platform/gitlab/index', () => {
url: 'some-url',
});

expect(timers.setTimeout.mock.calls).toHaveLength(1);
expect(timers.setTimeout.mock.calls).toHaveLength(2);
expect(timers.setTimeout.mock.calls[0][0]).toBe(1000);
});

Expand Down Expand Up @@ -1145,6 +1153,7 @@ describe('modules/platform/gitlab/index', () => {

it('waits for RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY ms when set', async () => {
const delay = 5000;
const retry = 2;
process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_DELAY = String(delay);

const scope = await initRepo();
Expand All @@ -1160,6 +1169,58 @@ describe('modules/platform/gitlab/index', () => {
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, [])
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, []);

await gitlab.setBranchStatus({
branchName: 'some-branch',
context: 'some-context',
description: 'some-description',
state: 'green',
url: 'some-url',
});

expect(timers.setTimeout.mock.calls).toHaveLength(retry);
expect(timers.setTimeout.mock.calls[0][0]).toBe(delay);
});

it('do RENOVATE_X_GITLAB_BRANCH_STATUS_CHECK_ATTEMPS attemps when set', async () => {
const delay = 1000;
const retry = 5;
process.env.RENOVATE_X_GITLAB_BRANCH_STATUS_CHECK_ATTEMPS = String(retry);

const scope = await initRepo();
scope
.post(
'/api/v4/projects/some%2Frepo/statuses/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, {})
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e/statuses',
)
.reply(200, [])
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, [])
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, [])
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, [])
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, [])
.get(
'/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e',
)
.reply(200, []);

await gitlab.setBranchStatus({
Expand All @@ -1170,7 +1231,7 @@ describe('modules/platform/gitlab/index', () => {
url: 'some-url',
});

expect(timers.setTimeout.mock.calls).toHaveLength(1);
expect(timers.setTimeout.mock.calls).toHaveLength(retry);
expect(timers.setTimeout.mock.calls[0][0]).toBe(delay);
});
});
Expand Down

0 comments on commit 200551a

Please sign in to comment.