MCPcopy
hub / github.com/ScrapeGraphAI/Scrapegraph-ai / test_lazy_load_sequential_timing

Function test_lazy_load_sequential_timing

tests/test_chromium.py:2147–2166  ·  view source on GitHub ↗

Test that lazy_load runs scraping sequentially rather than concurrently.

(monkeypatch)

Source from the content-addressed store, hash-verified

2145
2146@pytest.mark.asyncio
2147def 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

Callers

nothing calls this directly

Calls 2

lazy_loadMethod · 0.95
ChromiumLoaderClass · 0.90

Tested by

no test coverage detected