mirror of
https://github.com/sofastack/sofa-rpc-node.git
synced 2026-01-25 16:06:26 +00:00
feat: without registry & serverHost in unittest env (#23)
This commit is contained in:
parent
b1283696ca
commit
2499080b4e
@ -18,7 +18,7 @@ class RpcConsumer extends Base {
|
||||
constructor(options = {}) {
|
||||
assert(options.interfaceName, '[RpcConsumer] options.interfaceName is required');
|
||||
assert(options.logger, '[RpcConsumer] options.logger is required');
|
||||
assert(options.serverHost || options.registry, '[RpcConsumer] options.registry or options.serverHost at least set one');
|
||||
assert(options.allowMock || options.serverHost || options.registry, '[RpcConsumer] options.registry or options.serverHost at least set one');
|
||||
assert(options.connectionManager, '[RpcConsumer] options.connectionManager is required');
|
||||
super({ initMethod: '_init' });
|
||||
|
||||
@ -73,13 +73,15 @@ class RpcConsumer extends Base {
|
||||
if (this.options.serverHost) {
|
||||
const addressList = this.options.serverHost.split(',').map(url => this.parseUrl(url));
|
||||
setImmediate(() => { this._addressGroup.addressList = addressList; });
|
||||
} else {
|
||||
} else if (this.registry) {
|
||||
await this.registry.ready();
|
||||
this._addressGroup = this.createAddressGroup(this.id + '@' + this.group);
|
||||
this._addressListener = addressList => {
|
||||
this._addressGroup.addressList = addressList.map(url => this.parseUrl(url));
|
||||
};
|
||||
this.registry.subscribe(this.registryConfig, this._addressListener);
|
||||
} else {
|
||||
setImmediate(() => { this._addressGroup.addressList = []; });
|
||||
}
|
||||
await this._addressGroup.ready();
|
||||
}
|
||||
|
||||
@ -66,4 +66,29 @@ describe('test/client/client.test.js', () => {
|
||||
|
||||
await client.close();
|
||||
});
|
||||
|
||||
it('should support without registry or serverHost in unittest env', async function() {
|
||||
const client = new RpcClient({
|
||||
protocol,
|
||||
logger,
|
||||
allowMock: true, // 标识当前支持 mock
|
||||
});
|
||||
const consumer = client.createConsumer({
|
||||
interfaceName: 'com.alipay.sofa.rpc.test.ProtoService',
|
||||
targetAppName: 'pb',
|
||||
});
|
||||
await consumer.ready();
|
||||
|
||||
const args = [{
|
||||
name: 'Peter',
|
||||
group: 'A',
|
||||
}];
|
||||
try {
|
||||
await consumer.invoke('echoObj', args);
|
||||
assert(false);
|
||||
} catch (err) {
|
||||
assert(err.name === 'RpcNoProviderError');
|
||||
assert(err.message === 'No provider of com.alipay.sofa.rpc.test.ProtoService:1.0@SOFA:echoObj() found!');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -340,6 +340,7 @@ describe('test/client/connection.test.js', () => {
|
||||
assert(res.error.message.includes('this request is block by circuit breaker, HealthCounts'));
|
||||
|
||||
await sleep(connection._circuitBreaker.config.sleepWindowInMilliseconds);
|
||||
await sleep(10);
|
||||
|
||||
res = await connection.invoke(req);
|
||||
assert.deepEqual(res, { error: null, appResponse: 3, responseProps: null });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user