Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load more data in smoke spec and cleanup #96

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version: "2"
services:
postgres:
image: postgres:9.6.2-alpine
image: postgres:14-alpine
ports:
- "5432:5432"
environment:
POSTGRES_USER: jamesbond
POSTGRES_DB: postgres
POSTGRES_HOST_AUTH_METHOD: trust
6 changes: 3 additions & 3 deletions spec/fixtures/bench.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BEGIN;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
UPDATE pgbench_accounts_validate SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
-- UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
-- UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
END;
END;
39 changes: 27 additions & 12 deletions spec/lib/smoke_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# frozen_string_literal: true

require 'English'
def log(msg)
puts "======= #{msg} ======="
end

def setup_pgbench_tables(foreign_keys:)
log("Setting up pgbench")
if foreign_keys
`pgbench --initialize -s 10 --foreign-keys --host #{client.host} -U #{client.username} -d #{client.dbname}`
`pgbench --initialize -s 100 --foreign-keys --host #{client.host} -U #{client.username} -d #{client.dbname}`
else
`pgbench --initialize -s 10 --host #{client.host} -U #{client.username} -d #{client.dbname}`
`pgbench --initialize -s 100 --host #{client.host} -U #{client.username} -d #{client.dbname}`
end

log("Setting up pgbench validate table")
Expand Down Expand Up @@ -66,13 +67,13 @@ def setup_pgbench_tables(foreign_keys:)
expect_query_result(
connection: client.connection,
query: "select count(*) from pgbench_accounts",
assertions: [{ count: 1, data: [{ "count" => "1000000" }] }],
assertions: [{ count: 1, data: [{ "count" => "10000000" }] }],
)

expect_query_result(
connection: client.connection,
query: "select count(*) from pgbench_accounts_validate",
assertions: [{ count: 1, data: [{ "count" => "1000000" }] }],
assertions: [{ count: 1, data: [{ "count" => "10000000" }] }],
)
end

Expand All @@ -81,23 +82,29 @@ def setup_pgbench_tables(foreign_keys:)
fork do
log("Running pgbench")
exec(
"pgbench --file spec/fixtures/bench.sql -T 60000 -c 5 --host #{client.host} -U #{client.username} -d #{client.dbname}",
"pgbench --file spec/fixtures/bench.sql -T 600000 -c 15 --host #{client.host} -U #{client.username} -d #{client.dbname}",
)
end
Process.detach(pid)
sleep(10)

log("Running pg-osc")
statement = <<~SCRIPT
PGPASSWORD="#{client.password}" bundle exec bin/pg-online-schema-change perform \
PGPASSWORD="#{client.password}" DEBUG=true bundle exec bin/pg-online-schema-change perform \
-a 'ALTER TABLE pgbench_accounts ALTER COLUMN aid TYPE BIGINT' \
-d #{client.dbname} \
-h #{client.host} \
-u #{client.username} \
--drop
SCRIPT
result = `#{statement}`
IO.popen(statement) do |io|
io.each do |line|
puts line
output << line
end
end

expect(result).to match(/All tasks successfully completed/)
expect(output.join(",")).to match(/All tasks successfully completed/)
Process.kill("KILL", pid)

log("Comparing data between two tables")
Expand Down Expand Up @@ -137,23 +144,31 @@ def setup_pgbench_tables(foreign_keys:)
fork do
log("Running pgbench")
exec(
"pgbench --file spec/fixtures/bench.sql -T 60000 -c 5 --host #{client.host} -U #{client.username} -d #{client.dbname}",
"pgbench --file spec/fixtures/bench.sql -T 600000 -c 15 --host #{client.host} -U #{client.username} -d #{client.dbname} >/dev/null 2>&1",
)
end
Process.detach(pid)

sleep(10)

log("Running pg-osc")
statement = <<~SCRIPT
PGPASSWORD="#{client.password}" bundle exec bin/pg-online-schema-change perform \
PGPASSWORD="#{client.password}" DEBUG=true bundle exec bin/pg-online-schema-change perform \
-a 'ALTER TABLE pgbench_accounts ALTER COLUMN aid TYPE BIGINT' \
-d #{client.dbname} \
-h #{client.host} \
-u #{client.username} \
--drop
SCRIPT
result = `#{statement}`
output = []
IO.popen(statement) do |io|
io.each do |line|
puts line
output << line
end
end

expect(result).to match(/All tasks successfully completed/)
expect(output.join(",")).to match(/All tasks successfully completed/)
Process.kill("KILL", pid)

log("Comparing data between two tables")
Expand Down