diff --git a/reddit_api_async/rate_limiter.ml b/reddit_api_async/rate_limiter.ml index 454f75dc..7a520584 100644 --- a/reddit_api_async/rate_limiter.ml +++ b/reddit_api_async/rate_limiter.ml @@ -230,8 +230,6 @@ module By_headers = struct return (`Repeat ())))) ;; - (* TODO: Allow retries once per minute? *) - let update_server_side_info t ~new_server_side_info = (match t.state with | State.Created | State.Consuming_rate_limit _ -> () @@ -253,7 +251,10 @@ module By_headers = struct let permit_request t = let%bind () = wait_until_ready t in match t.state with - | Waiting_on_first_request _ -> (* TODO is this impossible? *) assert false + | Waiting_on_first_request _ -> + raise_s + [%message + "Unexpectedly in [Waiting_on_first_request] state after [wait_until_ready]."] | Created -> let received_response = Ivar.create () in t.state <- Waiting_on_first_request { received_response }; @@ -275,7 +276,6 @@ module By_headers = struct (* We assume that, in the absence of ratelimit headers, we must have hit some authentication failure. As a heuristic to avoid getting stuck, we immediately reset [t.ready]. *) - (* TODO: What to do here? *) t.state <- Created | Some response_server_side_info -> let new_server_side_info = diff --git a/test/test_rate_limiter.ml b/test/test_rate_limiter.ml index 3116698b..c88092e7 100644 --- a/test/test_rate_limiter.ml +++ b/test/test_rate_limiter.ml @@ -117,9 +117,11 @@ let%expect_test _ = Rate_limiter.notify_response rate_limiter (build_header ~server_time:(00 ^: 10) ~limit_remaining:10); + let%bind () = Log.Global.flushed () in print (); [%expect {| + ("Rate limit is resetting"(old_remaining_api_calls 0)) ((time (1970-01-01 00:00:00.000000000Z)) (is_ready true) (rate_limiter ( @@ -138,10 +140,8 @@ let%expect_test _ = return (`Repeat (n - 1))) in print (); - (* TODO It's not actually resetting: It's just exhausted. *) [%expect {| - ("Rate limit is resetting"(old_remaining_api_calls 0)) ((time (1970-01-01 00:00:00.000000000Z)) (is_ready false) (rate_limiter (