Skip to content

Commit

Permalink
test: put dns disk cache behind a flag.
Browse files Browse the repository at this point in the history
When actively woring on the claim related test cases, setting
HSD_TEST_DNS_FILE_CACHE=true will cache the requests locally.
NOTE: the cache does not have any expiration logic.
  • Loading branch information
nodech committed Dec 5, 2023
1 parent 6fec5d9 commit 357b420
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/util/stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class CachedStubResolver extends StubResolver {
super(options);

this.enabled = true;
this.cacheOnDisk = false;
this.cacheFile = path.join(tmpdir(), 'hsd', 'dns-cache.json');
this.cacheOnDisk = process.env['HSD_TEST_DNS_FILE_CACHE'] === 'true';
this.cacheDir = path.join(tmpdir(), 'hsd-test');
this.cacheFile = path.join(this.cacheDir, 'dns-cache.json');

this.loadCacheSync();
}
Expand All @@ -27,6 +28,9 @@ class CachedStubResolver extends StubResolver {
if (!this.cacheOnDisk)
return;

if (!fs.existsSync(this.cacheDir))
fs.mkdirSync(this.cacheDir);

if (fs.existsSync(this.cacheFile))
CACHE = JSON.parse(fs.readFileSync(this.cacheFile, 'utf8'));
}
Expand Down

0 comments on commit 357b420

Please sign in to comment.