File tree Expand file tree Collapse file tree 3 files changed +41
-6
lines changed Expand file tree Collapse file tree 3 files changed +41
-6
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ class DynamoDBLocal
8
8
9
9
PATH_TO_JAR = '../../../lib/jars/dynamodb_local'
10
10
11
+ RETRIES = 5
12
+
11
13
def initialize ( pid )
12
14
@pid = pid
13
15
end
@@ -21,12 +23,25 @@ def up
21
23
"-sharedDb -inMemory -port #{ PORT } " )
22
24
@instance = DynamoDBLocal . new ( pid )
23
25
26
+ test_connection
27
+
24
28
@instance
25
29
end
26
30
27
31
def down
28
32
@instance . down if defined? @instance
29
33
end
34
+
35
+ def test_connection
36
+ RETRIES . times do
37
+ begin
38
+ Net ::HTTP . get_response ( URI . parse ( ENDPOINT ) )
39
+ break
40
+ rescue Errno ::ECONNREFUSED
41
+ sleep ( 0.5 )
42
+ end
43
+ end
44
+ end
30
45
end
31
46
32
47
def down
Original file line number Diff line number Diff line change 4
4
describe DynamoLocalRuby ::DynamoDBLocal do
5
5
let ( :dynamo_instance ) { described_class . up }
6
6
7
- describe '.up' do
8
- before do
9
- stub_const ( "#{ described_class } ::PATH_TO_JAR" , SPEC_JAR_DIR )
10
- end
7
+ before do
8
+ stub_const ( "#{ described_class } ::PATH_TO_JAR" , SPEC_JAR_DIR )
9
+ end
11
10
11
+ describe '.up' do
12
12
after ( :each ) do
13
13
described_class . down
14
14
end
26
26
let ( :uri ) { URI . parse ( described_class ::ENDPOINT ) }
27
27
let ( :response ) { Net ::HTTP . get_response ( uri ) }
28
28
29
+ context 'but is not accepting connections' do
30
+ context 'retries and is now accepting connections' do
31
+ it 'succeeds' do
32
+ call_count = 0
33
+ expect ( Net ::HTTP ) . to receive ( :get_response ) . twice do
34
+ call_count += 1
35
+ fail Errno ::ECONNREFUSED if call_count == 1
36
+ end
37
+
38
+ dynamo_instance
39
+ end
40
+ end
41
+
42
+ context 'retries and never accepts connections' do
43
+ it 'tries 5 times' do
44
+ expect ( Net ::HTTP ) . to receive ( :get_response ) . exactly ( 5 ) . times \
45
+ . and_raise ( Errno ::ECONNREFUSED . new )
46
+ dynamo_instance
47
+ end
48
+ end
49
+ end
50
+
29
51
it 'responds to requests' do
30
52
# I'd like this to be in a before block but couldn't get it working
31
53
dynamo_instance
32
- sleep ( 2 ) # remove this once retry is enabled
33
54
expect { response } . to_not raise_error
34
55
end
35
56
end
Original file line number Diff line number Diff line change 15
15
16
16
before ( :each ) do
17
17
DynamoLocalRuby ::DynamoDBLocal . up
18
- sleep ( 2 ) # remove once retries are enabled
19
18
end
20
19
21
20
after ( :each ) do
You can’t perform that action at this time.
0 commit comments