Skip to content

Commit ec7e4ef

Browse files
authored
Merge pull request #33 from hapinessjs/next
Next into master
2 parents dc9cbd2 + 3868079 commit ec7e4ef

7 files changed

Lines changed: 13 additions & 38 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hapiness/rabbitmq",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Hapiness module for rabbitmq",
55
"main": "commonjs/index.js",
66
"types": "index.d.ts",

src/module/managers/channel-manager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export class ChannelManager extends EventEmitter {
2222
this._connection = connectionManager.connection;
2323
this._prefetch = prefetch;
2424
this._global = global;
25+
this._connectionManager.on('error', () => {
26+
this._isConnected = false;
27+
});
2528
}
2629

2730
get prefetch(): number {

src/module/managers/connection-manager.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { events } from '../events';
77
import { ChannelStore } from './channel-store';
88
import { ChannelManager } from './channel-manager';
99

10-
export const REGEX_URI = /^amqp:\/\/([^@\n]+:[^@\n]+@)?(\w+)(:?)(\d{0,6})(\/[\w%]+)?(\?(?:&?[^=&\s]*=[^=&\s]*)+)?$/;
11-
1210
const debug = require('debug')('hapiness:rabbitmq');
1311

1412
export class ConnectionManager extends EventEmitter {
@@ -38,10 +36,6 @@ export class ConnectionManager extends EventEmitter {
3836
}
3937

4038
if (this._options.uri) {
41-
if (!this._options.uri.match(REGEX_URI)) {
42-
throw new Error('Invalid uri');
43-
}
44-
4539
this._uri = this._options.uri;
4640
} else {
4741
const port = this._options.port || 5672;
@@ -53,7 +47,9 @@ export class ConnectionManager extends EventEmitter {
5347
}
5448

5549
// Will block new connection if SIGTERM is received
50+
/* istanbul ignore next */
5651
process.once('SIGTERM', () => this._isSIGTERMReceived = true);
52+
/* istanbul ignore next */
5753
process.once('SIGINT', () => this._isSIGTERMReceived = true);
5854

5955
this.setDefaultPrefetch(this._options.default_prefetch);
@@ -109,6 +105,7 @@ export class ConnectionManager extends EventEmitter {
109105
return Observable.of(null);
110106
}
111107

108+
/* istanbul ignore next */
112109
if (this._isSIGTERMReceived) {
113110
return Observable.of(null);
114111
}

test/unit/extension/init-extension.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export class InitExtensionUnitTest {
2323
private userQueue;
2424

2525
before() {
26-
this.ch = new ChannelManager(<any>{connection: {}});
26+
const connection = new ConnectionManagerMock();
27+
this.ch = new ChannelManager(connection);
2728
this.ch['ch'] = <any>new ChannelMock();
2829
this.userQueue = new UserQueue();
2930
this.queueWrapper = new QueueWrapper(this.userQueue, extractMetadataByDecorator(UserQueue, 'Queue'));

test/unit/managers/connection.test.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,41 +49,14 @@ export class ConnectionUnitTest {
4949
});
5050
}
5151

52-
@test(' - Test options.uri')
53-
testOptionsUri() {
54-
const urisOk = [
55-
'amqp://localhost',
56-
'amqp://hello:world@localhost',
57-
'amqp://hello:world@localhost:98798',
58-
'amqp://hello:world@localhost:98798/vhost',
59-
'amqp://hello:world@localhost:98798/%2Fvhost',
60-
'amqp://hello:world@localhost:98798'
61-
];
62-
63-
const urisNOk = ['not_good', ' amqp://localhost', 'amqp://xxx:zzzzz@', 'amqp://xxx:zzzzz#/322d'];
64-
65-
urisOk.forEach(uri => {
66-
const instance = new ConnectionManager({ uri });
67-
unit.object(instance).isInstanceOf(ConnectionManager);
68-
});
69-
70-
urisNOk.forEach(uri => {
71-
unit
72-
.exception(_ => {
73-
unit.when('Invalid uri', new ConnectionManager({ uri }));
74-
})
75-
.isInstanceOf(Error)
76-
.hasProperty('message', 'Invalid uri');
77-
});
78-
}
79-
8052
@test(' - Test options')
8153
testOptions() {
8254
const options = [
8355
[{ login: 'keyboard', password: 'cat' }, 'amqp://keyboard:cat@localhost:5672'],
8456
[{ retry: { maximum_attempts: 0 } }, 'amqp://localhost:5672'],
8557
[{ params: { heartBeat: 30 } }, 'amqp://localhost:5672?heartBeat=30'],
8658
[{ params: { heartBeat: 30 }, vhost: '/my_vhost' }, 'amqp://localhost:5672/%2Fmy_vhost?heartBeat=30'],
59+
[{ uri: 'amqp://localhost:5672/%2Fmy_vhost?heartBeat=30' }, 'amqp://localhost:5672/%2Fmy_vhost?heartBeat=30'],
8760
[undefined, 'amqp://localhost:5672']
8861
];
8962

test/unit/managers/queue.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { UserExchange } from '../../fixtures/Exchanges';
1111
import { generateMessage } from '../../mocks/Message';
1212
import { extractMetadataByDecorator } from '@hapiness/core';
1313
import { MessageStore } from '../../../src';
14+
import { ConnectionManagerMock } from '../../mocks/ConnectionManager';
1415

1516
@suite('- Unit Queue')
1617
export class QueueServiceUnitTest {
@@ -31,7 +32,7 @@ export class QueueServiceUnitTest {
3132
}
3233

3334
before() {
34-
this.ch = new ChannelManager(<any>{ connection: {}});
35+
this.ch = new ChannelManager(new ConnectionManagerMock());
3536
this.ch.setChannel(new ChannelMock());
3637
unit.spy(this.ch.getChannel(), 'assertQueue');
3738
unit.spy(this.ch.getChannel(), 'bindQueue');

0 commit comments

Comments
 (0)