Skip to content

Commit

Permalink
use at exit to cleanup WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan committed Oct 4, 2015
1 parent ad76ba9 commit 44cccef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/dynamo-local-ruby/dynamo_db_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def up
pid = spawn("java -Djava.library.path=#{lib_path} -jar #{jar_path} "\
"-sharedDb -inMemory -port #{PORT}")
@instance = DynamoDBLocal.new(pid)
at_exit { teardown(pid) }

test_connection

Expand All @@ -42,12 +43,18 @@ def test_connection
end
end
end

private
def teardown(pid)
Process.kill('SIGINT', pid)
Process.waitpid2(pid)
rescue Errno::ESRCH
end
end

def down
return unless @pid
Process.kill('SIGINT', @pid)
Process.waitpid2(@pid)
self.class.teardown(@pid)
@pid = nil
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/dynamo-local-ruby/dynamo_db_local_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
end

describe '.up' do
describe 'exit teardown' do

end

after(:each) do
described_class.down
end
Expand Down

0 comments on commit 44cccef

Please sign in to comment.