Skip to content

Commit 0fd9f29

Browse files
committed
Fix agent tests + coverage for subprocesses
1 parent 9fe0579 commit 0fd9f29

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

mrq/agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def unpack(v):
294294
if total_jobs > total_greenlets and report_count == current_desired_count:
295295
desired_count = current_desired_count + 1
296296

297-
final_count = min(max(desired_count, profile["min_count"]), profile["max_count"])
297+
final_count = min(max(desired_count, profile.get("min_count", 0)), profile.get("max_count", 100))
298298

299299
if final_count != current_desired_count:
300300
log.debug("Autoscaling: Changing worker profile %s count from %s to %s" % (
@@ -397,7 +397,7 @@ def fetch_worker_group_definition(self):
397397
definition = connections.mongodb_jobs.mrq_workergroups.find_one({"_id": self.worker_group})
398398

399399
# Prepend all commands by their worker profile.
400-
for profileid, profile in definition.get("profiles", {}).items():
400+
for profileid, profile in (definition or {}).get("profiles", {}).items():
401401
profile["command"] = "MRQ_WORKER_PROFILE=%s %s" % (profileid, profile["command"])
402402

403403
return definition

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ def start(self, flush=True, deps=True, trace=True, agent=False, **kwargs):
158158
env = kwargs.get("env") or {}
159159
env.setdefault("MRQ_MAX_LATENCY", "0.1")
160160

161+
# Pass coverage-related environment variables
162+
for k, v in os.environ.items():
163+
if k.startswith("COV_"):
164+
env[k] = v
165+
161166
print(cmdline)
162167
ProcessFixture.start(self, cmdline=cmdline, env=env, expected_children=processes)
163168

tests/test_agent.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_orchestration_scenarios(worker):
4040
}
4141
]) == {
4242
"worker1": [
43-
"mrq-worker a"
43+
"MRQ_WORKER_PROFILE=a mrq-worker a"
4444
]
4545
}
4646

@@ -102,7 +102,11 @@ def test_orchestration_scenarios(worker):
102102
"desired_workers": ["mrq-worker c", "mrq-worker b", "mrq-worker b"]
103103
}
104104
]) == {
105-
"worker1": ["mrq-worker a", "mrq-worker a", "mrq-worker b"]
105+
"worker1": [
106+
"MRQ_WORKER_PROFILE=a mrq-worker a",
107+
"MRQ_WORKER_PROFILE=a mrq-worker a",
108+
"MRQ_WORKER_PROFILE=b mrq-worker b"
109+
]
106110
}
107111

108112
# Worker removal & add priority
@@ -132,8 +136,12 @@ def test_orchestration_scenarios(worker):
132136
"desired_workers": ["mrq-worker a", "mrq-worker a"]
133137
}
134138
]) == {
135-
"worker1": ["mrq-worker a", "mrq-worker a", "mrq-worker b"],
136-
"worker2": ["mrq-worker a"]
139+
"worker1": [
140+
"MRQ_WORKER_PROFILE=a mrq-worker a",
141+
"MRQ_WORKER_PROFILE=a mrq-worker a",
142+
"MRQ_WORKER_PROFILE=b mrq-worker b"
143+
],
144+
"worker2": ["MRQ_WORKER_PROFILE=a mrq-worker a"]
137145
}
138146

139147
worker.stop()

0 commit comments

Comments
 (0)