Skip to content

Instantly share code, notes, and snippets.

@acoulton
Last active August 11, 2017 12:08
Show Gist options
  • Save acoulton/14d2ce1ad0d476a89edcab61333da1a9 to your computer and use it in GitHub Desktop.
Save acoulton/14d2ce1ad0d476a89edcab61333da1a9 to your computer and use it in GitHub Desktop.
Reproduction case for slow chefignore performance
#!/bin/bash
# This case verifies that chefignore is not processed efficiently, causing slow chefspec runs (among other things
# when large build-time directories are present).
#
# * Download and unpack this gist to a directory with at least one empty directory above - eg /tmp/chef/slow-chef
# * cd /tmp/chef/slow-chef
# * chmod +x _testcase.sh
# * ./_testcase.sh
#
# Observe that once vendor directory is present, even with a chefignore, the runtime increases dramatically (around
# 180 times slower on my machine)
set -o errexit
# Move stuff to the right place because of gist limitations
if [ ! -d spec ]; then
mkdir spec
fi
if [ ! -d recipes ]; then
mkdir recipes
fi
cp recipes_default.rb recipes/default.rb
cp spec_spec_helper.rb spec/spec_helper.rb
cp spec_default_spec.rb spec/default_spec.rb
# Cleanup any previous test
rm -f chefignore
rm -rf vendor
rm -f Gemfile.lock
echo "Installing gems"
bundle install --path="/tmp/cheftest-gems" > /dev/null
echo "With no local vendors"
time bundle exec rspec
mkdir vendor
rsync -a /tmp/cheftest-gems/ vendor/bundle
echo "With local vendors and no chefignore - expected to be slow"
time bundle exec rspec
echo "With local vendors chefignored - should be faster"
echo "vendor" > chefignore
echo "vendor/*" >> chefignore
time bundle exec rspec
source 'https://rubygems.org'
gem 'chefspec', '~> 7.0'
gem 'chef', '~>13.2'
name 'slow-chef'
require 'spec_helper'
describe 'slow-chef::default' do
let (:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) }
it 'converges once' do
chef_run
end
it 'converges twice' do
chef_run
end
end
require 'chefspec'
RSpec.configure do | c |
c.platform = 'ubuntu'
c.version = '14.04'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment