11# frozen_string_literal: true
22
3+ require 'English'
34def log ( msg )
45 puts "======= #{ msg } ======="
56end
67
78def setup_pgbench_tables ( foreign_keys :)
89 log ( "Setting up pgbench" )
910 if foreign_keys
10- `pgbench --initialize -s 10 --foreign-keys --host #{ client . host } -U #{ client . username } -d #{ client . dbname } `
11+ `pgbench --initialize -s 100 --foreign-keys --host #{ client . host } -U #{ client . username } -d #{ client . dbname } `
1112 else
12- `pgbench --initialize -s 10 --host #{ client . host } -U #{ client . username } -d #{ client . dbname } `
13+ `pgbench --initialize -s 100 --host #{ client . host } -U #{ client . username } -d #{ client . dbname } `
1314 end
1415
1516 log ( "Setting up pgbench validate table" )
@@ -66,13 +67,13 @@ def setup_pgbench_tables(foreign_keys:)
6667 expect_query_result (
6768 connection : client . connection ,
6869 query : "select count(*) from pgbench_accounts" ,
69- assertions : [ { count : 1 , data : [ { "count" => "1000000 " } ] } ] ,
70+ assertions : [ { count : 1 , data : [ { "count" => "10000000 " } ] } ] ,
7071 )
7172
7273 expect_query_result (
7374 connection : client . connection ,
7475 query : "select count(*) from pgbench_accounts_validate" ,
75- assertions : [ { count : 1 , data : [ { "count" => "1000000 " } ] } ] ,
76+ assertions : [ { count : 1 , data : [ { "count" => "10000000 " } ] } ] ,
7677 )
7778 end
7879
@@ -81,23 +82,29 @@ def setup_pgbench_tables(foreign_keys:)
8182 fork do
8283 log ( "Running pgbench" )
8384 exec (
84- "pgbench --file spec/fixtures/bench.sql -T 60000 -c 5 --host #{ client . host } -U #{ client . username } -d #{ client . dbname } " ,
85+ "pgbench --file spec/fixtures/bench.sql -T 600000 -c 15 --host #{ client . host } -U #{ client . username } -d #{ client . dbname } " ,
8586 )
8687 end
8788 Process . detach ( pid )
89+ sleep ( 10 )
8890
8991 log ( "Running pg-osc" )
9092 statement = <<~SCRIPT
91- PGPASSWORD="#{ client . password } " bundle exec bin/pg-online-schema-change perform \
93+ PGPASSWORD="#{ client . password } " DEBUG=true bundle exec bin/pg-online-schema-change perform \
9294 -a 'ALTER TABLE pgbench_accounts ALTER COLUMN aid TYPE BIGINT' \
9395 -d #{ client . dbname } \
9496 -h #{ client . host } \
9597 -u #{ client . username } \
9698 --drop
9799 SCRIPT
98- result = `#{ statement } `
100+ IO . popen ( statement ) do |io |
101+ io . each do |line |
102+ puts line
103+ output << line
104+ end
105+ end
99106
100- expect ( result ) . to match ( /All tasks successfully completed/ )
107+ expect ( output . join ( "," ) ) . to match ( /All tasks successfully completed/ )
101108 Process . kill ( "KILL" , pid )
102109
103110 log ( "Comparing data between two tables" )
@@ -137,23 +144,31 @@ def setup_pgbench_tables(foreign_keys:)
137144 fork do
138145 log ( "Running pgbench" )
139146 exec (
140- "pgbench --file spec/fixtures/bench.sql -T 60000 -c 5 --host #{ client . host } -U #{ client . username } -d #{ client . dbname } " ,
147+ "pgbench --file spec/fixtures/bench.sql -T 600000 -c 15 --host #{ client . host } -U #{ client . username } -d #{ client . dbname } >/dev/null 2>&1 " ,
141148 )
142149 end
143150 Process . detach ( pid )
144151
152+ sleep ( 10 )
153+
145154 log ( "Running pg-osc" )
146155 statement = <<~SCRIPT
147- PGPASSWORD="#{ client . password } " bundle exec bin/pg-online-schema-change perform \
156+ PGPASSWORD="#{ client . password } " DEBUG=true bundle exec bin/pg-online-schema-change perform \
148157 -a 'ALTER TABLE pgbench_accounts ALTER COLUMN aid TYPE BIGINT' \
149158 -d #{ client . dbname } \
150159 -h #{ client . host } \
151160 -u #{ client . username } \
152161 --drop
153162 SCRIPT
154- result = `#{ statement } `
163+ output = [ ]
164+ IO . popen ( statement ) do |io |
165+ io . each do |line |
166+ puts line
167+ output << line
168+ end
169+ end
155170
156- expect ( result ) . to match ( /All tasks successfully completed/ )
171+ expect ( output . join ( "," ) ) . to match ( /All tasks successfully completed/ )
157172 Process . kill ( "KILL" , pid )
158173
159174 log ( "Comparing data between two tables" )
0 commit comments