@@ -43,6 +43,33 @@ def test_call_works_as_expected
4343 assert Time . parse ( payload [ 0 ] . time ) - start_time < 0.01
4444 end
4545
46+ def test_call_with_ip
47+ response_code = rand ( 200 ..204 )
48+ app = Proc . new { |env | sleep ( 2.5 ) ; [ response_code , { "Content-Type" => "text/html" } , [ "Hello Rack!" ] ] }
49+ url = "http://localhost:8080/foo?a=b"
50+ ip = "1.1.1.1"
51+ http_method = 'PUT'
52+ env = Rack ::MockRequest . env_for ( url , :method => http_method , "REMOTE_ADDR" => ip )
53+ instrumentation_key = 'key'
54+ sender = MockAsynchronousSender . new
55+ track_request = TrackRequest . new app , instrumentation_key , 500 , 1 , true
56+ track_request . send ( :sender= , sender )
57+ start_time = Time . now
58+
59+ SecureRandom . expects ( :base64 ) . with ( 10 ) . returns ( 'y0NM2eOY/fnQPw==' )
60+ result = track_request . call ( env )
61+
62+ app_result = app . call ( env )
63+ assert_equal app_result , result
64+ sleep ( sender . send_interval )
65+
66+ assert_equal 1 , sender . buffer . count
67+ payload = sender . buffer [ 0 ]
68+ request_data = payload [ 0 ] . data . base_data
69+
70+ assert_equal request_data . properties [ 'clientIp' ] , ip
71+ end
72+
4673 def test_call_with_failed_request
4774 response_code = rand ( 400 ..600 )
4875 app = Proc . new { |env | [ response_code , { "Content-Type" => "text/html" } , [ "Hello Rack!" ] ] }
@@ -68,13 +95,13 @@ def test_call_with_unhandled_exception
6895 sender = MockAsynchronousSender . new
6996 track_request = TrackRequest . new app , instrumentation_key , 500 , 1
7097 track_request . send ( :sender= , sender )
71-
98+
7299 begin
73100 track_request . call ( env )
74101 rescue => ex
75102 assert_equal 'Boom!' , ex . message
76103 end
77-
104+
78105 sleep ( sender . send_interval )
79106 payload = sender . buffer [ 0 ]
80107 assert_equal 2 , payload . count
@@ -109,7 +136,7 @@ def test_format_request_duration_less_than_a_day
109136 track_request = TrackRequest . new app , 'one'
110137 duration_seconds = rand ( 86400 ) + rand
111138 time_span = track_request . send ( :format_request_duration , duration_seconds )
112-
139+
113140 match = TIME_SPAN_FORMAT . match time_span
114141 assert_not_nil match
115142 days = duration_seconds . to_i /86400
@@ -129,7 +156,7 @@ def test_format_request_duration_more_than_a_day
129156 track_request = TrackRequest . new app , 'one'
130157 duration_seconds = rand ( 86400 ..240000 ) + rand
131158 time_span = track_request . send ( :format_request_duration , duration_seconds )
132-
159+
133160 match = TIME_SPAN_FORMAT . match time_span
134161 assert_not_nil match
135162 assert_equal 1 , match [ 'day' ] . to_i
0 commit comments