Skip to content

Commit

Permalink
Add log line to detect edge condition (#1654)
Browse files Browse the repository at this point in the history
* Add log line to detect edge condition

* Change log position

* Fix coverage

* Change log type to debug

* Update packages/core/src/network.js

Co-authored-by: Pradum Kumar <[email protected]>

* Change timing log to debug log

* Fix test

---------

Co-authored-by: Pradum Kumar <[email protected]>
  • Loading branch information
chinmay-browserstack and prklm10 authored Jul 19, 2024
1 parent a1b2590 commit c3cfcc4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
13 changes: 13 additions & 0 deletions packages/core/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ export class Network {
throw error;
}
});

// After waiting for network to idle check if there are still some request
const activeRequests = this.getActiveRequests(filter);
/* istanbul ignore if: race condition, very hard to mock this */
if (activeRequests.length > 0) {
this.log.debug(`There are ${activeRequests.length} active requests pending during asset discovery. Try increasing the networkIdleTimeout to resolve this issue. \n ${activeRequests}`);
}
}

getActiveRequests(filter) {
let requests = Array.from(this.#requests.values()).filter(filter);
requests = requests.filter((req) => !this.#finishedUrls.has(req.url));
return requests;
}

// Validates that requestId is still valid as sometimes request gets cancelled and we have already executed
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/timing.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class TimeIt {
return await callback();
} finally {
const duration = Date.now() - startTime;
this.log.info(`${name} - ${identifier} - ${duration / 1000}s`);
this.log.debug(`${name} - ${identifier} - ${duration / 1000}s`);
}
}
}
1 change: 0 additions & 1 deletion packages/core/test/snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,6 @@ describe('Snapshot', () => {
domSnapshot: testDOM
});

expect(logger.stdout).toContain(jasmine.stringContaining('[percy] asset-discovery - test snapshot'));
expect(logger.stderr).toEqual([
'[percy] Encountered an error taking snapshot: test snapshot',
'[percy] Error: unexpected snapshot error'
Expand Down
7 changes: 5 additions & 2 deletions packages/core/test/unit/timing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ describe('TimeIt', () => {
// response for it as well.
spyOn(Date, 'now').and.returnValues(date1, date1, date2, date1);
const timeit = new TimeIt();
timeit.log.loglevel('debug');
const callback = async () => { log.info('abcd'); };
await timeit.measure('step', 'test', callback);
expect(mockLogger.stdout).toEqual([
'[percy] abcd',
'[percy] step - test - 60s'
'[percy] abcd'
]);
expect(mockLogger.stderr).toEqual([
'[percy:timer] step - test - 60s'
]);
});
});
Expand Down

0 comments on commit c3cfcc4

Please sign in to comment.