module-postgresql/spec/unit/classes/server_spec.rb
Ken Barber 5df36cf1f7 (GH-198) Fix race condition on postgresql startup
This patch is a fix for the race condition that keeps occuring during
postgresql setup. Its very rare on its own, but when you are using this
module in a CI environment it happens quite frequently.

Basically what happens is that sometimes the service will announce the
database has started, but really it is still working in the background.
Sometimes the unix socket may not be listening, and sometimes the
system is still loading and you get a weird client error.

The fix itself is a modification to postgresql::validate_db_connection
so that it is able to connect on the local unix socket, plus retry
until the database is available.

This new and improved validate_db_connection can then be put into the
build pipeline (in the service class in particular) to ensure the
database is started before continuing on with the remaining steps.

This in effect blocks the puppet module from continuing until the
postgresql database is fully started and able to receive connections
which is perfect.

Tests and documentation provided.

Signed-off-by: Ken Barber <ken@bob.sh>
2013-10-24 00:33:45 +01:00

93 lines
2 KiB
Ruby

require 'spec_helper'
describe 'postgresql::server', :type => :class do
let :facts do
{
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6.0',
:concat_basedir => tmpfilename('server'),
:kernel => 'Linux',
}
end
describe 'with no parameters' do
it { should include_class("postgresql::params") }
it { should include_class("postgresql::server") }
it 'should validate connection' do
should contain_postgresql__validate_db_connection('validate_service_is_running')
end
end
describe 'manage_firewall => true' do
let(:params) do
{
:manage_firewall => true,
:ensure => true,
}
end
it 'should create firewall rule' do
should contain_firewall("5432 accept - postgres")
end
end
describe 'ensure => absent' do
let(:params) do
{
:ensure => 'absent',
:datadir => '/my/path',
}
end
it 'should make package purged' do
should contain_package('postgresql-server').with({
:ensure => 'purged',
})
end
it 'stop the service' do
should contain_service('postgresqld').with({
:ensure => false,
})
end
it 'should remove datadir' do
should contain_file('/my/path').with({
:ensure => 'absent',
})
end
end
describe 'package_ensure => absent' do
let(:params) do
{
:package_ensure => 'absent',
}
end
it 'should remove the package' do
should contain_package('postgresql-server').with({
:ensure => 'purged',
})
end
it 'should still enable the service' do
should contain_service('postgresqld').with({
:ensure => true,
})
end
end
describe 'needs_initdb => true' do
let(:params) do
{
:needs_initdb => true,
}
end
it 'should contain proper initdb exec' do
should contain_exec('postgresql_initdb')
end
end
end