Skip to content

Commit

Permalink
chore: ignore RWLock from Istanbul coverage (#32478)
Browse files Browse the repository at this point in the history
This periodically blocks PRs on CodeCov if the locking logic
nondeterminstically happens to have taken another path.

----

*By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Dec 12, 2024
1 parent 225d261 commit fe7d435
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/aws-cdk/lib/api/util/rwlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as path from 'path';
* This class is not 100% race safe, but in practice it should be a lot
* better than the 0 protection we have today.
*/
/* istanbul ignore next: code paths are unpredictable */
export class RWLock {
private readonly pidString: string;
private readonly writerFile: string;
Expand Down Expand Up @@ -158,6 +159,7 @@ export interface IWriterLock extends ILock {
convertToReaderLock(): Promise<ILock>;
}

/* istanbul ignore next: code paths are unpredictable */
async function readFileIfExists(filename: string): Promise<string | undefined> {
try {
return await fs.readFile(filename, { encoding: 'utf-8' });
Expand All @@ -168,13 +170,15 @@ async function readFileIfExists(filename: string): Promise<string | undefined> {
}

let tmpCounter = 0;
/* istanbul ignore next: code paths are unpredictable */
async function writeFileAtomic(filename: string, contents: string): Promise<void> {
await fs.mkdir(path.dirname(filename), { recursive: true });
const tmpFile = `${filename}.${process.pid}_${++tmpCounter}`;
await fs.writeFile(tmpFile, contents, { encoding: 'utf-8' });
await fs.rename(tmpFile, filename);
}

/* istanbul ignore next: code paths are unpredictable */
async function deleteFile(filename: string) {
try {
await fs.unlink(filename);
Expand All @@ -186,6 +190,7 @@ async function deleteFile(filename: string) {
}
}

/* istanbul ignore next: code paths are unpredictable */
function processExists(pid: number) {
try {
process.kill(pid, 0);
Expand Down

0 comments on commit fe7d435

Please sign in to comment.