pgtk 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: baa19244cc0bb678a2a694232365acc92b72102ec96c2fe41f9a47d36487a0d3
4
- data.tar.gz: ea5749be062492fceb1fbac012f1b55c9b6a43991f3718e4d8b65e05bf67a0e4
3
+ metadata.gz: b219dccbf16fe5c25e14e50419ec42b500ac9d62e940dde922549345ff263ead
4
+ data.tar.gz: 5b604cedbc33cc7e6945dc8747d218605109bd6c5f20b3fa009fb9f7d806c8a7
5
5
  SHA512:
6
- metadata.gz: 706e072b93b40d26ae5efda68870cb6f9c59eaa0e0d13205a2be858871c4c1e1a487a4ff07384d68a80bd0ece19cee214d58631ddab51cd5c66c807907cd5512
7
- data.tar.gz: a92669230a4f7c92a0ededd321e795648a712f0f9951bc0e410ea89b782c1479156c1b4b8105b943e6eee5505121fd23f7e23d01a322053d7dc28214bd5c72d4
6
+ metadata.gz: f60a0d134a37cff5ccd1d45209121588950fa0a24ae885cdec78d65e1afb5f36f41c0714c2d7a9d16c9d5336f9a7b4b74c3bdeb5dabe4d2937d323307bd52733
7
+ data.tar.gz: b5d85d743ab268a8213619ed5a44f6f84c8eed7b21953275bcd8cc57facbda71cd40b8dfac6c3c16d1ae41ee151dc5f4ce81276a92da5ec0d997b6d668117f27
@@ -16,10 +16,12 @@ Layout/EmptyLineAfterGuardClause:
16
16
  Metrics/AbcSize:
17
17
  Max: 50
18
18
  Metrics/CyclomaticComplexity:
19
- Max: 10
19
+ Max: 12
20
+ Metrics/ClassLength:
21
+ Max: 120
20
22
  Metrics/MethodLength:
21
23
  Max: 100
22
24
  Metrics/PerceivedComplexity:
23
- Max: 10
25
+ Max: 12
24
26
  Metrics/ParameterLists:
25
27
  Max: 6
@@ -43,6 +43,7 @@ class Pgtk::PgsqlTask < Rake::TaskLib
43
43
  attr_accessor :dbname
44
44
  attr_accessor :yaml
45
45
  attr_accessor :quiet
46
+ attr_accessor :port
46
47
 
47
48
  def initialize(*args, &task_block)
48
49
  @name = args.shift || :pgsql
@@ -51,6 +52,7 @@ class Pgtk::PgsqlTask < Rake::TaskLib
51
52
  @user = 'test'
52
53
  @password = 'test'
53
54
  @dbname = 'test'
55
+ @port = nil
54
56
  unless ::Rake.application.last_description
55
57
  desc 'Start a local PostgreSQL server'
56
58
  end
@@ -88,8 +90,15 @@ class Pgtk::PgsqlTask < Rake::TaskLib
88
90
  )
89
91
  end
90
92
  raise unless $CHILD_STATUS.exitstatus.zero?
91
- port = RandomPort::Pool.new.acquire
93
+ port = @port
94
+ if port.nil?
95
+ port = RandomPort::Pool::SINGLETON.acquire
96
+ puts "Random TCP port #{port} is used"
97
+ else
98
+ puts "Required TCP port #{port} is used"
99
+ end
92
100
  pid = Process.spawn('postgres', '-k', home, '-D', home, "--port=#{port}")
101
+ IO.write(File.join(@dir, 'pid'), pid)
93
102
  at_exit do
94
103
  `kill -TERM #{pid}`
95
104
  puts "PostgreSQL killed in PID #{pid}"
@@ -130,6 +139,6 @@ class Pgtk::PgsqlTask < Rake::TaskLib
130
139
  }
131
140
  }.to_yaml
132
141
  )
133
- puts "PostgreSQL is running in PID #{pid}"
142
+ puts "PostgreSQL has been started in process ##{pid}, port #{port}"
134
143
  end
135
144
  end
@@ -165,7 +165,7 @@ class Pgtk::Pool
165
165
  begin
166
166
  yield conn
167
167
  rescue StandardError => e
168
- conn.close
168
+ conn.close unless conn.finished?
169
169
  conn = @wire.connection
170
170
  raise e
171
171
  ensure
@@ -28,5 +28,5 @@ require_relative '../pgtk'
28
28
  # License:: MIT
29
29
  module Pgtk
30
30
  # Current version of the library.
31
- VERSION = '0.7.4'
31
+ VERSION = '0.7.5'
32
32
  end
@@ -80,6 +80,40 @@ class TestPool < Minitest::Test
80
80
  end
81
81
  end
82
82
 
83
+ def test_reconnects_on_pg_reboot
84
+ port = RandomPort::Pool::SINGLETON.acquire
85
+ Dir.mktmpdir 'test' do |dir|
86
+ id = rand(100..999)
87
+ Pgtk::PgsqlTask.new("pgsql#{id}") do |t|
88
+ t.dir = File.join(dir, 'pgsql')
89
+ t.user = 'hello'
90
+ t.password = 'A B C привет ! & | !'
91
+ t.dbname = 'test'
92
+ t.yaml = File.join(dir, 'cfg.yml')
93
+ t.quiet = true
94
+ t.fresh_start = true
95
+ t.port = port
96
+ end
97
+ task = Rake::Task["pgsql#{id}"]
98
+ task.invoke
99
+ pool = Pgtk::Pool.new(
100
+ Pgtk::Wire::Yaml.new(File.join(dir, 'cfg.yml')),
101
+ log: Loog::VERBOSE
102
+ )
103
+ pool.start(1)
104
+ pool.exec('SELECT * FROM pg_catalog.pg_tables')
105
+ pid = IO.read(File.join(dir, 'pgsql/pid')).to_i
106
+ `kill -KILL #{pid}`
107
+ sleep 1
108
+ task.reenable
109
+ task.invoke
110
+ assert_raises PG::UnableToSend do
111
+ pool.exec('SELECT * FROM pg_catalog.pg_tables')
112
+ end
113
+ pool.exec('SELECT * FROM pg_catalog.pg_tables')
114
+ end
115
+ end
116
+
83
117
  private
84
118
 
85
119
  def bootstrap
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-20 00:00:00.000000000 Z
11
+ date: 2019-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace