Skip to content

Commit e54de2b

Browse files
when reporting, only report according to the split containers
1 parent a192c99 commit e54de2b

File tree

2 files changed

+50
-33
lines changed

2 files changed

+50
-33
lines changed

choose_l10n_ci_set.py

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,48 +35,28 @@ def valid_l10n_mappings():
3535
return mapping
3636

3737

38-
def add_selected_mappings(mappings):
38+
def distribute_mappings_evenly(mappings, version):
3939
"""
4040
Write the selected mappings to the output file.
4141
4242
Args:
4343
mappings (dict): A dictionary of mappings, where the keys are sites and the values are sets of regions.
44+
version (int): The beta_version of the beta.
4445
"""
4546
if not mappings:
4647
return
4748
# sort the mappings by the length of the regions per site
4849
mappings = dict(sorted(mappings.items(), key=lambda val: len(val[1]), reverse=True))
4950
# place the mappings into 3 containers evenly according to the load
5051
loads = [0, 0, 0]
51-
containers = [[] for _ in range(3)]
52+
containers = [defaultdict(set) for _ in range(3)]
5253
for key, value in mappings.items():
5354
min_idx = loads.index(min(loads))
54-
containers[min_idx].append(f"{key} {' '.join(value)}")
55+
containers[min_idx][key] = value
5556
loads[min_idx] += len(value)
56-
# shuffle the containers so each run for a beta is random.
57-
random.shuffle(containers)
58-
try:
59-
version = int(
60-
(
61-
subprocess.check_output(
62-
[sys.executable, "./collect_executables.py", "-n"]
63-
)
64-
.strip()
65-
.decode()
66-
)
67-
.split("-")[0]
68-
.split(".")[1]
69-
.split("b")[1]
70-
)
71-
except ValueError:
72-
# failsafe version
73-
version = 0
74-
# get container index according to beta version
57+
# get container index according to beta beta_version
7558
run_idx = version % 3
76-
current_running_mappings = "\n".join(containers[run_idx])
77-
logging.warning(f"Running the mappings:\n{current_running_mappings}")
78-
with open(OUTPUT_FILE, "a+") as f:
79-
f.write(f"{current_running_mappings}\n")
59+
return containers[run_idx]
8060

8161

8262
def process_changed_file(f, selected_mappings):
@@ -107,6 +87,22 @@ def process_changed_file(f, selected_mappings):
10787
selected_mappings[site].add(region)
10888

10989

90+
def save_mappings(selected_container):
91+
"""
92+
Save the selected mappings to the output file.
93+
94+
Args:
95+
selected_container: the selected mappings container.
96+
"""
97+
98+
current_running_mappings = [
99+
f"{key} {' '.join(value)}\n" for key, value in selected_container.items()
100+
]
101+
logging.warning(f"Running the mappings:\n{''.join(current_running_mappings)}")
102+
with open(OUTPUT_FILE, "a+") as f:
103+
f.writelines(current_running_mappings)
104+
105+
110106
if __name__ == "__main__":
111107
if os.path.exists(".env"):
112108
with open(".env") as fh:
@@ -117,11 +113,27 @@ def process_changed_file(f, selected_mappings):
117113
os.environ["MANUAL"] = "true"
118114
with open(OUTPUT_FILE, "w") as file:
119115
pass # File is created or cleared
116+
try:
117+
beta_version = int(
118+
(
119+
subprocess.check_output(
120+
[sys.executable, "./collect_executables.py", "-n"]
121+
)
122+
.strip()
123+
.decode()
124+
)
125+
.split("-")[0]
126+
.split(".")[1]
127+
.split("b")[1]
128+
)
129+
except ValueError:
130+
# failsafe beta_version
131+
beta_version = 0
120132
l10n_mappings = valid_l10n_mappings()
121133
sample_mappings = {k: v for k, v in l10n_mappings.items() if k.startswith("demo")}
122134
if os.environ.get("TESTRAIL_REPORT") or os.environ.get("MANUAL"):
123135
# Run all tests if this is a scheduled beta or a manual run
124-
add_selected_mappings(l10n_mappings)
136+
save_mappings(distribute_mappings_evenly(l10n_mappings, beta_version))
125137
sys.exit(0)
126138

127139
re_set_all = [
@@ -182,5 +194,5 @@ def process_changed_file(f, selected_mappings):
182194
selected_mappings |= sample_mappings
183195
break
184196

185-
add_selected_mappings(selected_mappings)
197+
save_mappings(distribute_mappings_evenly(selected_mappings, beta_version))
186198
sys.exit(0)

modules/testrail_integration.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55
import sys
66

7-
from choose_l10n_ci_set import valid_l10n_mappings
7+
from choose_l10n_ci_set import distribute_mappings_evenly, valid_l10n_mappings
88
from modules import taskcluster as tc
99
from modules import testrail as tr
1010
from modules.testrail import TestRail
@@ -187,26 +187,31 @@ def reportable(platform_to_test=None):
187187

188188
plan_entries = this_plan.get("entries")
189189
if os.environ.get("FX_L10N"):
190-
l10n_mappings = valid_l10n_mappings()
190+
report = True
191+
beta_version = int(minor_num.split("b")[-1])
192+
distributed_mappings = distribute_mappings_evenly(
193+
valid_l10n_mappings(), beta_version
194+
)
191195
covered_mappings = 0
192196
# keeping this logic to still see how many mappings are reported.
193197
for entry in plan_entries:
194-
if entry.get("name") in l10n_mappings:
198+
if entry.get("name") in distributed_mappings:
199+
report = False
195200
site = entry.get("name")
196201
for run_ in entry.get("runs"):
197202
if run_.get("config"):
198203
run_region, run_platform = run_.get("config").split("-")
199204
covered_mappings += (
200205
1
201-
if run_region in l10n_mappings[site]
206+
if run_region in distributed_mappings[site]
202207
and platform in run_platform
203208
else 0
204209
)
205210
logging.warning(
206211
f"Potentially matching run found for {platform}, may be reportable. (Found {covered_mappings} site/region mappings reported.)"
207212
)
208213
# Only report when there is a new beta and no other site/region mappings are reported.
209-
return covered_mappings == 0
214+
return report or covered_mappings == 0
210215
else:
211216
covered_suites = 0
212217
for entry in plan_entries:

0 commit comments

Comments
 (0)