Skip to content

Commit 44cccef

Browse files
author
Ethan
committed
use at exit to cleanup WIP
1 parent ad76ba9 commit 44cccef

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/dynamo-local-ruby/dynamo_db_local.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def up
2222
pid = spawn("java -Djava.library.path=#{lib_path} -jar #{jar_path} "\
2323
"-sharedDb -inMemory -port #{PORT}")
2424
@instance = DynamoDBLocal.new(pid)
25+
at_exit { teardown(pid) }
2526

2627
test_connection
2728

@@ -42,12 +43,18 @@ def test_connection
4243
end
4344
end
4445
end
46+
47+
private
48+
def teardown(pid)
49+
Process.kill('SIGINT', pid)
50+
Process.waitpid2(pid)
51+
rescue Errno::ESRCH
52+
end
4553
end
4654

4755
def down
4856
return unless @pid
49-
Process.kill('SIGINT', @pid)
50-
Process.waitpid2(@pid)
57+
self.class.teardown(@pid)
5158
@pid = nil
5259
end
5360
end

spec/dynamo-local-ruby/dynamo_db_local_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
end
1010

1111
describe '.up' do
12+
describe 'exit teardown' do
13+
14+
end
15+
1216
after(:each) do
1317
described_class.down
1418
end

0 commit comments

Comments
 (0)