-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add retries to taxonomy reading. (#205)
When we try to load a taxonomy multiple times concurrently, we run into `FileExistsError`s as the various threads try to cache files at the same location.
- Loading branch information
Showing
2 changed files
with
34 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import concurrent.futures | ||
from unittest.mock import patch | ||
|
||
from arelle import Cntlr | ||
|
||
from ferc_xbrl_extractor.arelle_interface import load_taxonomy | ||
|
||
|
||
def test_concurrent_taxonomy_load(tmp_path): | ||
cntlr = Cntlr.Cntlr() | ||
cntlr.webCache.cacheDir = str(tmp_path) | ||
cntlr.webCache.clear() | ||
path = "https://eCollection.ferc.gov/taxonomy/form60/2022-01-01/form/form60/form-60_2022-01-01.xsd" | ||
with patch("ferc_xbrl_extractor.arelle_interface.Cntlr.Cntlr", lambda: cntlr): | ||
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor: | ||
futures = [executor.submit(load_taxonomy, path) for _ in range(2)] | ||
done, _not_done = concurrent.futures.wait( | ||
futures, timeout=10, return_when=concurrent.futures.ALL_COMPLETED | ||
) | ||
errored = {fut for fut in done if fut.exception()} | ||
assert len(errored) == 0 |