Refactor VPN proxy components and update related behavior
This commit is contained in:
+10
-22
@@ -1,5 +1,4 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import http from 'node:http';
|
||||
import test from 'node:test';
|
||||
|
||||
import {
|
||||
@@ -21,38 +20,27 @@ test('operation conflicts block domain controls but leave copy and navigation al
|
||||
}
|
||||
}
|
||||
|
||||
const refreshing = { subscriptionRefresh: { status: 'running' } };
|
||||
const refreshing = { profileRefresh: { status: 'running', target: 'primary' } };
|
||||
assert.equal(operationBlocked(refreshing, 'connection'), true);
|
||||
assert.equal(operationBlocked(refreshing, 'serverApply'), true);
|
||||
assert.equal(operationBlocked(refreshing, 'subscriptionDelete'), true);
|
||||
assert.equal(operationBlocked(refreshing, 'copy'), false);
|
||||
assert.equal(operationBlocked(refreshing, 'navigation'), false);
|
||||
assert.equal(operationBlocked(refreshing, 'profileDelete'), true);
|
||||
|
||||
const applying = { serverApply: { status: 'running' } };
|
||||
const applying = { serverApply: { status: 'running', target: 'primary:server' } };
|
||||
assert.equal(operationBlocked(applying, 'connection'), true);
|
||||
assert.equal(operationBlocked(applying, 'subscriptionRefresh'), true);
|
||||
assert.equal(operationBlocked(applying, 'copy'), false);
|
||||
assert.equal(operationBlocked(applying, 'profileRefresh'), true);
|
||||
});
|
||||
|
||||
test('double click shares one in-flight request end to end', async (t) => {
|
||||
test('double click shares one in-flight request end to end', async () => {
|
||||
const request = deferred();
|
||||
let requests = 0;
|
||||
const server = http.createServer((request, response) => {
|
||||
requests += 1;
|
||||
setTimeout(() => {
|
||||
response.writeHead(200, { 'content-type': 'application/json' });
|
||||
response.end('{"success":true}');
|
||||
}, 20);
|
||||
});
|
||||
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
||||
t.after(() => new Promise((resolve) => server.close(resolve)));
|
||||
|
||||
const registry = createOperationRegistry();
|
||||
const action = () => fetch(`http://127.0.0.1:${server.address().port}/apply`).then((response) => response.json());
|
||||
const first = registry.run('serverApply', action);
|
||||
const second = registry.run('serverApply', action);
|
||||
const action = () => { requests += 1; return request.promise; };
|
||||
const first = registry.run('serverApply', action, 'primary:server');
|
||||
const second = registry.run('serverApply', action, 'primary:server');
|
||||
|
||||
assert.equal(second, first);
|
||||
assert.equal(registry.getSnapshot().serverApply.status, 'running');
|
||||
request.resolve({ success: true });
|
||||
assert.deepEqual(await first, { success: true });
|
||||
assert.equal(requests, 1);
|
||||
assert.deepEqual(registry.getSnapshot(), {});
|
||||
|
||||
Reference in New Issue
Block a user