Use electron's DNS resolver, prioritizing ipv4 connections

This commit is contained in:
Fedor Indutny 2023-05-30 16:57:16 -07:00 committed by GitHub
parent 615539ed6d
commit 557b86f52e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 169 additions and 240 deletions

View file

@ -1,67 +0,0 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import * as sinon from 'sinon';
import { DNSCache } from '../../util/dns';
import { SECOND } from '../../util/durations';
const NOW = 1680726906000;
describe('dns/DNSCache', () => {
let sandbox: sinon.SinonSandbox;
let cache: DNSCache;
beforeEach(() => {
sandbox = sinon.createSandbox();
cache = new DNSCache();
});
afterEach(() => {
sandbox.restore();
});
it('should cache records and pick a random one', () => {
sandbox.useFakeTimers({
now: NOW,
});
const result = cache.setAndPick('signal.org', 4, [
{
data: '10.0.0.1',
expiresAt: NOW + SECOND,
},
{
data: '10.0.0.2',
expiresAt: NOW + SECOND,
},
]);
assert.oneOf(result, ['10.0.0.1', '10.0.0.2']);
});
it('should invalidate cache after expiration', () => {
const clock = sandbox.useFakeTimers({
now: NOW,
});
cache.setAndPick('signal.org', 4, [
{
data: '10.0.0.1',
expiresAt: NOW + SECOND,
},
{
data: '10.0.0.2',
expiresAt: NOW + 2 * SECOND,
},
]);
assert.oneOf(cache.get('signal.org', 4), ['10.0.0.1', '10.0.0.2']);
clock.tick(SECOND);
assert.strictEqual(cache.get('signal.org', 4), '10.0.0.2');
clock.tick(SECOND);
assert.strictEqual(cache.get('signal.org', 4), undefined);
});
});