You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sdap.apache.org by ea...@apache.org on 2020/06/12 22:09:02 UTC
[incubator-sdap-ingester] branch tests updated: unit test wip
This is an automated email from the ASF dual-hosted git repository.
eamonford pushed a commit to branch tests
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-ingester.git
The following commit(s) were added to refs/heads/tests by this push:
new 6f17c7c unit test wip
6f17c7c is described below
commit 6f17c7c578d96af9496c5cb18e27980f480753f5
Author: Eamon Ford <ea...@jpl.nasa.gov>
AuthorDate: Fri Jun 12 15:08:51 2020 -0700
unit test wip
---
.../tests/services/test_CollectionWatcher.py | 41 +++++++++++++++++++---
1 file changed, 36 insertions(+), 5 deletions(-)
diff --git a/collection_manager/tests/services/test_CollectionWatcher.py b/collection_manager/tests/services/test_CollectionWatcher.py
index a1d8022..5a5b073 100644
--- a/collection_manager/tests/services/test_CollectionWatcher.py
+++ b/collection_manager/tests/services/test_CollectionWatcher.py
@@ -1,9 +1,10 @@
import os
import tempfile
+import time
import unittest
from datetime import datetime
from unittest.mock import Mock
-import time
+
from collection_manager.entities import Collection
from collection_manager.entities.exceptions import YamlParsingError, CollectionConfigFileNotFoundError
from collection_manager.services import CollectionWatcher
@@ -98,9 +99,39 @@ collections:
forward-processing-priority: 5
"""
collections_config.write(collections_str.encode("utf-8"))
- time.sleep(1)
- self.assertEqual(2, collection_callback.call_count)
+ assert_called_within_timeout(collection_callback, call_count=2)
+ granule_dir.cleanup()
+
+ def test_granule_callback_is_called_on_new_file(self):
+ with tempfile.NamedTemporaryFile("w+b", buffering=0) as collections_config:
+ granule_dir = tempfile.TemporaryDirectory()
+ collections_str = f"""
+collections:
+- id: TELLUS_GRACE_MASCON_CRI_GRID_RL05_V2_LAND
+ path: {granule_dir.name}
+ variable: lwe_thickness
+ priority: 1
+ forward-processing-priority: 5
+ """
+ collections_config.write(collections_str.encode("utf-8"))
+
+ granule_callback = Mock()
+ collection_watcher = CollectionWatcher(collections_config.name, Mock(), granule_callback)
+ collection_watcher.start_watching()
+
+ new_granule = open(os.path.join(granule_dir.name, 'test.nc'), "w+")
+ new_granule.close()
+
+ assert_called_within_timeout(granule_callback)
+ granule_dir.cleanup()
+
+
+def assert_called_within_timeout(mock_func, timeout_sec=1.0, call_count=1):
+ start = datetime.now()
- def test_granule_callback_is_called(self):
- ...
\ No newline at end of file
+ while (datetime.now() - start).total_seconds() < timeout_sec:
+ time.sleep(0.01)
+ if mock_func.call_count >= call_count:
+ return
+ raise AssertionError(f"{mock_func} did not reach {call_count} calls called within {timeout_sec} sec")