-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
140 additions
and
19 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
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 |
---|---|---|
|
@@ -2,11 +2,14 @@ | |
import time | ||
|
||
import pytest | ||
import yaml | ||
from posttroll.message import Message | ||
from posttroll.testing import patched_publisher, patched_subscriber_recv | ||
from pytroll_watchers.selector import ( | ||
TTLDict, | ||
_run_selector_with_managed_dict_server, | ||
_running_redis_server, | ||
cli, | ||
run_selector, | ||
) | ||
|
||
|
@@ -48,7 +51,7 @@ def test_run_selector_that_starts_redis_on_given_port(tmp_path): | |
f'"uid": "{uid}", "uri": "file://{str(sdr_file)}", "path": "{str(sdr_file)}", ' | ||
'"filesystem": {"cls": "fsspec.implementations.local.LocalFileSystem", "protocol": "file", "args": []}}') | ||
|
||
messages = [msg1] | ||
messages = [Message.decode(msg1)] | ||
|
||
pipe_in_address = "ipc://" + str(tmp_path / "in.ipc") | ||
pipe_out_address = "ipc://" + str(tmp_path / "out.ipc") | ||
|
@@ -67,7 +70,6 @@ def test_run_selector_that_starts_redis_on_given_port(tmp_path): | |
assert len(published_messages) == 1 | ||
|
||
|
||
|
||
@pytest.fixture(scope="module") | ||
def _redis_server(): | ||
"""Start a redis server.""" | ||
|
@@ -84,7 +86,7 @@ def create_data_file(path): | |
|
||
|
||
@pytest.mark.usefixtures("_redis_server") | ||
def test_run_selector_on_single_file_messages(tmp_path): | ||
def test_run_selector_on_single_file_messages(tmp_path, caplog): | ||
"""Test running the selector on single file messages.""" | ||
uid = "IVCDB_j02_d20240419_t1114110_e1115356_b07465_c20240419113435035578_cspp_dev.h5" | ||
sdr_file = tmp_path / "sdr" / uid | ||
|
@@ -110,7 +112,7 @@ def test_run_selector_on_single_file_messages(tmp_path): | |
f'"uid": "{uid2}", "uri": "ssh://someplace.pytroll.org:/{str(sdr_file2)}", "path": "{str(sdr_file2)}", ' | ||
'"filesystem": {"cls": "fsspec.implementations.ssh.SFTPFileSystem", "protocol": "ssh", "args": []}}') | ||
|
||
messages = [msg1, msg2, msg3] | ||
messages = [Message.decode(msg1), Message.decode(msg2), Message.decode(msg3)] | ||
|
||
pipe_in_address = "ipc://" + str(tmp_path / "in.ipc") | ||
pipe_out_address = "ipc://" + str(tmp_path / "out.ipc") | ||
|
@@ -123,12 +125,17 @@ def test_run_selector_on_single_file_messages(tmp_path): | |
|
||
selector_config = dict(ttl=1, host="localhost", port=6379) | ||
|
||
caplog.set_level("INFO") | ||
with patched_subscriber_recv(messages): | ||
with patched_publisher() as published_messages: | ||
_run_selector_with_managed_dict_server(selector_config, subscriber_config, publisher_config) | ||
assert len(published_messages) == 2 | ||
assert published_messages[0] == msg1 | ||
assert published_messages[1] == msg3 | ||
assert "New content " + str(msg1) in caplog.text | ||
assert "Discarded " + str(msg2) in caplog.text | ||
assert "New content " + str(msg3) in caplog.text | ||
|
||
|
||
|
||
@pytest.mark.usefixtures("_redis_server") | ||
|
@@ -148,3 +155,40 @@ def test_ttldict(): | |
time.sleep(ttl+1) | ||
sel[key] = other_value | ||
assert sel[key] == other_value | ||
|
||
|
||
def test_cli(tmp_path): | ||
"""Test the command-line interface.""" | ||
uid = "IVCDB_j03_d20240419_t1114110_e1115356_b07465_c20240419113435035578_cspp_dev.h5" | ||
sdr_file = tmp_path / "sdr" / uid | ||
create_data_file(sdr_file) | ||
|
||
msg1 = ('pytroll://segment/viirs/l1b/ info [email protected] 2024-04-19T11:35:00.487388 v1.01 ' | ||
'application/json {"sensor": "viirs", ' | ||
f'"uid": "{uid}", "uri": "file://{str(sdr_file)}", "path": "{str(sdr_file)}", ' | ||
'"filesystem": {"cls": "fsspec.implementations.local.LocalFileSystem", "protocol": "file", "args": []}}') | ||
|
||
messages = [Message.decode(msg1)] | ||
|
||
pipe_in_address = "ipc://" + str(tmp_path / "in.ipc") | ||
pipe_out_address = "ipc://" + str(tmp_path / "out.ipc") | ||
subscriber_config = dict(addresses=[pipe_in_address], | ||
nameserver=False, | ||
port=3000) | ||
|
||
publisher_config = dict(address=pipe_out_address, | ||
nameservers=False) | ||
|
||
redis_dir = tmp_path / "redis_dir" | ||
|
||
selector_config = dict(ttl=1, port=6389, directory=str(redis_dir)) | ||
config = dict(publisher_config=publisher_config, | ||
subscriber_config=subscriber_config, | ||
selector_config=selector_config) | ||
config_file = tmp_path / "selector_config" | ||
with open(config_file, "w") as fd: | ||
fd.write(yaml.dump(config)) | ||
with patched_subscriber_recv(messages): | ||
with patched_publisher() as published_messages: | ||
cli([str(config_file)]) | ||
assert len(published_messages) == 1 |