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

Fix transient failures in unit_seedable_global_PRNG. #5234

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions tiledb/common/random/test/unit_random_label_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* Tests for the random label generator.
*/

#include <math.h>

#include <test/support/tdb_catch.h>
#include "../random_label.h"

Expand All @@ -36,8 +38,8 @@ using namespace tiledb::sm;

size_t generate_labels(std::vector<std::string>& 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();
}
Expand All @@ -46,21 +48,34 @@ size_t generate_labels(std::vector<std::string>& labels) {
}

void validate_labels(std::vector<std::string>& 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;
Expand All @@ -72,7 +87,7 @@ void validate_labels(std::vector<std::string>& labels, size_t num_labels) {
this_group += 1;
}

REQUIRE(num_groups > 10);
REQUIRE(num_groups > 100);
}

TEST_CASE(
Expand Down
Loading