Skip to content

Commit

Permalink
test: clarify usage of tmpdir.refresh()
Browse files Browse the repository at this point in the history
This emphasizes that `tmpdir.refresh()` must be called only once in each
test file when needed.

PR-URL: #37383
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
RaisinTen authored and targos committed May 1, 2021
1 parent 51ef745 commit 776ef11
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -944,13 +944,18 @@ The realpath of the testing temporary directory.

Deletes and recreates the testing temporary directory.

The first time `refresh()` runs, it adds a listener to process `'exit'` that
The first time `refresh()` runs, it adds a listener to process `'exit'` that
cleans the temporary directory. Thus, every file under `tmpdir.path` needs to
be closed before the test completes. A good way to do this is to add a
listener to process `'beforeExit'`. If a file needs to be left open until
Node.js completes, use a child process and call `refresh()` only in the
parent.

It is usually only necessary to call `refresh()` once in a test file.
Avoid calling it more than once in an asynchronous context as one call
might refresh the temporary directory of a different context, causing
the test to fail somewhat mysteriously.

## UDP pair helper

The `common/udppair` module exports a function `makeUDPPair` and a class
Expand Down

0 comments on commit 776ef11

Please sign in to comment.