MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / ShouldShard

Function ShouldShard

rtpose_wrapper/src/gtest/gtest-all.cpp:5606–5646  ·  view source on GitHub ↗

Checks whether sharding is enabled by examining the relevant environment variable values. If the variables are present, but inconsistent (i.e., shard_index >= total_shards), prints an error and exits. If in_subprocess_for_death_test, sharding is disabled because it must only be applied to the original test process. Otherwise, we could filter out death tests we intended to execute.

Source from the content-addressed store, hash-verified

5604// disabled because it must only be applied to the original test
5605// process. Otherwise, we could filter out death tests we intended to execute.
5606bool ShouldShard(const char* total_shards_env,
5607 const char* shard_index_env,
5608 bool in_subprocess_for_death_test) {
5609 if (in_subprocess_for_death_test) {
5610 return false;
5611 }
5612
5613 const Int32 total_shards = Int32FromEnvOrDie(total_shards_env, -1);
5614 const Int32 shard_index = Int32FromEnvOrDie(shard_index_env, -1);
5615
5616 if (total_shards == -1 && shard_index == -1) {
5617 return false;
5618 } else if (total_shards == -1 && shard_index != -1) {
5619 const Message msg = Message()
5620 << "Invalid environment variables: you have "
5621 << kTestShardIndex << " = " << shard_index
5622 << ", but have left " << kTestTotalShards << " unset.\n";
5623 ColoredPrintf(COLOR_RED, msg.GetString().c_str());
5624 fflush(stdout);
5625 exit(EXIT_FAILURE);
5626 } else if (total_shards != -1 && shard_index == -1) {
5627 const Message msg = Message()
5628 << "Invalid environment variables: you have "
5629 << kTestTotalShards << " = " << total_shards
5630 << ", but have left " << kTestShardIndex << " unset.\n";
5631 ColoredPrintf(COLOR_RED, msg.GetString().c_str());
5632 fflush(stdout);
5633 exit(EXIT_FAILURE);
5634 } else if (shard_index < 0 || shard_index >= total_shards) {
5635 const Message msg = Message()
5636 << "Invalid environment variables: we require 0 <= "
5637 << kTestShardIndex << " < " << kTestTotalShards
5638 << ", but you have " << kTestShardIndex << "=" << shard_index
5639 << ", " << kTestTotalShards << "=" << total_shards << ".\n";
5640 ColoredPrintf(COLOR_RED, msg.GetString().c_str());
5641 fflush(stdout);
5642 exit(EXIT_FAILURE);
5643 }
5644
5645 return total_shards > 1;
5646}
5647
5648// Parses the environment variable var as an Int32. If it is unset,
5649// returns default_val. If it is not an Int32, prints an error

Callers 2

OnTestIterationStartMethod · 0.85
RunAllTestsMethod · 0.85

Calls 3

Int32FromEnvOrDieFunction · 0.85
ColoredPrintfFunction · 0.85
MessageFunction · 0.70

Tested by

no test coverage detected