Skip to content

Commit 98c8516

Browse files
committed
test: reconfigure(). closes #3
1 parent 65f8df3 commit 98c8516

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

test/client.js

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,5 +2099,156 @@ describe('RPCClient', function(){
20992099

21002100
});
21012101

2102+
describe('#reconfigure', function() {
2103+
2104+
it("should not change identity on reconnect", async () => {
2105+
2106+
const {endpoint, close, server} = await createServer({}, {
2107+
withClient: cli => {
2108+
cli.handle('Drop', () => cli.close());
2109+
cli.handle('GetID', () => cli.identity);
2110+
}
2111+
});
2112+
const cli = new RPCClient({
2113+
endpoint,
2114+
identity: 'X',
2115+
backoff: {
2116+
initialDelay: 1,
2117+
maxDelay: 2,
2118+
}
2119+
});
2120+
2121+
try {
2122+
await cli.connect();
2123+
assert.equal(await cli.call('GetID'), 'X');
2124+
2125+
cli.reconfigure({identity: 'Y'});
2126+
await cli.call('Drop').catch(()=>{});
2127+
2128+
assert.equal(await cli.call('GetID'), 'X');
2129+
2130+
} finally {
2131+
await cli.close();
2132+
close();
2133+
}
2134+
2135+
});
2136+
2137+
it("should change identity on explicit close and connect", async () => {
2138+
2139+
const {endpoint, close, server} = await createServer({}, {
2140+
withClient: cli => {
2141+
cli.handle('Drop', () => cli.close());
2142+
cli.handle('GetID', () => cli.identity);
2143+
}
2144+
});
2145+
const cli = new RPCClient({
2146+
endpoint,
2147+
identity: 'X',
2148+
});
2149+
2150+
try {
2151+
await cli.connect();
2152+
assert.equal(await cli.call('GetID'), 'X');
2153+
2154+
cli.reconfigure({identity: 'Y'});
2155+
await cli.close();
2156+
await cli.connect();
2157+
2158+
assert.equal(await cli.call('GetID'), 'Y');
2159+
2160+
} finally {
2161+
await cli.close();
2162+
close();
2163+
}
2164+
2165+
});
2166+
2167+
it("should be able to adjust queue concurrency", async () => {
2168+
2169+
const {endpoint, close, server} = await createServer({}, {
2170+
withClient: cli => {
2171+
let processing = 0;
2172+
cli.handle('Max', async () => {
2173+
++processing;
2174+
await setTimeout(10);
2175+
return processing--;
2176+
});
2177+
}
2178+
});
2179+
const cli = new RPCClient({
2180+
endpoint,
2181+
identity: 'X',
2182+
callConcurrency: 1,
2183+
});
2184+
2185+
try {
2186+
await cli.connect();
2187+
2188+
const arr = [1,2,3,4,5,6];
2189+
2190+
const cc1 = await Promise.all(arr.map(x => cli.call('Max')));
2191+
cli.reconfigure({callConcurrency: 3});
2192+
const cc3 = await Promise.all(arr.map(x => cli.call('Max')));
2193+
2194+
assert.equal(Math.max(...cc1), 1);
2195+
assert.equal(Math.max(...cc3), 3);
2196+
2197+
} finally {
2198+
await cli.close();
2199+
close();
2200+
}
2201+
2202+
});
2203+
2204+
it("should be able to adjust backoff configuration", async () => {
2205+
2206+
const {endpoint, close, server} = await createServer({}, {
2207+
withClient: cli => {
2208+
cli.handle('Drop', () => cli.close());
2209+
}
2210+
});
2211+
const cli = new RPCClient({
2212+
endpoint,
2213+
identity: 'X',
2214+
backoff: {
2215+
initialDelay: 1,
2216+
maxDelay: 2,
2217+
}
2218+
});
2219+
2220+
try {
2221+
await cli.connect();
2222+
2223+
await cli.call('Drop').catch(() => {});
2224+
const t1 = Date.now();
2225+
await once(cli, 'open');
2226+
const r1 = Date.now() - t1;
2227+
2228+
cli.reconfigure({
2229+
backoff: {
2230+
initialDelay: 30,
2231+
maxDelay: 31,
2232+
}
2233+
});
2234+
2235+
await cli.call('Drop').catch(() => {});
2236+
const t2 = Date.now();
2237+
await once(cli, 'open');
2238+
const r2 = Date.now() - t2;
2239+
2240+
assert.ok(r1 < 20);
2241+
assert.ok(r2 > 20);
2242+
2243+
} finally {
2244+
await cli.close();
2245+
close();
2246+
}
2247+
2248+
});
2249+
2250+
2251+
});
2252+
21022253
});
21032254

0 commit comments

Comments
 (0)