Skip to content

Commit

Permalink
Load more data in smoke spec and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shayonj committed Jul 2, 2023
1 parent 4e581a3 commit aaa3c1d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
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;
35 changes: 25 additions & 10 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 @@ -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

0 comments on commit aaa3c1d

Please sign in to comment.