-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new test scenarios and adapt scenarios of load balancing to be parametrized, given that the tests were the same for the round robin and least connections configuration. Also add markers on every test case so that it's possible to run tests for a specific feature without running every test.
- Loading branch information
Showing
17 changed files
with
507 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[pytest] | ||
markers = | ||
command: Test for the command server. | ||
round_robin: Test ekilibri with the round robin configuration. | ||
least_connections: Test ekilibri with the least connections configuration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from time import sleep | ||
from typing import Set | ||
|
||
import requests | ||
|
||
EKILIBRI_URL = "http://localhost:8080" | ||
|
||
|
||
def assert_health(n: int, status: int): | ||
for _ in range(n): | ||
response = requests.get(EKILIBRI_URL + "/health") | ||
assert response.status_code == status | ||
|
||
|
||
def assert_health_multiple_status(n: int, statuses: Set[int]): | ||
"""Checks the response for the health endpoint validating the status code | ||
could be of different values.""" | ||
for _ in range(n): | ||
response = requests.get(EKILIBRI_URL + "/health") | ||
assert response.status_code in statuses | ||
|
||
|
||
def wait_fail_window(): | ||
"""Waits the fail window for ekilibri to remove the server from the healthy servers list.""" | ||
sleep(5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
servers = [ | ||
"127.0.0.1:8081", | ||
"127.0.0.1:8082", | ||
"127.0.0.1:8083" | ||
] | ||
strategy = "LeastConnections" | ||
max_fails = 1 | ||
fail_window = 5 | ||
connection_timeout = 1000 | ||
write_timeout = 1000 | ||
read_timeout = 1000 | ||
health_check_path = "/sleep" | ||
pool_size = 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import pytest | ||
import requests | ||
|
||
from common import EKILIBRI_URL, assert_health | ||
from ekilibri_setup import kill_process, setup_ekilibri_server | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"configuration", | ||
[ | ||
pytest.param("least-connections", marks=pytest.mark.least_connections), | ||
pytest.param("round-robin", marks=pytest.mark.round_robin), | ||
], | ||
) | ||
def test_multiple_get_request_to_three_servers(request, configuration): | ||
pid = setup_ekilibri_server(request, f"tests/ekilibri-{configuration}.toml") | ||
try: | ||
assert_health(100, status=200) | ||
finally: | ||
kill_process(pid) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"configuration", | ||
[ | ||
pytest.param("least-connections", marks=pytest.mark.least_connections), | ||
pytest.param("round-robin", marks=pytest.mark.round_robin), | ||
], | ||
) | ||
def test_multiple_get_request_with_timeout(request, configuration): | ||
pid = setup_ekilibri_server(request, f"tests/ekilibri-{configuration}.toml") | ||
try: | ||
for _ in range(10): | ||
response = requests.get(EKILIBRI_URL + "/sleep") | ||
assert response.status_code == 504 | ||
finally: | ||
kill_process(pid) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"configuration", | ||
[ | ||
pytest.param("least-connections", marks=pytest.mark.least_connections), | ||
pytest.param("round-robin", marks=pytest.mark.round_robin), | ||
], | ||
) | ||
def test_get_not_found(request, configuration): | ||
pid = setup_ekilibri_server(request, f"tests/ekilibri-{configuration}.toml") | ||
try: | ||
response = requests.get(EKILIBRI_URL + "/not-found") | ||
assert response.status_code == 404 | ||
assert response.text == "" | ||
finally: | ||
kill_process(pid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
|
||
from common import assert_health, wait_fail_window | ||
from ekilibri_setup import kill_process, setup_ekilibri_server | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"configuration", | ||
[ | ||
pytest.param("least-connections", marks=pytest.mark.least_connections), | ||
pytest.param("round-robin", marks=pytest.mark.round_robin), | ||
], | ||
) | ||
def test_get_requests_when_the_health_check_path_is_timing_out(request, configuration): | ||
pid = setup_ekilibri_server(request, f"tests/ekilibri-{configuration}-timeout.toml") | ||
try: | ||
# First requests should be ok, given that Ekilibri still hasn't removed | ||
# the servers from healthy servers list. | ||
assert_health(100, status=200) | ||
|
||
wait_fail_window() | ||
|
||
assert_health(10, status=502) | ||
finally: | ||
kill_process(pid) |
Oops, something went wrong.