Skip to content

Commit 8dc8aa6

Browse files
committed
Added debug logging
1 parent a2348a6 commit 8dc8aa6

File tree

6 files changed

+152
-17
lines changed

6 files changed

+152
-17
lines changed

dist/LDMPClient.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ var _parsers = require('./parsers');
1616

1717
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1818

19+
// import {FrameParser} from './parsers'
20+
1921
const ACK = Buffer.from('\r');
2022

2123
const DEFAULT_PORT = 1024;
@@ -70,17 +72,34 @@ class LDMPClient extends _events.EventEmitter {
7072
const sock = this.socket = new _net2.default.Socket();
7173

7274
sock.once('connect', () => {
75+
console.log('LDMPClient connect!');
76+
7377
sock.removeAllListeners();
78+
79+
sock.pipe(new _parsers.FrameParser({
80+
matchChar: Buffer.from('\0'),
81+
matchEncoding: 'ascii'
82+
})).pipe(new _parsers.XMLRecordParser()).on('data', data => {
83+
this.emit('record', data);
84+
});
85+
86+
// sock.pipe(new FrameParser({
87+
// matchChar: Buffer.from('\0'),
88+
// matchEncoding: 'ascii'
89+
// })).on('data', data => {
90+
// this.emit('record', data.frame.toString())
91+
// })
92+
7493
resolve(sock);
7594
});
7695
sock.once('error', reject);
7796

78-
sock.pipe(new _parsers.FrameParser({
79-
matchChar: Buffer.from('\0'),
80-
matchEncoding: 'ascii'
81-
})).pipe(new _parsers.XMLRecordParser()).on('data', data => {
82-
this.emit('record', data);
83-
});
97+
// sock.pipe(new FrameParser({
98+
// matchChar: Buffer.from('\0'),
99+
// matchEncoding: 'ascii'
100+
// })).pipe(new XMLRecordParser()).on('data', data => {
101+
// this.emit('record', data)
102+
// })
84103

85104
sock.connect(this.options.port, this.options.host);
86105
});
@@ -106,11 +125,20 @@ class LDMPClient extends _events.EventEmitter {
106125
*/
107126
ack() {
108127
return new Promise((resolve, reject) => {
128+
if (!this.isConnected) console.log('LDMPClient ack not connected');
109129
if (!this.isConnected) return reject(new Error('Not connected'));
110130

111-
this.socket.write(ACK);
131+
try {
132+
this.socket.write(ACK);
133+
134+
console.log('LDMPClient ack sent');
112135

113-
resolve();
136+
resolve();
137+
} catch (err) {
138+
console.log('LDMPClient ack error', err);
139+
140+
reject(err);
141+
}
114142
});
115143
}
116144

@@ -152,6 +180,8 @@ class LDMPClient extends _events.EventEmitter {
152180
tables
153181
});
154182

183+
console.log('LDMPClient specify', `${spec}`);
184+
155185
this.socket.write(spec);
156186

157187
resolve(spec.toString());

dist/parsers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class FrameParser extends _stream.Transform {
2727
let i;
2828
let s = 0;
2929

30+
// console.log('FrameParser._transform chunk', chunk)
31+
3032
try {
3133
this._buf = this._buf ? Buffer.concat([this._buf, chunk], this._buf.length + chunk.length) : chunk;
3234

@@ -69,6 +71,8 @@ class XMLRecordParser extends _stream.Transform {
6971
const errors = [];
7072
const obj = {};
7173

74+
// console.log('XMLRecordParser._transform chunk', chunk)
75+
7276
try {
7377
const xmlDoc = new _xmldom.DOMParser({
7478
errorHandler: {

src/LDMPClient.js

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import net from 'net'
22
import {EventEmitter} from 'events'
33
import {ClientSpecFormatter} from './formatters'
44
import {FrameParser, XMLRecordParser} from './parsers'
5+
// import {FrameParser} from './parsers'
56

67
const ACK = Buffer.from('\r')
78

@@ -57,17 +58,34 @@ export default class LDMPClient extends EventEmitter {
5758
const sock = this.socket = new net.Socket()
5859

5960
sock.once('connect', () => {
61+
console.log('LDMPClient connect!')
62+
6063
sock.removeAllListeners()
64+
65+
sock.pipe(new FrameParser({
66+
matchChar: Buffer.from('\0'),
67+
matchEncoding: 'ascii'
68+
})).pipe(new XMLRecordParser()).on('data', data => {
69+
this.emit('record', data)
70+
})
71+
72+
// sock.pipe(new FrameParser({
73+
// matchChar: Buffer.from('\0'),
74+
// matchEncoding: 'ascii'
75+
// })).on('data', data => {
76+
// this.emit('record', data.frame.toString())
77+
// })
78+
6179
resolve(sock)
6280
})
6381
sock.once('error', reject)
6482

65-
sock.pipe(new FrameParser({
66-
matchChar: Buffer.from('\0'),
67-
matchEncoding: 'ascii'
68-
})).pipe(new XMLRecordParser()).on('data', data => {
69-
this.emit('record', data)
70-
})
83+
// sock.pipe(new FrameParser({
84+
// matchChar: Buffer.from('\0'),
85+
// matchEncoding: 'ascii'
86+
// })).pipe(new XMLRecordParser()).on('data', data => {
87+
// this.emit('record', data)
88+
// })
7189

7290
sock.connect(this.options.port, this.options.host)
7391
})
@@ -96,11 +114,20 @@ export default class LDMPClient extends EventEmitter {
96114
*/
97115
ack () {
98116
return new Promise((resolve, reject) => {
117+
if (!this.isConnected) console.log('LDMPClient ack not connected')
99118
if (!this.isConnected) return reject(new Error('Not connected'))
100119

101-
this.socket.write(ACK)
120+
try {
121+
this.socket.write(ACK)
122+
123+
console.log('LDMPClient ack sent')
102124

103-
resolve()
125+
resolve()
126+
} catch (err) {
127+
console.log('LDMPClient ack error', err)
128+
129+
reject(err)
130+
}
104131
})
105132
}
106133

@@ -145,6 +172,8 @@ export default class LDMPClient extends EventEmitter {
145172
tables
146173
})
147174

175+
console.log('LDMPClient specify', `${spec}`)
176+
148177
this.socket.write(spec)
149178

150179
resolve(spec.toString())

src/parsers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export class FrameParser extends Transform {
1919
let i
2020
let s = 0
2121

22+
// console.log('FrameParser._transform chunk', chunk)
23+
2224
try {
2325
this._buf = this._buf ? Buffer.concat([this._buf, chunk], this._buf.length + chunk.length) : chunk
2426

@@ -61,6 +63,8 @@ export class XMLRecordParser extends Transform {
6163
const errors = []
6264
const obj = {}
6365

66+
// console.log('XMLRecordParser._transform chunk', chunk)
67+
6468
try {
6569
const xmlDoc = new DOMParser({
6670
errorHandler: {

test/01/long-run.spec.js

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/01/test.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Main tests
33
*/
44

5-
describe('Module', function () {
5+
describe.skip('Module', function () {
66
this.timeout(60000)
77

88
const tables = [{

0 commit comments

Comments
 (0)