Skip to content

Commit 412ec28

Browse files
Resize execution context for spec with CRYSTAL_WORKERS (#16444)
When running specs with execution contexts, it's annoying to have to explicitly scale the default execution context in order to get actual parallelism. This could be handled in some kind of spec helper, but it would still require extra effort, and it'd be easy to miss out on it. Thus we resize the EC in the stdlib `spec` package (i.e. for _any_ spec program) if the environment variable `CRYSTAL_WORKERS` is defined.
1 parent 7bdbd04 commit 412ec28

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/spec.cr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ module Spec
130130
Process.on_terminate { abort! }
131131
{% end %}
132132

133+
{% if flag?(:execution_context) %}
134+
if count = ENV["CRYSTAL_WORKERS"]?.try(&.to_i?)
135+
Fiber::ExecutionContext.current.resize(count)
136+
end
137+
{% end %}
138+
133139
run
134140
end
135141
end

0 commit comments

Comments
 (0)