pgtk 0.7.4 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.rubocop.yml +4 -2
 - data/lib/pgtk/pgsql_task.rb +11 -2
 - data/lib/pgtk/pool.rb +1 -1
 - data/lib/pgtk/version.rb +1 -1
 - data/test/test_pool.rb +34 -0
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: b219dccbf16fe5c25e14e50419ec42b500ac9d62e940dde922549345ff263ead
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5b604cedbc33cc7e6945dc8747d218605109bd6c5f20b3fa009fb9f7d806c8a7
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f60a0d134a37cff5ccd1d45209121588950fa0a24ae885cdec78d65e1afb5f36f41c0714c2d7a9d16c9d5336f9a7b4b74c3bdeb5dabe4d2937d323307bd52733
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b5d85d743ab268a8213619ed5a44f6f84c8eed7b21953275bcd8cc57facbda71cd40b8dfac6c3c16d1ae41ee151dc5f4ce81276a92da5ec0d997b6d668117f27
         
     | 
    
        data/.rubocop.yml
    CHANGED
    
    | 
         @@ -16,10 +16,12 @@ Layout/EmptyLineAfterGuardClause: 
     | 
|
| 
       16 
16 
     | 
    
         
             
            Metrics/AbcSize:
         
     | 
| 
       17 
17 
     | 
    
         
             
              Max: 50
         
     | 
| 
       18 
18 
     | 
    
         
             
            Metrics/CyclomaticComplexity:
         
     | 
| 
       19 
     | 
    
         
            -
              Max:  
     | 
| 
      
 19 
     | 
    
         
            +
              Max: 12
         
     | 
| 
      
 20 
     | 
    
         
            +
            Metrics/ClassLength:
         
     | 
| 
      
 21 
     | 
    
         
            +
              Max: 120
         
     | 
| 
       20 
22 
     | 
    
         
             
            Metrics/MethodLength:
         
     | 
| 
       21 
23 
     | 
    
         
             
              Max: 100
         
     | 
| 
       22 
24 
     | 
    
         
             
            Metrics/PerceivedComplexity:
         
     | 
| 
       23 
     | 
    
         
            -
              Max:  
     | 
| 
      
 25 
     | 
    
         
            +
              Max: 12
         
     | 
| 
       24 
26 
     | 
    
         
             
            Metrics/ParameterLists:
         
     | 
| 
       25 
27 
     | 
    
         
             
              Max: 6
         
     | 
    
        data/lib/pgtk/pgsql_task.rb
    CHANGED
    
    | 
         @@ -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 =  
     | 
| 
      
 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  
     | 
| 
      
 142 
     | 
    
         
            +
                puts "PostgreSQL has been started in process ##{pid}, port #{port}"
         
     | 
| 
       134 
143 
     | 
    
         
             
              end
         
     | 
| 
       135 
144 
     | 
    
         
             
            end
         
     | 
    
        data/lib/pgtk/pool.rb
    CHANGED
    
    
    
        data/lib/pgtk/version.rb
    CHANGED
    
    
    
        data/test/test_pool.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            +
              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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-10-25 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: backtrace
         
     |