blob: d6451d49de0270c4b95d0a5137b6e4548587c8df [file]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Send compliant traffic on one connection at a non-divisor rate."""
import argparse
import http.client
import time
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--port", type=int, required=True)
args = parser.parse_args()
connection = http.client.HTTPConnection("127.0.0.1", args.port, timeout=5)
start = time.monotonic()
for index in range(300):
time.sleep(max(0, start + index / 30 - time.monotonic()))
connection.request("GET", "/", headers={"Host": "localhost"})
response = connection.getresponse()
response.read()
if response.status != 200:
raise RuntimeError(f"Request {index}: expected 200, got {response.status}")
connection.close()
print("300 successful requests at 30 requests per second")
if __name__ == "__main__":
main()