From a6ff6ab353b3834744c0a91a02c9a6c8c63fbedb Mon Sep 17 00:00:00 2001 From: Rebekah Davis Date: Fri, 9 Aug 2024 16:19:36 -0400 Subject: [PATCH] Fix transient failures in unit_seedable_global_PRNG. --- .../test/unit_random_label_generator.cc | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/tiledb/common/random/test/unit_random_label_generator.cc b/tiledb/common/random/test/unit_random_label_generator.cc index 529608a42ed..e7a69b54d95 100644 --- a/tiledb/common/random/test/unit_random_label_generator.cc +++ b/tiledb/common/random/test/unit_random_label_generator.cc @@ -28,6 +28,8 @@ * Tests for the random label generator. */ +#include + #include #include "../random_label.h" @@ -36,8 +38,8 @@ using namespace tiledb::sm; size_t generate_labels(std::vector& labels) { size_t labels_size = labels.size(); - auto now = utils::time::timestamp_now_ms(); size_t idx = 0; + auto now = utils::time::timestamp_now_ms(); while ((utils::time::timestamp_now_ms()) < now + 100 && idx < labels_size) { labels[idx++] = random_label(); } @@ -46,21 +48,34 @@ size_t generate_labels(std::vector& labels) { } void validate_labels(std::vector& labels, size_t num_labels) { - // Given the label randomness and the fact that we're racing the processor, - // the best we can do here (for now) is assert that there's 10 ordered groups. - // In this manner, groups are defined as sharing the first 4 bytes. + /** + * When creating a random label, ordering is determined by the first 8 bytes. + * In this test, we are assuming the buffer overflow check works as expected, + * and no more than 16^8 labels are generated within a single millisecond. + * + * Given the label randomness, and the fact that we're racing the processor, + * the best we can do here (for now) is assert that there's at least 100 + * ordered groups, as `generate_labels` generates approximately 100 labels per + * timestamp. + * + * A group is defined as sharing the first _n_ bytes, where n is calculated + * as the lowest number of bytes within the 8-byte counter which can contain + * the given num_labels. + */ + + size_t group_delimeter = ceil(log(num_labels) / log(16)); uint64_t num_groups = 0; uint64_t this_group = 0; for (size_t i = 1; i < num_labels; i++) { bool match = true; - for (size_t j = 0; j < 4; j++) { + for (size_t j = 0; j < group_delimeter; j++) { if (labels[i - 1][j] != labels[i][j]) { match = false; break; } } if (!match) { - if (this_group > 10) { + if (this_group > 100) { num_groups += 1; } this_group = 0; @@ -72,7 +87,7 @@ void validate_labels(std::vector& labels, size_t num_labels) { this_group += 1; } - REQUIRE(num_groups > 10); + REQUIRE(num_groups > 100); } TEST_CASE(