Skip to content

Commit

Permalink
@conninfo is not always defined in a describe context
Browse files Browse the repository at this point in the history
So define the constants in a before block and ensure the connection is closed.
  • Loading branch information
larskanis committed Aug 14, 2020
1 parent dfe5ea5 commit bfff001
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions spec/pg/gc_compact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@

if GC.respond_to?(:compact)
describe "GC.compact" do
TM1 = Class.new(PG::TypeMapByClass) do
def conv_array(value)
PG::TextEncoder::JSON.new
end
end.new
TM1[Array] = :conv_array
before :all do
TM1 = Class.new(PG::TypeMapByClass) do
def conv_array(value)
PG::TextEncoder::JSON.new
end
end.new
TM1[Array] = :conv_array

E1 = PG::TextEncoder::JSON.new
E1 = PG::TextEncoder::JSON.new

TM2 = PG::TypeMapByClass.new
TM2.default_type_map = PG::TypeMapInRuby.new
TM2 = PG::TypeMapByClass.new
TM2.default_type_map = PG::TypeMapInRuby.new

TMBC = PG::TypeMapByColumn.new([PG::TextDecoder::Float.new])
TMBC = PG::TypeMapByColumn.new([PG::TextDecoder::Float.new])


CONN2 = PG.connect(@conninfo)
CONN2.type_map_for_results = PG::BasicTypeMapForResults.new(CONN2)
CONN2 = PG.connect(@conninfo)
CONN2.type_map_for_results = PG::BasicTypeMapForResults.new(CONN2)

RES1 = CONN2.exec("SELECT 234")
RES1 = CONN2.exec("SELECT 234")

TUP1 = RES1.tuple(0)
TUP1 = RES1.tuple(0)

TM3 = PG::TypeMapByClass.new
CPYENC = PG::TextEncoder::CopyRow.new type_map: TM3
RECENC = PG::TextEncoder::Record.new type_map: TM3
TM3 = PG::TypeMapByClass.new
CPYENC = PG::TextEncoder::CopyRow.new type_map: TM3
RECENC = PG::TextEncoder::Record.new type_map: TM3
end

# Use GC.verify_compaction_references instead of GC.compact .
# This has the advantage that all movable objects are actually moved.
Expand Down Expand Up @@ -76,5 +78,8 @@ def conv_array(value)
expect( RECENC.encode([34]) ).to eq( '("34")' )
end

after :all do
CONN2.close
end
end
end

0 comments on commit bfff001

Please sign in to comment.