-
-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Threading was the cause of the issue in #779, so adding a test that will exercise multi-threading.
- Loading branch information
Showing
5 changed files
with
79 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
name: "1" | ||
url: "|echo job 1" | ||
command: "echo job 1" | ||
enabled: false | ||
--- | ||
name: "2" | ||
url: "|echo job 2" | ||
command: "echo job 2" | ||
--- | ||
name: "3" | ||
command: "echo job 3" | ||
--- | ||
name: "4" | ||
command: "echo job 4" | ||
--- | ||
name: "5" | ||
command: "echo job 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
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,64 @@ | ||
import sys | ||
from glob import glob | ||
|
||
from urlwatch.jobs import UrlJob, JobBase, ShellJob | ||
from urlwatch.storage import UrlsYaml, UrlsTxt | ||
|
||
import contextlib | ||
import pytest | ||
|
||
import tempfile | ||
import os | ||
|
||
from urlwatch import storage | ||
from urlwatch.config import CommandConfig | ||
from urlwatch.storage import YamlConfigStorage, CacheMiniDBStorage | ||
from urlwatch.main import Urlwatch | ||
from urlwatch.util import import_module_from_source | ||
|
||
root = os.path.join(os.path.dirname(__file__), '..', '..', '..') | ||
here = os.path.dirname(__file__) | ||
|
||
|
||
class ConfigForTest(CommandConfig): | ||
def __init__(self, config, urls, cache, hooks, verbose): | ||
super().__init__([], 'urlwatch', os.path.dirname(__file__), root, config, urls, hooks, cache, verbose) | ||
|
||
|
||
@contextlib.contextmanager | ||
def teardown_func(): | ||
try: | ||
yield | ||
finally: | ||
"tear down test fixtures" | ||
cache = os.path.join(here, 'data', 'cache.db') | ||
if os.path.exists(cache): | ||
os.remove(cache) | ||
|
||
|
||
def test_run_watcher(): | ||
with teardown_func(): | ||
urls = os.path.join(here, 'data', 'disabled-job.yaml') | ||
config = os.path.join(here, 'data', 'urlwatch.yaml') | ||
cache = os.path.join(here, 'data', 'cache.db') | ||
hooks = '' | ||
|
||
config_storage = YamlConfigStorage(config) | ||
urls_storage = UrlsYaml(urls) | ||
cache_storage = CacheMiniDBStorage(cache) | ||
try: | ||
urlwatch_config = ConfigForTest(config, urls, cache, hooks, True) | ||
|
||
# Prime cache | ||
urlwatcher = Urlwatch(urlwatch_config, config_storage, cache_storage, urls_storage) | ||
urlwatcher.run_jobs() | ||
|
||
# Run multiple times with clean report | ||
for _ in range(100): | ||
urlwatcher = Urlwatch(urlwatch_config, config_storage, cache_storage, urls_storage) | ||
urlwatcher.run_jobs() | ||
for job_state in urlwatcher.report.job_states: | ||
assert job_state.exception is None, 'Job failed during threading test' | ||
assert job_state.verb == 'unchanged', f'Job verb was "{job_state.verb}" for unchanged output during threading test' | ||
finally: | ||
cache_storage.close() |