green-em-pg 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,7 +20,7 @@ GEM
20
20
  debugger-linecache (1.1.2)
21
21
  debugger-ruby_core_source (>= 1.1.1)
22
22
  debugger-ruby_core_source (1.1.7)
23
- em-pg (0.1.1)
23
+ em-pg (0.1.2)
24
24
  eventmachine (>= 0.12)
25
25
  pg (>= 0.14)
26
26
  eventmachine (1.0.0)
@@ -1,7 +1,7 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'green-em-pg'
3
- s.version = '0.1.0'
4
- s.date = '2013-01-28'
3
+ s.version = '0.1.1'
4
+ s.date = '2013-01-30'
5
5
  s.summary = 'Async PostgreSQL client API for Ruby/EventMachine'
6
6
  s.email = "ceo@prepor.ru"
7
7
  s.homepage = "http://github.com/prepor/em-postgres"
@@ -3,7 +3,7 @@ require 'em/pg'
3
3
  class Green
4
4
  module EM
5
5
  class PG < ::EM::PG
6
- VERSION = "0.1.0"
6
+ VERSION = "0.1.1"
7
7
  def self.new(*args)
8
8
  Green.hub # ensure started green hub
9
9
  db = allocate
@@ -38,6 +38,8 @@ class Green
38
38
 
39
39
  def_delegators :@pg, :status, :escape_string, :escape_bytea
40
40
 
41
+ CONNECTION_OK = ::PG::CONNECTION_OK
42
+
41
43
  class << self
42
44
  alias :connect :new
43
45
  end
@@ -55,6 +57,10 @@ class Green
55
57
  # alias :exec_prepared :send_query_prepared
56
58
  # alias :finish :close
57
59
 
60
+ def block
61
+ true
62
+ end
63
+
58
64
  [:get_copy_data, :put_copy_data, :put_copy_end, :get_result, :wait_for_notify].each do |m|
59
65
  define_method(m) do |*args|
60
66
  raise "Unimplemented method #{m} in green postgres adapter"
@@ -12,53 +12,59 @@ describe Green::EM::PG do
12
12
  let(:db) { Sequel.connect(url, max_connection: size, pool_class: Green::EM::PG::Sequel::ConnectionPool, db_logger: Logger.new(nil)) }
13
13
  let(:test) { db[:test] }
14
14
 
15
- before do
16
- db.create_table!(:test) do
17
- text :name
18
- integer :value, index: true
15
+ describe "unexist table" do
16
+ it "should raise exception" do
17
+ proc { test.all }.must_raise Sequel::DatabaseError
19
18
  end
20
19
  end
21
20
 
22
- after do
23
- db.drop_table?(:test)
24
- end
21
+ describe "exist table" do
22
+ before do
23
+ db.create_table!(:test) do
24
+ text :name
25
+ integer :value, index: true
26
+ end
27
+ end
25
28
 
26
- it "should connect and execute query" do
27
- test.insert name: "andrew", value: 42
28
- test.where(name: "andrew").first[:value].must_equal 42
29
- end
29
+ after do
30
+ db.drop_table?(:test)
31
+ end
30
32
 
33
+ it "should connect and execute query" do
34
+ test.insert name: "andrew", value: 42
35
+ test.where(name: "andrew").first[:value].must_equal 42
36
+ end
31
37
 
32
- describe "pool size is exceeded" do
33
- let(:size) { 1 }
34
- it "should queue requests" do
35
- start = Time.now.to_f
36
38
 
37
- g = Green::Group.new
38
- res = []
39
- g.spawn { res << db[QUERY].all }
40
- g.spawn { res << db[QUERY].all }
41
- g.join
42
- (Time.now.to_f - start.to_f).must_be_within_delta DELAY * 2, DELAY * 2 * 0.15
43
- res.size.must_equal 2
39
+ describe "pool size is exceeded" do
40
+ let(:size) { 1 }
41
+ it "should queue requests" do
42
+ start = Time.now.to_f
43
+
44
+ g = Green::Group.new
45
+ res = []
46
+ g.spawn { res << db[QUERY].all }
47
+ g.spawn { res << db[QUERY].all }
48
+ g.join
49
+ (Time.now.to_f - start.to_f).must_be_within_delta DELAY * 2, DELAY * 2 * 0.15
50
+ res.size.must_equal 2
51
+ end
44
52
  end
45
- end
46
53
 
47
- describe "pool size is enough" do
48
- let(:size) { 2 }
49
- it "should parallel requests" do
50
- start = Time.now.to_f
54
+ describe "pool size is enough" do
55
+ let(:size) { 2 }
56
+ it "should parallel requests" do
57
+ start = Time.now.to_f
51
58
 
52
- g = Green::Group.new
53
- res = []
54
- g.spawn { res << db[QUERY].all }
55
- g.spawn { res << db[QUERY].all }
56
- g.join
59
+ g = Green::Group.new
60
+ res = []
61
+ g.spawn { res << db[QUERY].all }
62
+ g.spawn { res << db[QUERY].all }
63
+ g.join
57
64
 
58
- (Time.now.to_f - start.to_f).must_be_within_delta DELAY, DELAY * 0.30
59
- res.size.must_equal 2
65
+ (Time.now.to_f - start.to_f).must_be_within_delta DELAY, DELAY * 0.30
66
+ res.size.must_equal 2
67
+ end
60
68
  end
61
69
  end
62
-
63
-
64
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: green-em-pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
12
+ date: 2013-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine