[experiments] Add support for testing disabling already enabled experiments (#30831)

pull/30076/head
Craig Tiller 3 years ago committed by GitHub
parent 2d7ebdb5fd
commit 6ee7a647bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      bazel/experiments.bzl
  2. 29
      bazel/grpc_build_system.bzl
  3. 17
      tools/codegen/core/gen_experiments.py

@ -28,3 +28,6 @@ EXPERIMENTS = {
"tcp_read_chunks",
],
}
NEGATED_EXPERIMENTS = {
}

@ -29,7 +29,7 @@ Contains macros used throughout the repo.
load("//bazel:cc_grpc_library.bzl", "cc_grpc_library")
load("//bazel:copts.bzl", "GRPC_DEFAULT_COPTS")
load("//bazel:experiments.bzl", "EXPERIMENTS")
load("//bazel:experiments.bzl", "EXPERIMENTS", "NEGATED_EXPERIMENTS")
load("@upb//bazel:upb_proto_library.bzl", "upb_proto_library", "upb_proto_reflection_library")
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test")
load("@build_bazel_rules_apple//apple/testing/default_runner:ios_test_runner.bzl", "ios_test_runner")
@ -336,6 +336,14 @@ def expand_tests(name, srcs, deps, tags, args, exclude_pollers, uses_event_engin
experiments[experiment] = 1
experiments = list(experiments.keys())
negated_experiments = {}
for tag in tags:
if tag not in NEGATED_EXPERIMENTS:
continue
for experiment in NEGATED_EXPERIMENTS[tag]:
negated_experiments[experiment] = 1
negated_experiments = list(negated_experiments.keys())
experiment_config = list(poller_config)
for experiment in experiments:
for config in poller_config:
@ -356,6 +364,25 @@ def expand_tests(name, srcs, deps, tags, args, exclude_pollers, uses_event_engin
tags = tags + [tag]
config["tags"] = tags
experiment_config.append(config)
for experiment in negated_experiments:
for config in poller_config:
config = dict(config)
config["name"] = config["name"] + "@experiment=no_" + experiment
config["args"] = config["args"] + ["--experiment=-" + experiment]
tags = config["tags"]
must_have_tags = [
# We don't run experiments on cmake builds
"bazel_only",
# Nor on windows
"no_windows",
# Nor on mac
"no_mac",
]
for tag in must_have_tags:
if tag not in tags:
tags = tags + [tag]
config["tags"] = tags
experiment_config.append(config)
return experiment_config

@ -187,9 +187,14 @@ with open('src/core/lib/experiments/experiments.cc', 'w') as C:
print("} // namespace grpc_core", file=C)
tags_to_experiments = collections.defaultdict(list)
tags_to_negated_experiments = collections.defaultdict(list)
for attr in attrs:
for tag in attr['test_tags']:
tags_to_experiments[tag].append(attr['name'])
if attr['default']:
for tag in attr['test_tags']:
tags_to_negated_experiments[tag].append(attr['name'])
else:
for tag in attr['test_tags']:
tags_to_experiments[tag].append(attr['name'])
with open('bazel/experiments.bzl', 'w') as B:
put_copyright(B, "#")
@ -211,3 +216,11 @@ with open('bazel/experiments.bzl', 'w') as B:
print(" \"%s\"," % experiment, file=B)
print(" ],", file=B)
print("}", file=B)
print(file=B)
print("NEGATED_EXPERIMENTS = {", file=B)
for tag, experiments in sorted(tags_to_negated_experiments.items()):
print(" \"%s\": [" % tag, file=B)
for experiment in sorted(experiments):
print(" \"%s\"," % experiment, file=B)
print(" ],", file=B)
print("}", file=B)

Loading…
Cancel
Save