Skip to content

Commit

Permalink
test: add missing await in fs-rm/fs-rmdir tests
Browse files Browse the repository at this point in the history
Noticed that a few assertions were not being awaited, this could
potentially be leading to flakiness in tmp cleanup.

Refs: #41201

PR-URL: #41545
Refs: #41201
Reviewed-By: Ian Sutherland <ian@iansutherland.ca>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
  • Loading branch information
bcoe authored and BethGriggs committed Jan 24, 2022
1 parent c0aec67 commit 5e3f751
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions test/parallel/test-fs-rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,19 @@ function removeAsync(dir) {
makeNonEmptyDirectory(4, 10, 2, dir, true);

// Removal should fail without the recursive option set to true.
assert.rejects(fs.promises.rm(dir), { syscall: 'rm' });
assert.rejects(fs.promises.rm(dir, { recursive: false }), {
await assert.rejects(fs.promises.rm(dir), { syscall: 'rm' });
await assert.rejects(fs.promises.rm(dir, { recursive: false }), {
syscall: 'rm'
});

// Recursive removal should succeed.
await fs.promises.rm(dir, { recursive: true });

// Attempted removal should fail now because the directory is gone.
assert.rejects(fs.promises.rm(dir), { syscall: 'stat' });
await assert.rejects(fs.promises.rm(dir), { syscall: 'stat' });

// Should fail if target does not exist
assert.rejects(fs.promises.rm(
await assert.rejects(fs.promises.rm(
path.join(tmpdir.path, 'noexist.txt'),
{ recursive: true }
), {
Expand All @@ -207,7 +207,7 @@ function removeAsync(dir) {
});

// Should not fail if target does not exist and force option is true
fs.promises.rm(path.join(tmpdir.path, 'noexist.txt'), { force: true });
await fs.promises.rm(path.join(tmpdir.path, 'noexist.txt'), { force: true });

// Should delete file
const filePath = path.join(tmpdir.path, 'rm-promises-file.txt');
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-fs-rmdir-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ function removeAsync(dir) {
makeNonEmptyDirectory(4, 10, 2, dir, true);

// Removal should fail without the recursive option set to true.
assert.rejects(fs.promises.rmdir(dir), { syscall: 'rmdir' });
assert.rejects(fs.promises.rmdir(dir, { recursive: false }), {
await assert.rejects(fs.promises.rmdir(dir), { syscall: 'rmdir' });
await assert.rejects(fs.promises.rmdir(dir, { recursive: false }), {
syscall: 'rmdir'
});

Expand All @@ -154,7 +154,7 @@ function removeAsync(dir) {
{ code: 'ENOENT' });

// Attempted removal should fail now because the directory is gone.
assert.rejects(fs.promises.rmdir(dir), { syscall: 'rmdir' });
await assert.rejects(fs.promises.rmdir(dir), { syscall: 'rmdir' });
})().then(common.mustCall());

// Test input validation.
Expand Down

0 comments on commit 5e3f751

Please sign in to comment.