Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified temp dir builder #1529

Merged
merged 15 commits into from
Feb 27, 2024
Merged

Unified temp dir builder #1529

merged 15 commits into from
Feb 27, 2024

Conversation

Alenar
Copy link
Collaborator

@Alenar Alenar commented Feb 23, 2024

Content

This PR add an api to generate temp directory in mithril_common test_tools.

It can be used in two ways:

  1. In it's complete form it's a builder pattern, use that to access all of its options:
let temp_dir = TempDir::new("module", "name")
    .generate_shorter_path()
    .set_short_path_max_len(80)
    .build();
  1. Using shortcuts methods
let temp_dir = TempDir::create("module", "name");
let shorter_temp_dir = TempDir::create_with_short_path("module", "name");

With short path disabled (the default) the path generated is in the form of

  • linux: /tmp/mithril_test/$module/$name
  • macOS: /var/folders/_k/7j0m5c_n4g94vgx9gxknp4tm0000gn/T/mithril_test/$module/$name.

Shorter path are generated by not including a subfolder with the module but instead appending the first 10 characters of the sha256 hash of both the module & name. If even with that the path total length is longer than the short_path_max_len then the name is truncated as much as needed.

Example with the temp dir for pallas_observer::test::get_current_stake_distribution_with_fallback:

  • linux: /tmp/mithril_test/get_current_stake_distribution_with_fallback_5446f30db1
  • macOS: /var/folders/_k/7j0m5c_n4g94vgx9gxknp4tm0000gn/T/mithril_test/get_current_stake_5446f30db1.

In both cases if an a directory already exists with the same path it is removed alongside it's content.

Pre-submit checklist

  • Branch
    • Tests are provided (if possible)
    • Crates versions are updated (if relevant)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
  • PR
    • No clippy warnings in the CI
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

Issue(s)

Closes #1508

Copy link

github-actions bot commented Feb 23, 2024

Test Results

  3 files  ±0   42 suites  ±0   8m 22s ⏱️ +2s
871 tests +7  871 ✅ +7  0 💤 ±0  0 ❌ ±0 
960 runs  +7  960 ✅ +7  0 💤 ±0  0 ❌ ±0 

Results for commit 5f40284. ± Comparison against base commit 0451ff1.

This pull request removes 1 and adds 8 tests. Note that renamed tests count towards both.
mithril-client-cli ‑ commands::snapshot::download::tests::verify_snapshot_signature_should_remove_db_dir_if_messages_dismatch
mithril-client-cli ‑ commands::snapshot::download::tests::verify_snapshot_signature_should_remove_db_dir_if_messages_mismatch
mithril-common ‑ test_utils::temp_dir::tests::creating_temp_dir_remove_existing_content
mithril-common ‑ test_utils::temp_dir::tests::non_short_path_are_in_a_mithril_test_slash_module_folder_structure
mithril-common ‑ test_utils::temp_dir::tests::same_name_but_two_different_module_generate_different_path
mithril-common ‑ test_utils::temp_dir::tests::same_name_but_two_different_module_generate_different_path_even_with_short_path_enabled
mithril-common ‑ test_utils::temp_dir::tests::short_path_are_in_a_mithril_test_folder_structure
mithril-common ‑ test_utils::temp_dir::tests::shorter_path_have_a_length_lower_than_90_chars_even_when_given_module_longer_than_that
mithril-common ‑ test_utils::temp_dir::tests::shorter_path_have_a_length_lower_than_90_chars_even_when_given_name_longer_than_that

♻️ This comment has been updated with latest results.

@Alenar Alenar temporarily deployed to testing-preview February 23, 2024 17:01 — with GitHub Actions Inactive
@Alenar Alenar temporarily deployed to testing-sanchonet February 23, 2024 17:01 — with GitHub Actions Inactive
Copy link
Collaborator

@dlachaume dlachaume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Member

@jpraynaud jpraynaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

I left few comments/questions below.

mithril-common/src/test_utils/temp_dir.rs Outdated Show resolved Hide resolved
mithril-common/src/test_utils/temp_dir.rs Outdated Show resolved Hide resolved
mithril-common/src/test_utils/temp_dir.rs Outdated Show resolved Hide resolved
@Alenar Alenar force-pushed the djo/1508/unified_temp_dir_builder branch from c6f512b to 5f40284 Compare February 27, 2024 08:49
@Alenar Alenar temporarily deployed to testing-preview February 27, 2024 09:00 — with GitHub Actions Inactive
@Alenar Alenar temporarily deployed to testing-sanchonet February 27, 2024 09:00 — with GitHub Actions Inactive
@Alenar Alenar merged commit 174bc5f into main Feb 27, 2024
40 of 46 checks passed
@Alenar Alenar deleted the djo/1508/unified_temp_dir_builder branch February 27, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify test folder generation
4 participants