fix: ensure scheduler starts only once during Flask requests
This commit is contained in:
@@ -153,3 +153,23 @@ class TestScheduler:
|
||||
assert search_data.get(("losangeles", "python")) == 4
|
||||
assert search_data.get(("losangeles", "java")) == 1
|
||||
assert result.get("discovered") == 10 # Total unique jobs
|
||||
|
||||
|
||||
def test_app_scheduler_starts_once(monkeypatch):
|
||||
"""Ensure the Flask before_request hook starts scheduler only once."""
|
||||
import web.app as app_module
|
||||
|
||||
monkeypatch.setenv("SCRAPE_SCHEDULER_ENABLED", "true")
|
||||
monkeypatch.delenv("SERVER_SOFTWARE", raising=False)
|
||||
monkeypatch.delenv("FLASK_RUN_FROM_CLI", raising=False)
|
||||
monkeypatch.delenv("WERKZEUG_RUN_MAIN", raising=False)
|
||||
|
||||
app_module._scheduler_started = False
|
||||
|
||||
with patch("web.app.start_scheduler_in_background") as mock_start:
|
||||
app_module.app.config.update(TESTING=True, WTF_CSRF_ENABLED=False)
|
||||
with app_module.app.test_client() as client:
|
||||
client.get("/health")
|
||||
client.get("/health")
|
||||
|
||||
assert mock_start.call_count == 1
|
||||
|
||||
Reference in New Issue
Block a user