MCPcopy Create free account
hub / github.com/awslabs/aws-lambda-cpp / ShouldShard

Function ShouldShard

tests/gtest/gtest-all.cc:6845–6885  ·  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

6843// disabled because it must only be applied to the original test
6844// process. Otherwise, we could filter out death tests we intended to execute.
6845bool ShouldShard(const char* total_shards_env,
6846 const char* shard_index_env,
6847 bool in_subprocess_for_death_test) {
6848 if (in_subprocess_for_death_test) {
6849 return false;
6850 }
6851
6852 const Int32 total_shards = Int32FromEnvOrDie(total_shards_env, -1);
6853 const Int32 shard_index = Int32FromEnvOrDie(shard_index_env, -1);
6854
6855 if (total_shards == -1 && shard_index == -1) {
6856 return false;
6857 } else if (total_shards == -1 && shard_index != -1) {
6858 const Message msg = Message()
6859 << "Invalid environment variables: you have "
6860 << kTestShardIndex << " = " << shard_index
6861 << ", but have left " << kTestTotalShards << " unset.\n";
6862 ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str());
6863 fflush(stdout);
6864 exit(EXIT_FAILURE);
6865 } else if (total_shards != -1 && shard_index == -1) {
6866 const Message msg = Message()
6867 << "Invalid environment variables: you have "
6868 << kTestTotalShards << " = " << total_shards
6869 << ", but have left " << kTestShardIndex << " unset.\n";
6870 ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str());
6871 fflush(stdout);
6872 exit(EXIT_FAILURE);
6873 } else if (shard_index < 0 || shard_index >= total_shards) {
6874 const Message msg = Message()
6875 << "Invalid environment variables: we require 0 <= "
6876 << kTestShardIndex << " < " << kTestTotalShards
6877 << ", but you have " << kTestShardIndex << "=" << shard_index
6878 << ", " << kTestTotalShards << "=" << total_shards << ".\n";
6879 ColoredPrintf(COLOR_RED, "%s", msg.GetString().c_str());
6880 fflush(stdout);
6881 exit(EXIT_FAILURE);
6882 }
6883
6884 return total_shards > 1;
6885}
6886
6887// Parses the environment variable var as an Int32. If it is unset,
6888// returns default_val. If it is not an Int32, prints an error

Callers 2

OnTestIterationStartMethod · 0.85
RunAllTestsMethod · 0.85

Calls 4

Int32FromEnvOrDieFunction · 0.85
ColoredPrintfFunction · 0.85
GetStringMethod · 0.80
MessageFunction · 0.70

Tested by

no test coverage detected