-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sachin Varghese <[email protected]>
- Loading branch information
1 parent
ffc5ae1
commit 31caf16
Showing
8 changed files
with
113 additions
and
13 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
Empty file.
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,11 @@ | ||
import pytest | ||
|
||
from mlserver.cache.local import LocalCache | ||
from mlserver.cache import ResponseCache | ||
|
||
CACHE_SIZE = 10 | ||
|
||
|
||
@pytest.fixture | ||
def local_cache() -> ResponseCache: | ||
return LocalCache(size=CACHE_SIZE) |
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,39 @@ | ||
from string import ascii_lowercase | ||
|
||
from .conftest import CACHE_SIZE | ||
|
||
|
||
async def test_local_cache_lookup(local_cache): | ||
assert await local_cache.size() == 0 | ||
assert await local_cache.lookup("unknown key") == "" | ||
assert await local_cache.size() == 0 | ||
|
||
|
||
async def test_local_cache_insert(local_cache): | ||
assert await local_cache.size() == 0 | ||
|
||
await local_cache.insert("key", "value") | ||
assert await local_cache.lookup("key") == "value" | ||
|
||
assert await local_cache.size() == 1 | ||
|
||
await local_cache.insert("new key", "new value") | ||
assert await local_cache.lookup("key") == "value" | ||
assert await local_cache.lookup("new key") == "new value" | ||
|
||
assert await local_cache.size() == 2 | ||
|
||
|
||
async def test_local_cache_rotate(local_cache): | ||
# Insert alphabets on a loop | ||
for key, symbol in enumerate(ascii_lowercase): | ||
await local_cache.insert(str(key), symbol) | ||
|
||
if key < CACHE_SIZE: | ||
assert await local_cache.size() == key + 1 | ||
assert await local_cache.lookup(str(key)) == symbol | ||
|
||
else: | ||
assert await local_cache.size() == CACHE_SIZE | ||
assert await local_cache.lookup(str(key)) == symbol | ||
assert await local_cache.lookup(str(key - CACHE_SIZE)) == "" |
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 |
---|---|---|
@@ -1,10 +1,31 @@ | ||
import pytest | ||
import os | ||
|
||
from mlserver.settings import Settings | ||
from mlserver.handlers import DataPlane | ||
from mlserver.handlers.custom import CustomHandler | ||
from mlserver.registry import MultiModelRegistry | ||
from prometheus_client.registry import CollectorRegistry | ||
|
||
from ..fixtures import SumModel | ||
from ..conftest import TESTDATA_PATH | ||
|
||
|
||
@pytest.fixture | ||
def custom_handler(sum_model: SumModel) -> CustomHandler: | ||
return CustomHandler(rest_path="/my-custom-endpoint") | ||
|
||
|
||
@pytest.fixture | ||
def cached_settings() -> Settings: | ||
settings_path = os.path.join(TESTDATA_PATH, "settings-cache.json") | ||
return Settings.parse_file(settings_path) | ||
|
||
|
||
@pytest.fixture | ||
def cached_data_plane( | ||
cached_settings: Settings, | ||
model_registry: MultiModelRegistry, | ||
prometheus_registry: CollectorRegistry, | ||
) -> DataPlane: | ||
return DataPlane(settings=cached_settings, model_registry=model_registry) |
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,9 @@ | ||
{ | ||
"debug": true, | ||
"host": "127.0.0.1", | ||
"parallel_workers": 2, | ||
"cors_settings": { | ||
"allow_origins": ["*"] | ||
}, | ||
"cache_enabled": true | ||
} |
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 |
---|---|---|
|
@@ -4,6 +4,5 @@ | |
"parallel_workers": 2, | ||
"cors_settings": { | ||
"allow_origins": ["*"] | ||
}, | ||
"cache_enabled": true | ||
} | ||
} |