Test that lazy_load runs scraping sequentially rather than concurrently.
(monkeypatch)
| 2145 | |
| 2146 | @pytest.mark.asyncio |
| 2147 | def test_lazy_load_sequential_timing(monkeypatch): |
| 2148 | """Test that lazy_load runs scraping sequentially rather than concurrently.""" |
| 2149 | urls = ["http://example.com/1", "http://example.com/2", "http://example.com/3"] |
| 2150 | loader = ChromiumLoader(urls, backend="playwright", requires_js_support=False) |
| 2151 | |
| 2152 | async def dummy_scraper_with_delay(url, browser_name="chromium"): |
| 2153 | await asyncio.sleep(0.5) |
| 2154 | return f"<html>Delayed content for {url}</html>" |
| 2155 | |
| 2156 | monkeypatch.setattr(loader, "ascrape_playwright", dummy_scraper_with_delay) |
| 2157 | start = time.monotonic() |
| 2158 | docs = list(loader.lazy_load()) |
| 2159 | elapsed = time.monotonic() - start |
| 2160 | # At least 0.5 seconds per URL should be observed. |
| 2161 | assert elapsed >= 1.5, ( |
| 2162 | f"Sequential lazy_load took too little time: {elapsed:.2f} seconds" |
| 2163 | ) |
| 2164 | for doc, url in zip(docs, urls): |
| 2165 | assert f"Delayed content for {url}" in doc.page_content |
| 2166 | assert doc.metadata["source"] == url |
| 2167 | |
| 2168 | |
| 2169 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected