0
0
Testing Fundamentalstesting~10 mins

Network condition testing in Testing Fundamentals - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to simulate a network delay of 2 seconds in a test.

Testing Fundamentals
def test_network_delay():
    import time
    time.[1](2)
    assert True
Drag options to blanks, or click blank then click option'
Asleep
Bwait
Cdelay
Dpause
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent functions like time.wait or time.delay.
2fill in blank
medium

Complete the code to check if the network is reachable by pinging 'example.com'.

Testing Fundamentals
import subprocess

def is_network_reachable():
    response = subprocess.run(['ping', '-c', '1', '[1]'], capture_output=True)
    return response.returncode == 0
Drag options to blanks, or click blank then click option'
Alocalhost
Bexample.com
C192.168.1.1
Dgoogle.com
Attempts:
3 left
💡 Hint
Common Mistakes
Using local or private IP addresses that may not reflect internet connectivity.
3fill in blank
hard

Fix the error in the code to simulate packet loss by dropping 30% of packets in a test.

Testing Fundamentals
import random

def simulate_packet_loss():
    if random.random() [1] 0.3:
        return 'Packet dropped'
    else:
        return 'Packet sent'
Drag options to blanks, or click blank then click option'
A<
B<=
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using > 0.3 which causes 70% packet loss instead of 30%.
4fill in blank
hard

Fill both blanks to create a test that retries a network request up to 3 times if it fails.

Testing Fundamentals
def retry_request():
    attempts = 0
    while attempts [1] 3:
        success = make_request()
        if success:
            return True
        attempts [2] 1
    return False
Drag options to blanks, or click blank then click option'
A<
B<=
C+=
D++
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= 3 causes 4 attempts, using ++ is invalid in Python.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps URLs to their response times if response time is less than 500ms.

Testing Fundamentals
response_times = {url[1]: time for url, time in results.items() if time [2] 500 and url [3] 'http://example.com'}
Drag options to blanks, or click blank then click option'
A.upper()
B<
C!=
D.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using .upper() instead of .lower(), using > instead of <, using == instead of !=.