File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,15 @@ def handle_rate_limited_response(headers)
7272 { nil => Time . now + DEFAULT_DELAY }
7373 end
7474
75- @rate_limits . merge! ( rate_limits )
75+ rate_limits . each do |category , limit |
76+ if current_limit = @rate_limits [ category ]
77+ if current_limit < limit
78+ @rate_limits [ category ] = limit
79+ end
80+ else
81+ @rate_limits [ category ] = limit
82+ end
83+ end
7684 end
7785
7886 def parse_rate_limit_header ( rate_limit_header )
Original file line number Diff line number Diff line change 104104 end
105105 end
106106 end
107+
108+ context "when receiving a greater value for a present category" do
109+ let ( :headers ) do
110+ { "x-sentry-rate-limits" => "120:error:organization" }
111+ end
112+
113+ before do
114+ subject . rate_limits . merge! ( "error" => now + 10 )
115+ end
116+
117+ it "overrides the current limit" do
118+ send_data_and_verify_response ( now )
119+ expect ( subject . rate_limits ) . to eq ( { "error" => now + 120 } )
120+ end
121+ end
122+
123+ context "when receiving a smaller value for a present category" do
124+ let ( :headers ) do
125+ { "x-sentry-rate-limits" => "10:error:organization" }
126+ end
127+
128+ before do
129+ subject . rate_limits . merge! ( "error" => now + 120 )
130+ end
131+
132+ it "keeps the current limit" do
133+ send_data_and_verify_response ( now )
134+ expect ( subject . rate_limits ) . to eq ( { "error" => now + 120 } )
135+ end
136+ end
107137 end
108138
109139 context "with retry-after header" do
You can’t perform that action at this time.
0 commit comments