0
0
Microservicessystem_design~10 mins

Integration testing in Microservices - Interactive Code Practice

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

Complete the code to define an integration test that checks communication between two microservices.

Microservices
def test_service_communication():
    response = service_a.call_service_b()
    assert response.status_code == [1]
Drag options to blanks, or click blank then click option'
A200
B404
C500
D302
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 or 500 as success codes.
2fill in blank
medium

Complete the code to mock a dependent microservice during integration testing.

Microservices
with mock.patch('service_b.api_call') as mocked_call:
    mocked_call.return_value = [1]
    result = service_a.call_service_b()
    assert result == 'success'
Drag options to blanks, or click blank then click option'
A'error'
B'timeout'
CNone
D'success'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning error or None causing test failures.
3fill in blank
hard

Fix the error in the integration test setup to correctly start the test environment.

Microservices
def setup_test_env():
    [1].start()
    service_a.reset()
    service_b.reset()
Drag options to blanks, or click blank then click option'
Atest_environment
Btest_env
Cenv
Denvironment
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined or incorrect variable names.
4fill in blank
hard

Fill both blanks to create a test that waits for service B to be ready before calling it.

Microservices
def test_service_b_ready():
    while not service_b.[1]():
        time.[2](1)
    response = service_a.call_service_b()
    assert response.status_code == 200
Drag options to blanks, or click blank then click option'
Ais_ready
Bsleep
Cwait
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'wait' instead of 'sleep', or wrong readiness method.
5fill in blank
hard

Fill all three blanks to build a dictionary comprehension that maps service names to their health status if status is 'healthy'.

Microservices
health_status = { [1]: status for [2], status in services.items() if status [3] 'healthy' }
Drag options to blanks, or click blank then click option'
Aname
Bstatus
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causing wrong filtering.