Skip to content

Start the chef-zero server on demand - #54

Open
tas50 wants to merge 1 commit into
chef:mainfrom
tas50:fix/lazy-chef-zero
Open

Start the chef-zero server on demand#54
tas50 wants to merge 1 commit into
chef:mainfrom
tas50:fix/lazy-chef-zero

Conversation

@tas50

@tas50 tas50 commented Aug 22, 2026

Copy link
Copy Markdown

Fixes chefspec#1017

Problem

Requiring chefspec pulls in ServerRunner, which pulls in ZeroServer, which registers:

RSpec.configure do |config|
  config.before(:suite) { ChefSpec::ZeroServer.setup! }
  config.after(:each) { ChefSpec::ZeroServer.reset! }

A chef-zero server therefore starts for every suite, including suites that only ever use the SoloRunner. That reserves one port from server_runner_port (default 8889..8899) for the whole run, so no more than 11 suites can run concurrently before they fail to find a free port. It also runs a data reset after every single example.

Measured on a suite that only uses platform and SoloRunner, before the change:

PID 98098 sees open ports: [8889, 8890]
PID 98100 sees open ports: [8889, 8890]

Fix

Start the server the first time something actually needs it, from upload_cookbooks!, load_data and the server accessor, and skip the per example reset while it is not running.

This is the third option the reporter suggested. It is not a breaking change: ServerRunner behavior is unchanged, and code that starts the server explicitly, as examples/server/spec/exotic_port_spec.rb does, still works.

Testing

Adds a no_server acceptance example asserting no chef-zero server is running for a SoloRunner only suite.

  • With the fix: 2 examples, 0 failures, and no ports bound
  • With the fix reverted: 2 examples, 1 failure
  • server acceptance example (all ServerRunner): 17 examples, 0 failures
  • Unit suite: 197 examples, 0 failures

@tas50
tas50 requested review from a team and jaymzh as code owners August 22, 2026 00:07
Requiring chefspec pulls in the ServerRunner, which registers a
before(:suite) hook that starts a chef-zero server for every suite, even
suites that only ever use the SoloRunner.

That reserves one port from the configured range for the whole run, so no
more than 11 suites can run concurrently with the default range before
they start failing to find a free port. It also runs a data reset after
every single example.

Start the server the first time something actually needs it, from the
cookbook upload, the data loader and the server accessor, and skip the
per example reset while it is not running. ServerRunner behavior is
unchanged.

Fixes chefspec#1017

Signed-off-by: Tim Smith <tsmith84@proton.me>
@tas50
tas50 force-pushed the fix/lazy-chef-zero branch from f4b639d to a3d2d11 Compare August 22, 2026 00:09
@tas50

tas50 commented Aug 22, 2026

Copy link
Copy Markdown
Author

CI on this PR is red for an unrelated reason: main's bundle cannot be installed on Linux, which breaks every job before any test runs. That is fixed separately in #56, which is green across Ruby 3.1 to 3.4. This PR should go green once #56 lands and this branch is rebased.

Locally, against a working bundle, this branch passes rake unit and the acceptance examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chefspec always starts a ZeroServer even if ServerRunner not used

1 participant