Commit a9bc22a9 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'sh-test-pg-9.6' into 'master'

Test PostgreSQL 9.6 and postgres_fdw with Geo specs

See merge request gitlab-org/gitlab-ee!3136
parents 39ff420b ef4f6064
......@@ -69,6 +69,12 @@ stages:
- redis:alpine
- docker.elastic.co/elasticsearch/elasticsearch:5.5.2
.use-pg-9-6: &use-pg-9-6
services:
- postgres:9.6
- redis:alpine
- docker.elastic.co/elasticsearch/elasticsearch:5.5.2
.use-mysql: &use-mysql
services:
- mysql:latest
......@@ -117,6 +123,17 @@ stages:
<<: *use-pg
<<: *except-docs
.rspec-geo-pg-9-6: &rspec-metadata-pg-geo
<<: *use-pg-9-6
<<: *except-docs
stage: test
script:
- export NO_KNAPSACK=1
- export CACHE_CLASSES=true
- source scripts/prepare_postgres_fdw.sh
- scripts/gitaly-test-spawn
- bundle exec rspec --color --format documentation --tag geo spec/
.rspec-metadata-mysql: &rspec-metadata-mysql
<<: *rspec-metadata
<<: *use-mysql
......@@ -338,6 +355,8 @@ rspec-pg 22 25: *rspec-metadata-pg
rspec-pg 23 25: *rspec-metadata-pg
rspec-pg 24 25: *rspec-metadata-pg
rspec-pg geo: *rspec-metadata-pg-geo
rspec-mysql 0 25: *rspec-metadata-mysql
rspec-mysql 1 25: *rspec-metadata-mysql
rspec-mysql 2 25: *rspec-metadata-mysql
......
......@@ -74,6 +74,18 @@ module Gitlab
GeoNode.where(host: host, port: port).exists?
end
def self.fdw?
self.cache_value(:geo_fdw?) do
::Geo::BaseRegistry.connection.execute(
"SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '#{self.fdw_schema}' AND table_type = 'FOREIGN TABLE'"
).first.fetch('count').to_i.positive?
end
end
def self.fdw_schema
'gitlab_secondary'.freeze
end
def self.repository_sync_job
Sidekiq::Cron::Job.find('geo_repository_sync_worker')
end
......
#!/bin/bash
psql -h postgres -U postgres gitlabhq_geo_test <<EOF
CREATE EXTENSION postgres_fdw;
CREATE SERVER gitlab_secondary FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host 'localhost', dbname 'gitlabhq_test');
CREATE USER MAPPING FOR current_user SERVER gitlab_secondary OPTIONS (user 'postgres', password '');
CREATE SCHEMA gitlab_secondary;
IMPORT FOREIGN SCHEMA public FROM SERVER gitlab_secondary INTO gitlab_secondary;
GRANT USAGE ON FOREIGN SERVER gitlab_secondary TO current_user;
EOF
require 'spec_helper'
describe Gitlab::Geo do
describe Gitlab::Geo, :geo do
include ::EE::GeoHelpers
set(:primary_node) { create(:geo_node, :primary) }
......@@ -18,6 +18,26 @@ describe Gitlab::Geo do
end
end
describe 'fdw?' do
let(:fdw_check) { "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'gitlab_secondary' AND table_type = 'FOREIGN TABLE'" }
before do
allow(::Geo::BaseRegistry.connection).to receive(:execute).with(anything).and_call_original
end
it 'returns true when PostgreSQL FDW is enabled' do
expect(::Geo::BaseRegistry.connection).to receive(:execute).with(fdw_check).and_return([{ 'count' => 1 }])
expect(described_class.fdw?).to be_truthy
end
it 'returns false when PostgreSQL FDW is not enabled' do
expect(::Geo::BaseRegistry.connection).to receive(:execute).with(fdw_check).and_return([{ 'count' => 0 }])
expect(described_class.fdw?).to be_falsey
end
end
describe 'primary?' do
context 'when current node is a primary node' do
it 'returns true' do
......
......@@ -181,6 +181,10 @@ RSpec.configure do |config|
example.run if Group.supports_nested_groups?
end
config.around(:each, :geo) do |example|
example.run if Gitlab::Database.postgresql?
end
config.around(:each, :postgresql) do |example|
example.run if Gitlab::Database.postgresql?
end
......
require 'spec_helper'
describe Geo::FileDownloadDispatchWorker, :postgresql do
describe Geo::FileDownloadDispatchWorker, :geo do
include ::EE::GeoHelpers
set(:primary) { create(:geo_node, :primary, host: 'primary-geo-node') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment