Skip to content

Unit tests: create one top-level temporary directory #12574

@laanwj

Description

@laanwj

Currently, every unit test that needs a temporary directory creates a directory directly under the system tmp path, /tmp/0df0-cbb9-e3f5-5753 and such. This gets cluttered really quickly, especially if tests fail to clean up. If a directory is left behind it can be tricky to find out which test is the culprit.

I would prefer creating one temporary directory at start of the entire framework, then creating directories under this with the name of the test and optional iteration number. E.g. /tmp/0df0-cbb9-e3f5-5753/dbwrapper_1. This makes it clear if tests leave behind junk, and facilitates cleanup.

Two different mechanisms are used currently for generating temporary directories:

  • pathTemp = fs::temp_directory_path() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(100000))) ()
  • fs::temp_directory_path() / fs::unique_path()

This would also be unified, then.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions