File tree Expand file tree Collapse file tree 4 files changed +30
-23
lines changed Expand file tree Collapse file tree 4 files changed +30
-23
lines changed Original file line number Diff line number Diff line change @@ -72,24 +72,11 @@ def self.each_ip_protocol
72
72
end
73
73
74
74
def self . loop_with_timeout ( timeout = TIME_TOLERANCE )
75
- require 'timeout'
76
- time = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
75
+ start = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
77
76
78
- loop do
79
- if Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) - time >= timeout
80
- raise TimeoutError , "Did not succeed within #{ timeout } seconds"
81
- end
82
-
83
- sleep 0.01 # necessary on OSX; don't know why
84
- yield
85
- end
86
- end
87
-
88
- def self . wait_until_success ( timeout = TIME_TOLERANCE )
89
- loop_with_timeout ( timeout ) do
90
- begin
91
- return yield
92
- rescue
77
+ while yield == :retry
78
+ if Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) - start >= timeout
79
+ raise RuntimeError , "Did not succeed within #{ timeout } seconds"
93
80
end
94
81
end
95
82
end
Original file line number Diff line number Diff line change 31
31
end
32
32
end
33
33
34
- SocketSpecs . wait_until_success do
35
- @client . connect ( Socket . sockaddr_in ( @port , '127.0.0.1' ) )
34
+ SocketSpecs . loop_with_timeout do
35
+ begin
36
+ @client . connect ( Socket . sockaddr_in ( @port , '127.0.0.1' ) )
37
+ rescue SystemCallError
38
+ sleep 0.01
39
+ :retry
40
+ end
36
41
end
37
42
38
43
# At this point the connection has been set up but the thread may not yet
Original file line number Diff line number Diff line change 35
35
@client . connect ( Socket . sockaddr_in ( @port , '127.0.0.1' ) )
36
36
37
37
SocketSpecs . loop_with_timeout do
38
- SocketSpecs . wait_until_success { @client . write ( 'hello' ) }
39
-
40
- break if msg
38
+ begin
39
+ @client . write ( 'hello' )
40
+ rescue SystemCallError
41
+ sleep 0.01
42
+ :retry
43
+ else
44
+ unless msg
45
+ sleep 0.001
46
+ :retry
47
+ end
48
+ end
41
49
end
42
50
43
51
msg . should == 'hello'
Original file line number Diff line number Diff line change 39
39
end
40
40
end
41
41
42
- @client = SocketSpecs . wait_until_success { Socket . unix ( @path ) }
42
+ SocketSpecs . loop_with_timeout do
43
+ begin
44
+ @client = Socket . unix ( @path )
45
+ rescue SystemCallError
46
+ sleep 0.01
47
+ :retry
48
+ end
49
+ end
43
50
44
51
thread . join ( 2 )
45
52
You can’t perform that action at this time.
0 commit comments