File tree Expand file tree Collapse file tree 4 files changed +33
-26
lines changed Expand file tree Collapse file tree 4 files changed +33
-26
lines changed Original file line number Diff line number Diff line change 4
4
require 'temporal/error/failure'
5
5
require 'temporal/error/workflow_failure'
6
6
require 'temporal/interceptor/client'
7
+ require 'support/helpers/test_rpc'
7
8
8
9
class TestInterceptor < Temporal ::Interceptor ::Client
9
10
attr_reader :results
@@ -57,18 +58,9 @@ def terminate_workflow(input)
57
58
let ( :id ) { SecureRandom . uuid }
58
59
let ( :workflow ) { 'kitchen_sink' }
59
60
60
- def wait_for_server ( url )
61
- 10 . times do
62
- Temporal ::Connection . new ( "http://#{ url } " )
63
- break
64
- rescue Temporal ::Bridge ::Error
65
- sleep ( 0.5 ) # delay before retrying
66
- end
67
- end
68
-
69
61
before ( :all ) do
70
62
@server_pid = fork { exec ( "#{ support_path } /go_server/main #{ port } #{ namespace } " ) }
71
- wait_for_server ( url )
63
+ Helpers :: TestRPC . wait ( "http:// #{ url } " , 10 , 0.5 )
72
64
73
65
@worker_pid = fork { exec ( "#{ support_path } /go_worker/main #{ url } #{ namespace } #{ task_queue } " ) }
74
66
end
Original file line number Diff line number Diff line change 1
1
require 'grpc'
2
2
require 'temporal/connection'
3
+ require 'support/helpers/test_rpc'
3
4
require 'support/mock_server'
4
5
5
6
describe Temporal ::Connection do
6
7
mock_address = '0.0.0.0:4444' . freeze
7
8
8
- def wait_for_mock_server ( address , attempts , interval = 1 )
9
- request = Temporal ::Api ::WorkflowService ::V1 ::GetSystemInfoRequest . new
10
- attempts . times do |i |
11
- connection = described_class . new ( "http://#{ address } " )
12
- connection . get_system_info ( request )
13
- break
14
- rescue StandardError => e
15
- puts "Error connecting to a mock server: #{ e } . Attempt #{ i + 1 } / #{ attempts } "
16
- raise if i + 1 == attempts # re-raise upon exhausting attempts
17
-
18
- sleep interval
19
- end
20
- end
21
-
22
9
subject { described_class . new ( "http://#{ mock_address } " ) }
23
10
24
11
# TODO: For some reason the Bridge doesn't play well with the server in the same
25
12
# process throwing SegFaults in cases. Needs further investigation
26
13
before ( :all ) do
27
- @pid = fork { MockServer . run ( mock_address ) }
28
- wait_for_mock_server ( mock_address , 10 )
14
+ @pid = fork { exec ( 'bundle exec ruby spec/support/mock_server.rb' ) }
15
+ Helpers :: TestRPC . wait ( "http:// #{ mock_address } " , 10 )
29
16
end
30
17
after ( :all ) { Process . kill ( 'QUIT' , @pid ) }
31
18
Original file line number Diff line number Diff line change
1
+ require 'temporal/connection'
2
+
3
+ module Helpers
4
+ module TestRPC
5
+ def self . wait ( address , max_attempts , interval = 1 )
6
+ request = Temporal ::Api ::WorkflowService ::V1 ::GetSystemInfoRequest . new
7
+ max_attempts . times do |i |
8
+ connection = Temporal ::Connection . new ( address )
9
+ connection . get_system_info ( request )
10
+ break
11
+ rescue StandardError => e
12
+ puts "Error connecting to a server: #{ e } . Attempt #{ i + 1 } / #{ max_attempts } "
13
+ raise if i + 1 == max_attempts # re-raise upon exhausting attempts
14
+
15
+ sleep interval
16
+ end
17
+ end
18
+ end
19
+ end
Original file line number Diff line number Diff line change
1
+ if __FILE__ == $PROGRAM_NAME
2
+ $LOAD_PATH << File . expand_path ( '..' , File . dirname ( __FILE__ ) )
3
+ $LOAD_PATH << File . expand_path ( '../../lib/gen' , File . dirname ( __FILE__ ) )
4
+ end
5
+
1
6
require 'grpc'
2
7
require 'support/grpc/temporal/api/workflowservice/v1/service_services_pb'
3
8
@@ -16,3 +21,7 @@ def self.run(address)
16
21
end
17
22
end
18
23
end
24
+
25
+ if __FILE__ == $PROGRAM_NAME
26
+ MockServer . run ( '0.0.0.0:4444' )
27
+ end
You can’t perform that action at this time.
0 commit comments