0
0
Rest APIprogramming~20 mins

Load testing in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Load Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this simple load test script?
Consider this Python script using the requests library to simulate 3 sequential API calls. What will be printed?
Rest API
import requests

urls = ['https://api.example.com/data1', 'https://api.example.com/data2', 'https://api.example.com/data3']

for url in urls:
    response = requests.get(url)
    print(response.status_code)
A
200
200
200
B
200
404
200
C
404
404
404
D
200
200
404
Attempts:
2 left
💡 Hint
Assume all URLs are valid and the server is up.
🧠 Conceptual
intermediate
1:30remaining
Which factor is most important when designing a load test?
When creating a load test for a REST API, which factor should you prioritize to simulate real user behavior?
AThe programming language used to write the test
BOnly the total number of requests sent
CThe size of the API response payload
DNumber of concurrent users and request rate
Attempts:
2 left
💡 Hint
Think about what affects server load the most.
🔧 Debug
advanced
2:30remaining
Why does this load test script fail with a connection error?
This Python script uses threading to send 100 requests concurrently but raises a ConnectionError. What is the likely cause?
Rest API
import threading
import requests

def send_request():
    requests.get('https://api.example.com/data')

threads = []
for _ in range(100):
    t = threading.Thread(target=send_request)
    threads.append(t)
    t.start()

for t in threads:
    t.join()
AThe URL is invalid causing connection failure
BThe requests library does not support threading
CThe server limits the number of simultaneous connections causing errors
DThreads are not started properly
Attempts:
2 left
💡 Hint
Consider server-side limits on connections.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in this load test script snippet
What is wrong with this Python code snippet for sending multiple requests?
Rest API
import requests

responses = [requests.get('https://api.example.com/data') for i in range(5)]
print(responses.status_code)
A'responses' is a list; accessing 'status_code' directly causes AttributeError
BMissing parentheses in the print statement
CThe range function is used incorrectly
DThe requests.get call is missing required headers
Attempts:
2 left
💡 Hint
Think about the type of 'responses' and how to access elements.
🚀 Application
expert
3:00remaining
How many requests per second does this load test generate?
This script uses asyncio to send 50 requests with a 0.1 second delay between each start. How many requests per second does it generate approximately?
Rest API
import asyncio
import aiohttp

async def fetch(session, url):
    async with session.get(url) as response:
        return await response.text()

async def main():
    async with aiohttp.ClientSession() as session:
        tasks = []
        for _ in range(50):
            tasks.append(fetch(session, 'https://api.example.com/data'))
            await asyncio.sleep(0.1)
        await asyncio.gather(*tasks)

asyncio.run(main())
A50 requests per second
B10 requests per second
C5 requests per second
D100 requests per second
Attempts:
2 left
💡 Hint
Calculate how many requests start each second based on the delay.