Skip to content

Commit 195345c

Browse files
committed
Add test image generation timeout
1 parent 5aa17cf commit 195345c

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

test/image/make_baseline.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ async def make_baselines_async():
8787
if mathjax is not None:
8888
kopts["mathjax"] = mathjax
8989

90+
# Per-mock timeout so a runaway render surfaces as a named failure instead
91+
# of hanging the whole shard until the runner times out.
92+
PER_MOCK_TIMEOUT_SECONDS = 60
93+
9094
async with kaleido.Kaleido(n=1, **kopts) as k:
9195
for name in allNames:
9296
outName = name
9397
if mathjax_version == 3:
9498
outName = "mathjax3___" + name
9599

96-
print(outName)
100+
print(outName, flush=True)
97101

98102
created = False
99103

@@ -124,23 +128,35 @@ async def make_baselines_async():
124128
print(json.dumps(fig, indent=2))
125129

126130
try:
127-
bytes = await k.calc_fig(
128-
fig,
129-
opts=dict(
130-
format="png",
131-
width=width,
132-
height=height,
131+
bytes = await asyncio.wait_for(
132+
k.calc_fig(
133+
fig,
134+
opts=dict(
135+
format="png",
136+
width=width,
137+
height=height,
138+
),
139+
topojson=topojson,
133140
),
134-
topojson=topojson,
141+
timeout=PER_MOCK_TIMEOUT_SECONDS,
135142
)
136143
filename = os.path.join(dirOut, outName + ".png")
137144
with open(filename, "wb") as f:
138145
f.write(bytes)
139146
created = True
147+
except asyncio.TimeoutError:
148+
print(
149+
f"timed out after {PER_MOCK_TIMEOUT_SECONDS}s",
150+
flush=True,
151+
)
152+
if attempt < MAX_RETRY:
153+
print("retry", attempt + 1, "/", MAX_RETRY, flush=True)
154+
else:
155+
failed.append(outName)
140156
except Exception as e:
141-
print(e)
157+
print(e, flush=True)
142158
if attempt < MAX_RETRY:
143-
print("retry", attempt + 1, "/", MAX_RETRY)
159+
print("retry", attempt + 1, "/", MAX_RETRY, flush=True)
144160
else:
145161
failed.append(outName)
146162

0 commit comments

Comments
 (0)