Skip to content

Commit

Permalink
✨ increase interval for polling build (#1228)
Browse files Browse the repository at this point in the history
* 💥 increase interval for polling build

* PR suggestions

* remove log line

* fix tests

* fix tests

* refactor

* update warning message
  • Loading branch information
itsjwala authored Apr 6, 2023
1 parent df29f60 commit 5ad071c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/cli-build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Options:
-p, --project <slug> Build project slug, requires '--commit'
-c, --commit <sha> Build commit sha, requires '--project'
-t, --timeout <ms> Timeout before exiting without updates, defaults to 10 minutes
-i, --interval <ms> Interval at which to poll for updates, defaults to 1 second
-i, --interval <ms> Interval at which to poll for updates, defaults to 10 second
-f, --fail-on-changes Exit with an error when diffs are found
--pass-if-approved Doesn't Exit with an error if the build is approved, requires '--fail-on-changes'
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-build/src/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const wait = command('wait', {
short: 't'
}, {
name: 'interval',
description: 'Interval at which to poll for updates, defaults to 1 second',
description: 'Interval at which to poll for updates, defaults to 10 second',
type: 'ms',
parse: Number,
short: 'i'
Expand Down
6 changes: 3 additions & 3 deletions packages/cli-build/test/wait.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('percy build:wait', () => {

await wait(['--project=foo/bar', '--commit=sha123', '--timeout=500', '--interval=50']);

expect(logger.stderr).toEqual([]);
expect(logger.stderr).toEqual(['[percy] Ignoring interval since it cannot be less than 1000ms.']);
expect(logger.stdout).toEqual(jasmine.arrayContaining([
'[percy] Waiting for build...'
]));
Expand All @@ -72,7 +72,7 @@ describe('percy build:wait', () => {

await wait(['--build=123', '--interval=50']);

expect(logger.stderr).toEqual([]);
expect(logger.stderr).toEqual(['[percy] Ignoring interval since it cannot be less than 1000ms.']);
expect(logger.stdout).toEqual(jasmine.arrayContaining([
'[percy] Recieving snapshots...'
]));
Expand All @@ -95,7 +95,7 @@ describe('percy build:wait', () => {

await wait(['--build=123', '--interval=50']);

expect(logger.stderr).toEqual([]);
expect(logger.stderr).toEqual(['[percy] Ignoring interval since it cannot be less than 1000ms.']);
expect(logger.stdout).toEqual(jasmine.arrayContaining([
'[percy] Processing 18 snapshots - 16 of 72 comparisons finished...',
'[percy] Processing 18 snapshots - 32 of 72 comparisons finished...',
Expand Down
2 changes: 1 addition & 1 deletion packages/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,4 @@ await client.waitForBuild({
- `commit` — Commit SHA (**required** when missing `build`)
- `project` — Project slug (**required** when using `commit`)
- `timeout` — Timeout in milliseconds to wait with no updates (**default** `10 * 60 * 1000`)
- `interval` — Interval in miliseconds to check for updates (**default** `1000`)
- `interval` — Interval in miliseconds to check for updates (**default** `10000`)
8 changes: 7 additions & 1 deletion packages/client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
// Default client API URL can be set with an env var for API development
const { PERCY_CLIENT_API_URL = 'https://percy.io/api/v1' } = process.env;
const pkg = getPackageJSON(import.meta.url);
// minimum polling interval milliseconds
const MIN_POLLING_INTERVAL = 1_000;

// Validate ID arguments
function validateId(type, id) {
Expand Down Expand Up @@ -195,8 +197,12 @@ export class PercyClient {
project,
commit,
timeout = 10 * 60 * 1000,
interval = 1000
interval = 10_000
}, onProgress) {
if (interval < MIN_POLLING_INTERVAL) {
this.log.warn(`Ignoring interval since it cannot be less than ${MIN_POLLING_INTERVAL}ms.`);
interval = MIN_POLLING_INTERVAL;
}
if (!project && commit) {
throw new Error('Missing project path for commit');
} else if (!project && !build) {
Expand Down
16 changes: 13 additions & 3 deletions packages/client/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('PercyClient', () => {
let client;

beforeEach(async () => {
await logger.mock();
await logger.mock({ level: 'debug' });
await api.mock();

client = new PercyClient({
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('PercyClient', () => {
}]
})).toBeResolved();

expect(logger.stderr).toEqual(['[percy] Warning: Missing `clientInfo` and/or `environmentInfo` properties']);
expect(logger.stderr).toEqual(jasmine.arrayContaining(['[percy:client] Warning: Missing `clientInfo` and/or `environmentInfo` properties']));
});

it('it logs a debug warning when partial info is passed', async () => {
Expand All @@ -77,7 +77,7 @@ describe('PercyClient', () => {
}]
})).toBeResolved();

expect(logger.stderr).toEqual(['[percy] Warning: Missing `clientInfo` and/or `environmentInfo` properties']);
expect(logger.stderr).toEqual(jasmine.arrayContaining(['[percy:client] Warning: Missing `clientInfo` and/or `environmentInfo` properties']));
});

it('does not duplicate or include empty client and environment information', () => {
Expand Down Expand Up @@ -365,6 +365,16 @@ describe('PercyClient', () => {
.toThrowError('Invalid project path. Expected "org/project" but received "test"');
});

it('warns when interval is less than 1000ms', async () => {
api
.reply('/builds/123', () => [200, {
data: { attributes: { state: 'finished' } }
}]);

await client.waitForBuild({ build: '123', interval: 50 });
expect(logger.stderr).toEqual(jasmine.arrayContaining(['[percy:client] Ignoring interval since it cannot be less than 1000ms.']));
});

it('invokes the callback when data changes while waiting', async () => {
let progress = 0;

Expand Down

0 comments on commit 5ad071c

Please sign in to comment.