pogi 3.0.0-beta2 → 3.0.0-beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/.env +5 -0
  2. package/lib/connectionOptions.d.ts +1 -4
  3. package/lib/pgDb.d.ts +8 -8
  4. package/lib/pgDb.js +7 -7
  5. package/lib/pgDb.js.map +1 -1
  6. package/lib/pgDbInterface.d.ts +1 -32
  7. package/lib/pgDbInterface.js +8 -8
  8. package/lib/pgDbInterface.js.map +1 -1
  9. package/lib/pgSchema.d.ts +7 -9
  10. package/lib/pgSchema.js.map +1 -1
  11. package/lib/pgSchemaInterface.d.ts +0 -12
  12. package/lib/pgSchemaInterface.js +0 -1
  13. package/lib/pgTable.d.ts +4 -4
  14. package/lib/pgTableInterface.d.ts +0 -74
  15. package/lib/pgTableInterface.js.map +1 -1
  16. package/lib/pgUtils.d.ts +5 -5
  17. package/lib/pgUtils.js.map +1 -1
  18. package/lib/queryAble.d.ts +3 -4
  19. package/lib/queryAble.js +3 -3
  20. package/lib/queryAble.js.map +1 -1
  21. package/lib/queryAbleInterface.d.ts +4 -4
  22. package/lib/test/pgDbOperatorSpec.d.ts +1 -0
  23. package/lib/test/pgDbOperatorSpec.js +326 -0
  24. package/lib/test/pgDbOperatorSpec.js.map +1 -0
  25. package/lib/test/pgDbSpec.d.ts +1 -0
  26. package/lib/test/pgDbSpec.js +1139 -0
  27. package/lib/test/pgDbSpec.js.map +1 -0
  28. package/lib/test/pgServiceRestartTest.d.ts +1 -0
  29. package/lib/test/pgServiceRestartTest.js +1532 -0
  30. package/lib/test/pgServiceRestartTest.js.map +1 -0
  31. package/package.json +1 -1
  32. package/src/bin/generateInterface.ts +0 -54
  33. package/src/connectionOptions.ts +0 -77
  34. package/src/index.d.ts +0 -7
  35. package/src/index.ts +0 -6
  36. package/src/pgConverters.test.ts +0 -10
  37. package/src/pgConverters.ts +0 -59
  38. package/src/pgDb.test.ts +0 -1324
  39. package/src/pgDb.ts +0 -842
  40. package/src/pgDbInterface.ts +0 -57
  41. package/src/pgDbLogger.ts +0 -13
  42. package/src/pgDbOperators.test.ts +0 -478
  43. package/src/pgDbOperators.ts +0 -85
  44. package/src/pgSchema.ts +0 -16
  45. package/src/pgSchemaInterface.ts +0 -12
  46. package/src/pgTable.ts +0 -369
  47. package/src/pgTableInterface.ts +0 -131
  48. package/src/pgUtils.ts +0 -300
  49. package/src/queryAble.ts +0 -365
  50. package/src/queryAbleInterface.ts +0 -104
  51. package/src/queryWhere.ts +0 -325
  52. package/src/test/init.sql +0 -122
  53. package/src/test/pgServiceRestartTest.ts +0 -1500
  54. package/src/test/throw_exception.sql +0 -5
  55. package/src/test/tricky.sql +0 -13
@@ -0,0 +1,1532 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const pgDb_1 = require("../pgDb");
5
+ const yargs = require("yargs");
6
+ const shell = require("shelljs");
7
+ let argv = yargs
8
+ .usage('node pgServiceRestartTest.js\n Usage: $0')
9
+ .option('postgresOn', {
10
+ describe: 'the command line command which switches on the postgresql server',
11
+ type: "string"
12
+ })
13
+ .option('postgresOff', {
14
+ describe: 'the command line command which switches off the postgresql server',
15
+ type: "string"
16
+ })
17
+ .option('testParams', {
18
+ describe: 'check postgres Off & On params',
19
+ type: "boolean"
20
+ })
21
+ .argv;
22
+ function runCommand(command, options) {
23
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
24
+ return new Promise((resolve, reject) => {
25
+ shell.exec(command, { silent: options ? options.silent : true }, (code, stdout, stderr) => {
26
+ resolve({ stdout, stderr });
27
+ });
28
+ });
29
+ });
30
+ }
31
+ function asyncWaitMs(ms) {
32
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
33
+ yield new Promise(r => setTimeout(r, ms));
34
+ });
35
+ }
36
+ function syncWaitMs(ms) {
37
+ let origDate = +new Date();
38
+ let actDate = origDate;
39
+ while (origDate + ms > actDate) {
40
+ actDate = +new Date();
41
+ }
42
+ }
43
+ function postgresOff() {
44
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
45
+ console.log('Kill postgres server.');
46
+ yield runCommand(argv.postgresOff);
47
+ });
48
+ }
49
+ function postgresOn() {
50
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
51
+ console.log('Start postgres server.');
52
+ yield runCommand(argv.postgresOn);
53
+ yield asyncWaitMs(500);
54
+ });
55
+ }
56
+ const poolSize = 3;
57
+ function testSchemaClear(db) {
58
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
59
+ yield db.run(`drop table if exists pgdb_test.names`);
60
+ yield db.run(`DROP TYPE IF EXISTS pgdb_test.mood CASCADE`);
61
+ yield db.run(`DROP TABLE IF EXISTS pgdb_test."enumArrayTable"`);
62
+ });
63
+ }
64
+ function testSchemaInit(db) {
65
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
66
+ yield testSchemaClear(db);
67
+ yield db.run(`create table pgdb_test.names (name varchar null)`);
68
+ yield db.run(`insert into pgdb_test.names (name) values ('Kuka'), ('Hapci')`);
69
+ yield db.run(`CREATE TYPE pgdb_test.mood AS ENUM('sad', 'ok', 'happy')`);
70
+ yield db.run(`CREATE TABLE pgdb_test."enumArrayTable"(m pgdb_test.mood[] NULL)`);
71
+ yield db.run(`INSERT INTO pgdb_test."enumArrayTable"(m) values (ARRAY['sad'::pgdb_test.mood, 'happy'::pgdb_test.mood])`);
72
+ });
73
+ }
74
+ function testDbFreeConnections(db) {
75
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
76
+ let dedicatedConnections = new Array(poolSize).fill(null);
77
+ yield Promise.race([
78
+ asyncWaitMs(1000),
79
+ (() => tslib_1.__awaiter(this, void 0, void 0, function* () {
80
+ for (let i = 0; i < dedicatedConnections.length; ++i) {
81
+ dedicatedConnections[i] = yield db.dedicatedConnectionBegin();
82
+ }
83
+ }))()
84
+ ]);
85
+ if (dedicatedConnections.some(v => !v)) {
86
+ return new Error('Some of the connections are not free!');
87
+ }
88
+ for (let conn of dedicatedConnections) {
89
+ yield conn.dedicatedConnectionEnd();
90
+ }
91
+ return null;
92
+ });
93
+ }
94
+ function testInsertQuery(db) {
95
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
96
+ let tableContents = yield db.query(`select * from pgdb_test.names`);
97
+ if (tableContents.length != 2) {
98
+ return new Error('Simple query fails');
99
+ }
100
+ let callbackCounter1 = 0;
101
+ yield db.queryWithOnCursorCallback(`select * from pgdb_test.names`, {}, {}, (data) => {
102
+ ++callbackCounter1;
103
+ });
104
+ if (callbackCounter1 != 2) {
105
+ return new Error('Query with cursor callback fails');
106
+ }
107
+ let callbackCounter2 = 0;
108
+ let stream = yield db.queryAsStream(`select * from pgdb_test.names`);
109
+ yield new Promise((resolve, reject) => {
110
+ stream.on("data", (data) => {
111
+ ++callbackCounter2;
112
+ });
113
+ stream.on('error', reject);
114
+ stream.on('close', resolve);
115
+ });
116
+ if (callbackCounter2 != 2) {
117
+ return new Error('Query as stream fails');
118
+ }
119
+ return null;
120
+ });
121
+ }
122
+ function testNotificationSystem(db) {
123
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
124
+ let result;
125
+ yield db.listen('testChannel', (data) => { result = data.payload; });
126
+ yield db.notify('testChannel', 'newData');
127
+ yield asyncWaitMs(1000);
128
+ if (result != 'newData') {
129
+ return new Error('Notification not working...');
130
+ }
131
+ yield db.unlisten('testChannel');
132
+ });
133
+ }
134
+ function testDbUsability(db) {
135
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
136
+ try {
137
+ console.log('TestSchemaInit');
138
+ yield testSchemaInit(db);
139
+ console.log('TestFreeConnections');
140
+ let error = yield testDbFreeConnections(db);
141
+ if (!error) {
142
+ console.log('TestInsertQueries');
143
+ error = yield testInsertQuery(db);
144
+ }
145
+ if (!error) {
146
+ console.log('TestNotifications');
147
+ error = yield testNotificationSystem(db);
148
+ }
149
+ yield testSchemaClear(db);
150
+ return error;
151
+ }
152
+ catch (e) {
153
+ return e;
154
+ }
155
+ });
156
+ }
157
+ function runTestInternal(db, test) {
158
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
159
+ let callCounter = 0;
160
+ let errorResult = null;
161
+ try {
162
+ yield test.fn(db, (value) => {
163
+ ++callCounter;
164
+ if (!value && !errorResult) {
165
+ errorResult = new Error(`Error in test at the ${callCounter}. call.`);
166
+ }
167
+ });
168
+ }
169
+ catch (err) {
170
+ if (!errorResult) {
171
+ errorResult = err;
172
+ }
173
+ }
174
+ yield postgresOn();
175
+ if (!errorResult && !test.skipTestDb) {
176
+ errorResult = yield testDbUsability(db);
177
+ }
178
+ return errorResult;
179
+ });
180
+ }
181
+ let actTestCounter = 0;
182
+ let errorMessages = [];
183
+ function runTest(allTestCount, test) {
184
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
185
+ ++actTestCounter;
186
+ console.log('====================================================================================');
187
+ console.log(`${actTestCounter}/${allTestCount} Test starting: "${test.name}"`);
188
+ console.log('====================================================================================');
189
+ yield postgresOn();
190
+ let db = yield pgDb_1.PgDb.connect({
191
+ poolSize,
192
+ logger: {
193
+ log: console.log,
194
+ error: console.error
195
+ }
196
+ });
197
+ yield testSchemaInit(db);
198
+ let error = yield runTestInternal(db, test);
199
+ if (error) {
200
+ errorMessages.push({ testName: test.name, err: error });
201
+ }
202
+ yield db.close();
203
+ console.log('====================================================================================');
204
+ if (error) {
205
+ console.log(`${actTestCounter}/${allTestCount} Test errored: "${test.name}"`);
206
+ }
207
+ else {
208
+ console.log(`${actTestCounter}/${allTestCount} Test passed: "${test.name}"`);
209
+ }
210
+ console.log('====================================================================================');
211
+ });
212
+ }
213
+ let newConnectionTests = [
214
+ {
215
+ name: 'simple query 1',
216
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
217
+ let stageCounter = 0;
218
+ yield postgresOff();
219
+ try {
220
+ yield db.query(`select * from pgdb_test.names`);
221
+ isTrue(false);
222
+ }
223
+ catch (e) {
224
+ ++stageCounter;
225
+ }
226
+ try {
227
+ yield db.query(`select * from pgdb_test.names`);
228
+ isTrue(false);
229
+ }
230
+ catch (e) {
231
+ ++stageCounter;
232
+ }
233
+ isTrue(stageCounter == 2);
234
+ })
235
+ },
236
+ {
237
+ name: 'simple query 2',
238
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
239
+ let stageCounter = 0;
240
+ yield postgresOff();
241
+ try {
242
+ yield db.query(`select * from pgdb_test."enumArrayTable"`);
243
+ isTrue(false);
244
+ }
245
+ catch (e) {
246
+ ++stageCounter;
247
+ }
248
+ try {
249
+ yield db.query(`select * from pgdb_test."enumArrayTable"`);
250
+ isTrue(false);
251
+ }
252
+ catch (e) {
253
+ ++stageCounter;
254
+ }
255
+ isTrue(stageCounter == 2);
256
+ })
257
+ },
258
+ {
259
+ name: 'queryWithCallback 1 - postgresOff before call',
260
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
261
+ let stageCounter = 0;
262
+ yield postgresOff();
263
+ try {
264
+ yield db.queryWithOnCursorCallback(`select * from pgdb_test.names`, {}, {}, () => {
265
+ isTrue(false);
266
+ });
267
+ isTrue(false);
268
+ }
269
+ catch (e) {
270
+ ++stageCounter;
271
+ }
272
+ isTrue(stageCounter == 1);
273
+ })
274
+ },
275
+ {
276
+ name: 'queryWithCallback 2 - postgresOff between calls',
277
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
278
+ let stageCounter = 0;
279
+ let params = new Array(2000).fill(null).map((v, i) => `'Smith${i}'`).map(v => `(${v})`).join(', ');
280
+ yield db.run(`INSERT INTO pgdb_test.names(name) values ${params}`);
281
+ let i = 0;
282
+ let fn1 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
283
+ try {
284
+ yield db.queryWithOnCursorCallback('select * from pgdb_test.names', {}, {}, (data) => {
285
+ syncWaitMs(20);
286
+ ++i;
287
+ if (i % 10 == 0) {
288
+ console.log('Record:', i);
289
+ }
290
+ });
291
+ isTrue(false);
292
+ }
293
+ catch (e) {
294
+ ++stageCounter;
295
+ }
296
+ });
297
+ let fn2 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
298
+ console.log('Wait before postgres off...');
299
+ yield asyncWaitMs(100);
300
+ yield postgresOff();
301
+ });
302
+ yield Promise.all([fn1(), fn2()]);
303
+ isTrue(i > 0 && i < 2000);
304
+ isTrue(stageCounter == 1);
305
+ }),
306
+ },
307
+ {
308
+ name: 'queryWithCallback 3 - postgresOff between calls, unknown oid',
309
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
310
+ let stageCounter = 0;
311
+ let params = new Array(2000).fill(null).map((v) => `ARRAY['sad'::pgdb_test.mood, 'happy'::pgdb_test.mood]`).map(v => `(${v})`).join(', ');
312
+ yield db.run(`INSERT INTO pgdb_test."enumArrayTable"(m) values ${params}`);
313
+ let i = 0;
314
+ let fn1 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
315
+ try {
316
+ yield db.queryWithOnCursorCallback('select * from pgdb_test."enumArrayTable"', {}, {}, (data) => {
317
+ syncWaitMs(20);
318
+ ++i;
319
+ if (i % 10 == 0) {
320
+ console.log('Record:', i);
321
+ }
322
+ });
323
+ isTrue(false);
324
+ }
325
+ catch (e) {
326
+ ++stageCounter;
327
+ }
328
+ });
329
+ let fn2 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
330
+ console.log('Wait before postgres off...');
331
+ yield asyncWaitMs(100);
332
+ yield postgresOff();
333
+ });
334
+ yield Promise.all([fn1(), fn2()]);
335
+ isTrue(i > 0 && i < 2000);
336
+ isTrue(stageCounter == 1);
337
+ }),
338
+ },
339
+ {
340
+ name: 'queryAsStream 1 - postgresOff before call',
341
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
342
+ let stageCounter = 0;
343
+ yield postgresOff();
344
+ try {
345
+ let stream = yield db.queryAsStream(`select * from pgdb_test.names`);
346
+ isTrue(false);
347
+ }
348
+ catch (e) {
349
+ ++stageCounter;
350
+ }
351
+ isTrue(stageCounter == 1);
352
+ })
353
+ },
354
+ {
355
+ name: 'queryAsStream 2 - postgresOff between calls',
356
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
357
+ let stageCounter = 0;
358
+ let params = new Array(2000).fill(null).map((v, i) => `'Smith${i}'`).map(v => `(${v})`).join(', ');
359
+ yield db.run(`INSERT INTO pgdb_test.names(name) values ${params}`);
360
+ let stream = yield db.queryAsStream('select * from pgdb_test.names');
361
+ let i = 0;
362
+ let promise1 = new Promise((resolve, reject) => {
363
+ stream.on("data", (data) => {
364
+ syncWaitMs(20);
365
+ ++i;
366
+ if (i % 10 == 0) {
367
+ console.log(data.name);
368
+ }
369
+ });
370
+ stream.on('error', (...params) => {
371
+ ++stageCounter;
372
+ reject(...params);
373
+ });
374
+ stream.on('close', resolve);
375
+ });
376
+ let fn2 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
377
+ yield asyncWaitMs(100);
378
+ yield postgresOff();
379
+ });
380
+ try {
381
+ yield Promise.all([promise1, fn2()]);
382
+ isTrue(false);
383
+ }
384
+ catch (e) {
385
+ ++stageCounter;
386
+ }
387
+ isTrue(i > 0 && i < 2000);
388
+ isTrue(stageCounter == 2);
389
+ })
390
+ },
391
+ {
392
+ name: 'queryAsStream 3 - postgresOff between calls, unknown oid',
393
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
394
+ let stageCounter = 0;
395
+ let params = new Array(2000).fill(null).map((v) => `ARRAY['sad'::pgdb_test.mood, 'happy'::pgdb_test.mood]`).map(v => `(${v})`).join(', ');
396
+ yield db.run(`INSERT INTO pgdb_test."enumArrayTable"(m) values ${params}`);
397
+ let stream = yield db.queryAsStream('select * from pgdb_test."enumArrayTable"');
398
+ let i = 0;
399
+ let promise1 = new Promise((resolve, reject) => {
400
+ stream.on("data", (data) => {
401
+ syncWaitMs(20);
402
+ ++i;
403
+ if (i % 10 == 0) {
404
+ console.log(data.name);
405
+ }
406
+ });
407
+ stream.on('error', (...params) => {
408
+ ++stageCounter;
409
+ reject(...params);
410
+ });
411
+ stream.on('close', resolve);
412
+ });
413
+ let fn2 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
414
+ yield asyncWaitMs(100);
415
+ yield postgresOff();
416
+ });
417
+ try {
418
+ yield Promise.all([promise1, fn2()]);
419
+ isTrue(false);
420
+ }
421
+ catch (e) {
422
+ ++stageCounter;
423
+ }
424
+ isTrue(i == 0);
425
+ isTrue(stageCounter == 2);
426
+ yield postgresOff();
427
+ })
428
+ },
429
+ ];
430
+ let dedicatedConnection_SimpleQueryTests = [
431
+ {
432
+ name: 'dedicated connection - empty 1',
433
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
434
+ let stageCounter = 0;
435
+ yield postgresOff();
436
+ try {
437
+ let db0 = yield db.dedicatedConnectionBegin();
438
+ isTrue(false);
439
+ }
440
+ catch (e) {
441
+ ++stageCounter;
442
+ }
443
+ isTrue(stageCounter == 1);
444
+ })
445
+ },
446
+ {
447
+ name: 'dedicated connection - empty 2',
448
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
449
+ let stageCounter = 0;
450
+ let db0 = yield db.dedicatedConnectionBegin();
451
+ yield postgresOff();
452
+ try {
453
+ yield db0.dedicatedConnectionEnd();
454
+ ++stageCounter;
455
+ }
456
+ catch (e) {
457
+ isTrue(false);
458
+ }
459
+ isTrue(stageCounter == 1);
460
+ })
461
+ },
462
+ {
463
+ name: 'dedicated connection - simple query 1',
464
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
465
+ let stageCounter = 0;
466
+ let db0 = yield db.dedicatedConnectionBegin();
467
+ yield postgresOff();
468
+ try {
469
+ yield db0.query(`select * from pgdb_test.names`);
470
+ isTrue(false);
471
+ }
472
+ catch (e) {
473
+ ++stageCounter;
474
+ }
475
+ isTrue(stageCounter == 1);
476
+ })
477
+ },
478
+ {
479
+ name: 'dedicated connection - simple query 2',
480
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
481
+ let stageCounter = 0;
482
+ let db0 = yield db.dedicatedConnectionBegin();
483
+ yield postgresOff();
484
+ try {
485
+ yield db0.query(`select * from pgdb_test.names`);
486
+ isTrue(false);
487
+ }
488
+ catch (e) {
489
+ ++stageCounter;
490
+ }
491
+ try {
492
+ yield db0.dedicatedConnectionEnd();
493
+ ++stageCounter;
494
+ }
495
+ catch (e) {
496
+ isTrue(false);
497
+ }
498
+ isTrue(stageCounter == 2);
499
+ })
500
+ },
501
+ {
502
+ name: 'dedicated connection - simple query 3',
503
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
504
+ let stageCounter = 0;
505
+ let db0 = yield db.dedicatedConnectionBegin();
506
+ yield db0.run(`truncate pgdb_test.names`);
507
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
508
+ yield postgresOff();
509
+ try {
510
+ yield db0.dedicatedConnectionEnd();
511
+ ++stageCounter;
512
+ }
513
+ catch (e) {
514
+ isTrue(false);
515
+ }
516
+ yield postgresOn();
517
+ let result = yield db.query(`select * from pgdb_test.names`);
518
+ isTrue(result[0].name == 'Morgo');
519
+ isTrue(stageCounter == 1);
520
+ })
521
+ },
522
+ {
523
+ name: 'dedicated connection - simple query 4',
524
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
525
+ let stageCounter = 0;
526
+ let db0 = yield db.dedicatedConnectionBegin();
527
+ yield db0.run(`truncate pgdb_test.names`);
528
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
529
+ yield postgresOff();
530
+ try {
531
+ yield db0.query(`select * from pgdb_test.names`);
532
+ isTrue(false);
533
+ }
534
+ catch (e) {
535
+ ++stageCounter;
536
+ }
537
+ yield postgresOn();
538
+ let result = yield db.query(`select * from pgdb_test.names`);
539
+ isTrue(result[0].name == 'Morgo');
540
+ isTrue(stageCounter == 1);
541
+ })
542
+ },
543
+ {
544
+ name: 'dedicated connection - simple query 5',
545
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
546
+ let stageCounter = 0;
547
+ let db0 = yield db.dedicatedConnectionBegin();
548
+ yield db0.run(`truncate pgdb_test.names`);
549
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
550
+ yield postgresOff();
551
+ try {
552
+ yield db0.query(`select * from pgdb_test.names`);
553
+ isTrue(false);
554
+ }
555
+ catch (e) {
556
+ ++stageCounter;
557
+ }
558
+ try {
559
+ yield db0.dedicatedConnectionEnd();
560
+ ++stageCounter;
561
+ }
562
+ catch (e) {
563
+ isTrue(false);
564
+ }
565
+ yield postgresOn();
566
+ let result = yield db.query(`select * from pgdb_test.names`);
567
+ isTrue(result[0].name == 'Morgo');
568
+ isTrue(stageCounter == 2);
569
+ })
570
+ },
571
+ {
572
+ name: 'dedicated connection - simple query 6',
573
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
574
+ let stageCounter = 0;
575
+ let db0 = yield db.dedicatedConnectionBegin();
576
+ yield db0.run(`truncate pgdb_test.names`);
577
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
578
+ yield postgresOff();
579
+ try {
580
+ yield db0.query(`select * from pgdb_test.names`);
581
+ isTrue(false);
582
+ }
583
+ catch (e) {
584
+ ++stageCounter;
585
+ }
586
+ yield postgresOn();
587
+ try {
588
+ yield db0.dedicatedConnectionEnd();
589
+ ++stageCounter;
590
+ }
591
+ catch (e) {
592
+ isTrue(false);
593
+ }
594
+ let result = yield db.query(`select * from pgdb_test.names`);
595
+ isTrue(result[0].name == 'Morgo');
596
+ isTrue(stageCounter == 2);
597
+ })
598
+ },
599
+ {
600
+ name: 'transaction - simple query 7',
601
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
602
+ let stageCounter = 0;
603
+ yield db.run(`truncate pgdb_test.names`);
604
+ let db0 = yield db.transactionBegin();
605
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
606
+ yield postgresOff();
607
+ try {
608
+ yield db0.query(`select * from pgdb_test.names`);
609
+ isTrue(false);
610
+ }
611
+ catch (e) {
612
+ ++stageCounter;
613
+ }
614
+ yield postgresOn();
615
+ let result = yield db.query(`select * from pgdb_test.names`);
616
+ isTrue(result.length == 0);
617
+ isTrue(stageCounter == 1);
618
+ })
619
+ },
620
+ {
621
+ name: 'transaction - simple query 8',
622
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
623
+ let stageCounter = 0;
624
+ yield db.run(`truncate pgdb_test.names`);
625
+ let db0 = yield db.transactionBegin();
626
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
627
+ yield postgresOff();
628
+ try {
629
+ yield db0.query(`select * from pgdb_test.names`);
630
+ isTrue(false);
631
+ }
632
+ catch (e) {
633
+ ++stageCounter;
634
+ }
635
+ yield postgresOn();
636
+ try {
637
+ yield db0.transactionCommit();
638
+ isTrue(false);
639
+ }
640
+ catch (e) {
641
+ ++stageCounter;
642
+ }
643
+ let result = yield db.query(`select * from pgdb_test.names`);
644
+ isTrue(result.length == 0);
645
+ isTrue(stageCounter == 2);
646
+ })
647
+ },
648
+ {
649
+ name: 'transaction - simple query 9',
650
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
651
+ let stageCounter = 0;
652
+ yield db.run(`truncate pgdb_test.names`);
653
+ let db0 = yield db.transactionBegin();
654
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
655
+ yield postgresOff();
656
+ try {
657
+ yield db0.query(`select * from pgdb_test.names`);
658
+ isTrue(false);
659
+ }
660
+ catch (e) {
661
+ ++stageCounter;
662
+ }
663
+ try {
664
+ yield db0.transactionCommit();
665
+ isTrue(false);
666
+ }
667
+ catch (e) {
668
+ ++stageCounter;
669
+ }
670
+ yield postgresOn();
671
+ let result = yield db.query(`select * from pgdb_test.names`);
672
+ isTrue(result.length == 0);
673
+ isTrue(stageCounter == 2);
674
+ })
675
+ },
676
+ {
677
+ name: 'transaction - simple query 10',
678
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
679
+ let stageCounter = 0;
680
+ yield db.run(`truncate pgdb_test.names`);
681
+ let db0 = yield db.transactionBegin();
682
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
683
+ yield postgresOff();
684
+ try {
685
+ yield db0.query(`select * from pgdb_test.names`);
686
+ isTrue(false);
687
+ }
688
+ catch (e) {
689
+ ++stageCounter;
690
+ }
691
+ yield postgresOn();
692
+ let result = yield db.query(`select * from pgdb_test.names`);
693
+ isTrue(result.length == 0);
694
+ isTrue(stageCounter == 1);
695
+ })
696
+ },
697
+ {
698
+ name: 'transaction - simple query 11',
699
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
700
+ let stageCounter = 0;
701
+ yield db.run(`truncate pgdb_test.names`);
702
+ let db0 = yield db.transactionBegin();
703
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
704
+ yield postgresOff();
705
+ try {
706
+ yield db0.transactionCommit();
707
+ isTrue(false);
708
+ }
709
+ catch (e) {
710
+ ++stageCounter;
711
+ }
712
+ yield postgresOn();
713
+ let result = yield db.query(`select * from pgdb_test.names`);
714
+ isTrue(result.length == 0);
715
+ isTrue(stageCounter == 1);
716
+ })
717
+ },
718
+ {
719
+ name: 'transaction - rollback 1',
720
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
721
+ let stageCounter = 0;
722
+ yield db.run(`truncate pgdb_test.names`);
723
+ let db0 = yield db.transactionBegin();
724
+ yield postgresOff();
725
+ try {
726
+ yield db0.transactionRollback();
727
+ isTrue(false);
728
+ }
729
+ catch (e) {
730
+ ++stageCounter;
731
+ }
732
+ isTrue(stageCounter == 1);
733
+ })
734
+ },
735
+ {
736
+ name: 'transaction - rollback 2',
737
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
738
+ let stageCounter = 0;
739
+ yield db.run(`truncate pgdb_test.names`);
740
+ let db0 = yield db.transactionBegin();
741
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
742
+ yield postgresOff();
743
+ try {
744
+ yield db0.transactionRollback();
745
+ isTrue(false);
746
+ }
747
+ catch (e) {
748
+ ++stageCounter;
749
+ }
750
+ isTrue(stageCounter == 1);
751
+ })
752
+ },
753
+ {
754
+ name: 'transaction - rollback 3',
755
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
756
+ let stageCounter = 0;
757
+ yield db.run(`truncate pgdb_test.names`);
758
+ let db0 = yield db.transactionBegin();
759
+ yield postgresOff();
760
+ try {
761
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
762
+ isTrue(false);
763
+ }
764
+ catch (e) {
765
+ ++stageCounter;
766
+ }
767
+ try {
768
+ yield db0.transactionRollback();
769
+ isTrue(false);
770
+ }
771
+ catch (e) {
772
+ ++stageCounter;
773
+ }
774
+ isTrue(stageCounter == 2);
775
+ })
776
+ },
777
+ {
778
+ name: 'transaction - rollback 4',
779
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
780
+ let stageCounter = 0;
781
+ yield db.run(`truncate pgdb_test.names`);
782
+ let db0 = yield db.transactionBegin();
783
+ yield postgresOff();
784
+ try {
785
+ yield db0.run(`insert into pgdb_test.names (name) values ('Morgo')`);
786
+ isTrue(false);
787
+ }
788
+ catch (e) {
789
+ ++stageCounter;
790
+ }
791
+ yield postgresOn();
792
+ try {
793
+ yield db0.transactionRollback();
794
+ isTrue(false);
795
+ }
796
+ catch (e) {
797
+ ++stageCounter;
798
+ }
799
+ isTrue(stageCounter == 2);
800
+ })
801
+ }
802
+ ];
803
+ let dedicatedConnection_StreamQueryTests = [
804
+ {
805
+ name: 'dedicated connection queryWithCallback - 1',
806
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
807
+ let stageCounter = 0;
808
+ let db0 = yield db.dedicatedConnectionBegin();
809
+ yield postgresOff();
810
+ let i = 0;
811
+ try {
812
+ yield db0.queryWithOnCursorCallback(`select * from pgdb_test.names`, {}, {}, (data) => { ++i; });
813
+ isTrue(false);
814
+ }
815
+ catch (e) {
816
+ ++stageCounter;
817
+ }
818
+ isTrue(i == 0);
819
+ isTrue(stageCounter == 1);
820
+ })
821
+ },
822
+ {
823
+ name: 'dedicated connection queryWithCallback - 1',
824
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
825
+ let stageCounter = 0;
826
+ let db0 = yield db.dedicatedConnectionBegin();
827
+ yield postgresOff();
828
+ let i = 0;
829
+ try {
830
+ yield db0.queryWithOnCursorCallback(`select * from pgdb_test.names`, {}, {}, (data) => { ++i; });
831
+ isTrue(false);
832
+ }
833
+ catch (e) {
834
+ ++stageCounter;
835
+ }
836
+ try {
837
+ yield db0.dedicatedConnectionEnd();
838
+ ++stageCounter;
839
+ }
840
+ catch (e) {
841
+ isTrue(false);
842
+ }
843
+ isTrue(i == 0);
844
+ isTrue(stageCounter == 2);
845
+ })
846
+ },
847
+ {
848
+ name: 'dedicated connection queryWithCallback - 3',
849
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
850
+ let stageCounter = 0;
851
+ let db0 = yield db.dedicatedConnectionBegin();
852
+ yield postgresOff();
853
+ try {
854
+ yield db0.query(`select * from pgdb_test.names`);
855
+ isTrue(false);
856
+ }
857
+ catch (e) {
858
+ ++stageCounter;
859
+ }
860
+ let i = 0;
861
+ try {
862
+ yield db0.queryWithOnCursorCallback(`select * from pgdb_test.names`, {}, {}, (data) => { ++i; });
863
+ isTrue(false);
864
+ }
865
+ catch (e) {
866
+ ++stageCounter;
867
+ }
868
+ isTrue(i == 0);
869
+ isTrue(stageCounter == 2);
870
+ })
871
+ },
872
+ {
873
+ name: 'dedicated connection queryWithCallback 4 - postgresOff between calls',
874
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
875
+ let stageCounter = 0;
876
+ let params = new Array(2000).fill(null).map((v, i) => `'Smith${i}'`).map(v => `(${v})`).join(', ');
877
+ yield db.run(`INSERT INTO pgdb_test.names(name) values ${params}`);
878
+ let db0 = yield db.dedicatedConnectionBegin();
879
+ let i = 0;
880
+ let fn1 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
881
+ try {
882
+ yield db0.queryWithOnCursorCallback('select * from pgdb_test.names', {}, {}, (data) => {
883
+ syncWaitMs(20);
884
+ ++i;
885
+ if (i % 10 == 0) {
886
+ console.log('Record:', i);
887
+ }
888
+ });
889
+ isTrue(false);
890
+ }
891
+ catch (e) {
892
+ ++stageCounter;
893
+ }
894
+ });
895
+ let fn2 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
896
+ console.log('Wait before postgres off...');
897
+ yield asyncWaitMs(100);
898
+ yield postgresOff();
899
+ });
900
+ yield Promise.all([fn1(), fn2()]);
901
+ isTrue(i > 0 && i < 2000);
902
+ isTrue(stageCounter == 1);
903
+ }),
904
+ },
905
+ {
906
+ name: 'dedicated connection queryWithCallback 5 - postgresOff between calls, unknown oid',
907
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
908
+ let stageCounter = 0;
909
+ let params = new Array(2000).fill(null).map((v) => `ARRAY['sad'::pgdb_test.mood, 'happy'::pgdb_test.mood]`).map(v => `(${v})`).join(', ');
910
+ yield db.run(`INSERT INTO pgdb_test."enumArrayTable"(m) values ${params}`);
911
+ let db0 = yield db.dedicatedConnectionBegin();
912
+ let i = 0;
913
+ let fn1 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
914
+ try {
915
+ yield db0.queryWithOnCursorCallback('select * from pgdb_test."enumArrayTable"', {}, {}, (data) => {
916
+ syncWaitMs(20);
917
+ ++i;
918
+ if (i % 10 == 0) {
919
+ console.log('Record:', i);
920
+ }
921
+ });
922
+ isTrue(false);
923
+ }
924
+ catch (e) {
925
+ ++stageCounter;
926
+ }
927
+ });
928
+ let fn2 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
929
+ console.log('Wait before postgres off...');
930
+ yield asyncWaitMs(100);
931
+ yield postgresOff();
932
+ });
933
+ yield Promise.all([fn1(), fn2()]);
934
+ isTrue(i > 0 && i < 2000);
935
+ isTrue(stageCounter == 1);
936
+ }),
937
+ },
938
+ {
939
+ name: 'dedicated connection queryAsStream - 1',
940
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
941
+ let stageCounter = 0;
942
+ let db0 = yield db.dedicatedConnectionBegin();
943
+ yield postgresOff();
944
+ let stream;
945
+ try {
946
+ stream = yield db0.queryAsStream(`select * from pgdb_test.names`);
947
+ ++stageCounter;
948
+ }
949
+ catch (e) {
950
+ isTrue(false);
951
+ }
952
+ try {
953
+ yield new Promise((resolve, reject) => {
954
+ stream.on("data", (data) => {
955
+ isTrue(false);
956
+ });
957
+ stream.on('error', (...params) => {
958
+ ++stageCounter;
959
+ reject(...params);
960
+ });
961
+ stream.on('close', resolve);
962
+ });
963
+ isTrue(false);
964
+ }
965
+ catch (e) {
966
+ ++stageCounter;
967
+ }
968
+ isTrue(stageCounter == 3);
969
+ })
970
+ },
971
+ {
972
+ name: 'dedicated connection queryAsStream - 2',
973
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
974
+ let stageCounter = 0;
975
+ let db0 = yield db.dedicatedConnectionBegin();
976
+ yield postgresOff();
977
+ let stream;
978
+ try {
979
+ stream = yield db0.queryAsStream(`select * from pgdb_test.names`);
980
+ ++stageCounter;
981
+ }
982
+ catch (e) {
983
+ isTrue(false);
984
+ }
985
+ try {
986
+ yield new Promise((resolve, reject) => {
987
+ stream.on("data", (data) => {
988
+ isTrue(false);
989
+ });
990
+ stream.on('error', (...params) => {
991
+ ++stageCounter;
992
+ reject(...params);
993
+ });
994
+ stream.on('close', resolve);
995
+ });
996
+ isTrue(false);
997
+ }
998
+ catch (e) {
999
+ ++stageCounter;
1000
+ }
1001
+ try {
1002
+ yield db0.dedicatedConnectionEnd();
1003
+ ++stageCounter;
1004
+ }
1005
+ catch (e) {
1006
+ isTrue(false);
1007
+ }
1008
+ isTrue(stageCounter == 4);
1009
+ })
1010
+ },
1011
+ {
1012
+ name: 'dedicated connection queryAsStream - 3',
1013
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1014
+ let stageCounter = 0;
1015
+ let db0 = yield db.dedicatedConnectionBegin();
1016
+ yield postgresOff();
1017
+ try {
1018
+ yield db0.query(`select * from pgdb_test.names`);
1019
+ isTrue(false);
1020
+ }
1021
+ catch (e) {
1022
+ ++stageCounter;
1023
+ }
1024
+ let stream;
1025
+ try {
1026
+ stream = yield db0.queryAsStream(`select * from pgdb_test.names`);
1027
+ ++stageCounter;
1028
+ }
1029
+ catch (e) {
1030
+ isTrue(false);
1031
+ }
1032
+ try {
1033
+ yield new Promise((resolve, reject) => {
1034
+ stream.on("data", (data) => {
1035
+ isTrue(false);
1036
+ });
1037
+ stream.on('error', (...params) => {
1038
+ ++stageCounter;
1039
+ reject(...params);
1040
+ });
1041
+ stream.on('close', resolve);
1042
+ });
1043
+ isTrue(false);
1044
+ }
1045
+ catch (e) {
1046
+ ++stageCounter;
1047
+ }
1048
+ isTrue(stageCounter == 4);
1049
+ })
1050
+ },
1051
+ {
1052
+ name: 'dedicated connection queryAsStream 4 - postgresOff between calls',
1053
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1054
+ let stageCounter = 0;
1055
+ let params = new Array(2000).fill(null).map((v, i) => `'Smith${i}'`).map(v => `(${v})`).join(', ');
1056
+ yield db.run(`INSERT INTO pgdb_test.names(name) values ${params}`);
1057
+ let db0 = yield db.dedicatedConnectionBegin();
1058
+ let stream = yield db0.queryAsStream('select * from pgdb_test.names');
1059
+ let i = 0;
1060
+ let promise1 = new Promise((resolve, reject) => {
1061
+ stream.on("data", (data) => {
1062
+ syncWaitMs(20);
1063
+ ++i;
1064
+ if (i % 10 == 0) {
1065
+ console.log(data.name);
1066
+ }
1067
+ });
1068
+ stream.on('error', (...params) => {
1069
+ ++stageCounter;
1070
+ reject(...params);
1071
+ });
1072
+ stream.on('close', resolve);
1073
+ });
1074
+ let fn2 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1075
+ yield asyncWaitMs(100);
1076
+ yield postgresOff();
1077
+ });
1078
+ try {
1079
+ yield Promise.all([promise1, fn2()]);
1080
+ isTrue(false);
1081
+ }
1082
+ catch (e) {
1083
+ ++stageCounter;
1084
+ }
1085
+ isTrue(i > 0 && i < 2000);
1086
+ isTrue(stageCounter == 2);
1087
+ }),
1088
+ },
1089
+ {
1090
+ name: 'dedicated connection queryAsStream 5 - postgresOff between calls, unknown oid',
1091
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1092
+ let stageCounter = 0;
1093
+ let params = new Array(2000).fill(null).map((v) => `ARRAY['sad'::pgdb_test.mood, 'happy'::pgdb_test.mood]`).map(v => `(${v})`).join(', ');
1094
+ yield db.run(`INSERT INTO pgdb_test."enumArrayTable"(m) values ${params}`);
1095
+ let db0 = yield db.dedicatedConnectionBegin();
1096
+ let stream = yield db0.queryAsStream('select * from pgdb_test."enumArrayTable"');
1097
+ let i = 0;
1098
+ let promise1 = new Promise((resolve, reject) => {
1099
+ stream.on("data", (data) => {
1100
+ syncWaitMs(20);
1101
+ ++i;
1102
+ if (i % 10 == 0) {
1103
+ console.log(data.name);
1104
+ }
1105
+ });
1106
+ stream.on('error', (...params) => {
1107
+ ++stageCounter;
1108
+ reject(...params);
1109
+ });
1110
+ stream.on('close', resolve);
1111
+ });
1112
+ let fn2 = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1113
+ yield asyncWaitMs(100);
1114
+ yield postgresOff();
1115
+ });
1116
+ try {
1117
+ yield Promise.all([promise1, fn2()]);
1118
+ isTrue(false);
1119
+ }
1120
+ catch (e) {
1121
+ ++stageCounter;
1122
+ }
1123
+ isTrue(i == 0);
1124
+ isTrue(stageCounter == 2);
1125
+ yield postgresOff();
1126
+ }),
1127
+ }
1128
+ ];
1129
+ let postgresRestartTests = [
1130
+ {
1131
+ name: 'postgres restart 1',
1132
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1133
+ let stageCounter = 0;
1134
+ let db0 = yield db.dedicatedConnectionBegin();
1135
+ yield postgresOff();
1136
+ yield postgresOn();
1137
+ try {
1138
+ yield db0.dedicatedConnectionEnd();
1139
+ ++stageCounter;
1140
+ }
1141
+ catch (e) {
1142
+ isTrue(false);
1143
+ }
1144
+ isTrue(stageCounter == 1);
1145
+ })
1146
+ },
1147
+ {
1148
+ name: 'postgres restart 2',
1149
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1150
+ let stageCounter = 0;
1151
+ let db0 = yield db.transactionBegin();
1152
+ yield postgresOff();
1153
+ yield postgresOn();
1154
+ try {
1155
+ yield db0.transactionRollback();
1156
+ isTrue(false);
1157
+ }
1158
+ catch (e) {
1159
+ ++stageCounter;
1160
+ }
1161
+ isTrue(stageCounter == 1);
1162
+ })
1163
+ },
1164
+ {
1165
+ name: 'postgres restart 3',
1166
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1167
+ let stageCounter = 0;
1168
+ let db0 = yield db.dedicatedConnectionBegin();
1169
+ yield postgresOff();
1170
+ yield postgresOn();
1171
+ try {
1172
+ let result = yield db0.query(`select * from pgdb_test.names`);
1173
+ isTrue(false);
1174
+ }
1175
+ catch (e) {
1176
+ ++stageCounter;
1177
+ }
1178
+ isTrue(stageCounter == 1);
1179
+ })
1180
+ },
1181
+ {
1182
+ name: 'postgres restart 4',
1183
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1184
+ let stageCounter = 0;
1185
+ let db0 = yield db.dedicatedConnectionBegin();
1186
+ yield postgresOff();
1187
+ yield postgresOn();
1188
+ try {
1189
+ let result = yield db0.queryWithOnCursorCallback(`select * from pgdb_test.names`, {}, {}, (data) => {
1190
+ isTrue(false);
1191
+ });
1192
+ isTrue(false);
1193
+ }
1194
+ catch (e) {
1195
+ ++stageCounter;
1196
+ }
1197
+ isTrue(stageCounter == 1);
1198
+ })
1199
+ },
1200
+ {
1201
+ name: 'postgres restart 5',
1202
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1203
+ let stageCounter = 0;
1204
+ let db0 = yield db.dedicatedConnectionBegin();
1205
+ yield postgresOff();
1206
+ yield postgresOn();
1207
+ let stream;
1208
+ try {
1209
+ stream = yield db0.queryAsStream(`select * from pgdb_test.names`);
1210
+ ++stageCounter;
1211
+ }
1212
+ catch (e) {
1213
+ isTrue(false);
1214
+ }
1215
+ try {
1216
+ yield new Promise((resolve, reject) => {
1217
+ stream.on("data", (data) => {
1218
+ isTrue(false);
1219
+ });
1220
+ stream.on('error', (...params) => {
1221
+ ++stageCounter;
1222
+ reject(...params);
1223
+ });
1224
+ stream.on('close', resolve);
1225
+ });
1226
+ isTrue(false);
1227
+ }
1228
+ catch (e) {
1229
+ ++stageCounter;
1230
+ }
1231
+ isTrue(stageCounter == 3);
1232
+ })
1233
+ },
1234
+ ];
1235
+ let postgresEndTests = [
1236
+ {
1237
+ name: 'postgres end 1',
1238
+ skipTestDb: true,
1239
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1240
+ let stageCounter = 0;
1241
+ let db0 = yield db.dedicatedConnectionBegin();
1242
+ yield postgresOff();
1243
+ try {
1244
+ yield db.close();
1245
+ ++stageCounter;
1246
+ }
1247
+ catch (e) {
1248
+ isTrue(false);
1249
+ }
1250
+ isTrue(stageCounter == 1);
1251
+ })
1252
+ }
1253
+ ];
1254
+ let notifyTests = [
1255
+ {
1256
+ name: 'notification 1',
1257
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1258
+ let stageCounter = 0;
1259
+ yield postgresOff();
1260
+ try {
1261
+ yield db.listen('newChannel', (notif) => { });
1262
+ isTrue(false);
1263
+ }
1264
+ catch (e) {
1265
+ ++stageCounter;
1266
+ }
1267
+ isTrue(stageCounter == 1);
1268
+ })
1269
+ },
1270
+ {
1271
+ name: 'notification 2',
1272
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1273
+ yield db.listen('newChannel', (notif) => { });
1274
+ yield postgresOff();
1275
+ yield postgresOn();
1276
+ yield db.unlisten('newChannel');
1277
+ })
1278
+ },
1279
+ {
1280
+ name: 'notification 3',
1281
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1282
+ let result;
1283
+ yield db.listen('newChannel', (notif) => { result = notif.payload; });
1284
+ yield postgresOff();
1285
+ yield postgresOn();
1286
+ yield db.notify('newChannel', 'newValue');
1287
+ yield asyncWaitMs(1000);
1288
+ isTrue(result == 'newValue');
1289
+ yield db.unlisten('newChannel');
1290
+ })
1291
+ },
1292
+ {
1293
+ name: 'notification 4',
1294
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1295
+ let result;
1296
+ yield db.listen('newChannel', (notif) => { result = notif.payload; });
1297
+ yield postgresOff();
1298
+ yield postgresOn();
1299
+ yield db.run(`notify "newChannel", 'newValue'`);
1300
+ yield asyncWaitMs(1000);
1301
+ isTrue(result == 'newValue');
1302
+ yield db.unlisten('newChannel');
1303
+ })
1304
+ },
1305
+ {
1306
+ name: 'notification 5',
1307
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1308
+ let result;
1309
+ yield db.listen('newChannel', (notif) => { result = notif.payload; });
1310
+ yield postgresOff();
1311
+ yield postgresOn();
1312
+ let db0 = yield db.dedicatedConnectionBegin();
1313
+ yield db0.run(`notify "newChannel", 'newValue'`);
1314
+ yield asyncWaitMs(1000);
1315
+ isTrue(result == 'newValue');
1316
+ yield db.unlisten('newChannel');
1317
+ yield db0.dedicatedConnectionEnd();
1318
+ })
1319
+ },
1320
+ {
1321
+ name: 'notification 6',
1322
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1323
+ let i = 0;
1324
+ let fn1 = (notif) => { i += +notif.payload; };
1325
+ let fn2 = (notif) => { i += 2 * (+notif.payload); };
1326
+ yield db.listen('newChannel', fn1);
1327
+ yield postgresOff();
1328
+ yield db.listen('newChannel', fn2);
1329
+ yield postgresOn();
1330
+ yield db.notify('newChannel', '1');
1331
+ yield asyncWaitMs(1000);
1332
+ isTrue(i == 3);
1333
+ yield db.unlisten('newChannel');
1334
+ })
1335
+ },
1336
+ {
1337
+ name: 'notification 7',
1338
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1339
+ let i = 0;
1340
+ let fn1 = (notif) => { i += +notif.payload; };
1341
+ let fn2 = (notif) => { i += 2 * (+notif.payload); };
1342
+ yield db.listen('newChannel', fn1);
1343
+ yield postgresOff();
1344
+ yield db.listen('newChannel', fn2);
1345
+ yield db.unlisten('newChannel', fn1);
1346
+ yield postgresOn();
1347
+ yield db.notify('newChannel', '1');
1348
+ yield asyncWaitMs(1000);
1349
+ isTrue(i == 2);
1350
+ yield db.unlisten('newChannel');
1351
+ })
1352
+ },
1353
+ {
1354
+ name: 'notification 8',
1355
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1356
+ let i = 0;
1357
+ let j = 0;
1358
+ let fn1 = (notif) => { i += +notif.payload; };
1359
+ let fn2 = (notif) => { j += +notif.payload; };
1360
+ yield db.listen('newChannel', fn1);
1361
+ yield postgresOff();
1362
+ try {
1363
+ yield db.listen('newChannel2', fn2);
1364
+ isTrue(false);
1365
+ }
1366
+ catch (e) {
1367
+ }
1368
+ yield postgresOn();
1369
+ yield db.notify('newChannel', '1');
1370
+ yield db.notify('newChannel2', '1');
1371
+ yield asyncWaitMs(1000);
1372
+ isTrue(i == 1);
1373
+ isTrue(j == 0);
1374
+ yield db.unlisten('newChannel');
1375
+ })
1376
+ },
1377
+ {
1378
+ name: 'notification 9',
1379
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1380
+ let i = 0;
1381
+ let fn1 = (notif) => { i += +notif.payload; };
1382
+ yield db.listen('newChannel', fn1);
1383
+ yield postgresOff();
1384
+ try {
1385
+ yield db.unlisten('newChannel', fn1);
1386
+ isTrue(false);
1387
+ }
1388
+ catch (e) {
1389
+ }
1390
+ yield postgresOn();
1391
+ yield db.notify('newChannel', '1');
1392
+ yield asyncWaitMs(1000);
1393
+ isTrue(i == 1);
1394
+ yield db.unlisten('newChannel');
1395
+ })
1396
+ },
1397
+ {
1398
+ name: 'notification 10',
1399
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1400
+ let i = 0;
1401
+ let fn1 = (notif) => { i += +notif.payload; };
1402
+ yield db.listen('newChannel', fn1);
1403
+ yield postgresOff();
1404
+ try {
1405
+ yield db.unlisten('newChannel');
1406
+ isTrue(false);
1407
+ }
1408
+ catch (e) {
1409
+ }
1410
+ yield postgresOn();
1411
+ yield db.notify('newChannel', '1');
1412
+ yield asyncWaitMs(1000);
1413
+ isTrue(i == 1);
1414
+ yield db.unlisten('newChannel');
1415
+ })
1416
+ },
1417
+ {
1418
+ name: 'notification 11 - automatic notification restart...',
1419
+ fn: (db, isTrue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1420
+ let i = 0;
1421
+ let fn1 = (notif) => { i += +notif.payload; };
1422
+ yield db.listen('newChannel', fn1);
1423
+ yield postgresOff();
1424
+ yield postgresOn();
1425
+ yield asyncWaitMs(3000);
1426
+ let db2 = yield pgDb_1.PgDb.connect({});
1427
+ yield db2.notify('newChannel', '1');
1428
+ yield db2.close();
1429
+ yield asyncWaitMs(1000);
1430
+ isTrue(i == 1);
1431
+ yield db.unlisten('newChannel');
1432
+ })
1433
+ }
1434
+ ];
1435
+ function testParams() {
1436
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
1437
+ console.log('Start testing params');
1438
+ let postgresOnCommandOk = true;
1439
+ let postgresOffCommandOk = false;
1440
+ let frameworkError = false;
1441
+ try {
1442
+ console.log('Postgres On test');
1443
+ yield postgresOn();
1444
+ try {
1445
+ let db = yield pgDb_1.PgDb.connect({});
1446
+ }
1447
+ catch (e) {
1448
+ postgresOnCommandOk = false;
1449
+ }
1450
+ console.log('Postgres Off test');
1451
+ yield postgresOff();
1452
+ try {
1453
+ let db = yield pgDb_1.PgDb.connect({});
1454
+ }
1455
+ catch (e) {
1456
+ postgresOffCommandOk = postgresOnCommandOk;
1457
+ }
1458
+ console.log('Postgres On test');
1459
+ yield postgresOn();
1460
+ try {
1461
+ let db = yield pgDb_1.PgDb.connect({});
1462
+ }
1463
+ catch (e) {
1464
+ postgresOnCommandOk = false;
1465
+ }
1466
+ }
1467
+ catch (e) {
1468
+ console.log('Unknown exception has found', e);
1469
+ frameworkError = true;
1470
+ }
1471
+ if (!frameworkError) {
1472
+ if (postgresOffCommandOk && postgresOnCommandOk) {
1473
+ console.log('Postgres On/Off commands OK');
1474
+ }
1475
+ else {
1476
+ if (!postgresOnCommandOk) {
1477
+ console.log('Postgres On command NOT OK');
1478
+ }
1479
+ if (!postgresOffCommandOk) {
1480
+ console.log('Postgres Off command NOT OK');
1481
+ }
1482
+ }
1483
+ }
1484
+ console.log('Postgres On/Off test end');
1485
+ });
1486
+ }
1487
+ function runTests() {
1488
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
1489
+ console.log('Start tests');
1490
+ let allTests = [
1491
+ ...newConnectionTests,
1492
+ ...dedicatedConnection_SimpleQueryTests,
1493
+ ...dedicatedConnection_StreamQueryTests,
1494
+ ...postgresRestartTests,
1495
+ ...notifyTests,
1496
+ ...postgresEndTests
1497
+ ];
1498
+ let testNamePrefix = '';
1499
+ try {
1500
+ if (testNamePrefix) {
1501
+ allTests = allTests.filter(v => v.name.startsWith(testNamePrefix));
1502
+ }
1503
+ for (let test of allTests) {
1504
+ yield runTest(allTests.length, test);
1505
+ }
1506
+ console.log('All tests: ', actTestCounter);
1507
+ console.log(`Problematic tests: ${errorMessages.length}`);
1508
+ for (let errorMessage of errorMessages) {
1509
+ console.log(`Error in "${errorMessage.testName}"`);
1510
+ console.log(errorMessage.err);
1511
+ }
1512
+ }
1513
+ catch (e) {
1514
+ console.log('Error has found in the test framework!');
1515
+ console.log(e);
1516
+ }
1517
+ console.log('All tests are finished');
1518
+ });
1519
+ }
1520
+ (() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
1521
+ if (!argv.postgresOn || !argv.postgresOff) {
1522
+ console.log('postgresOn or postgresOff parameter is missing!');
1523
+ return;
1524
+ }
1525
+ if (argv.testParams) {
1526
+ yield testParams();
1527
+ }
1528
+ else {
1529
+ yield runTests();
1530
+ }
1531
+ }))().catch(console.log);
1532
+ //# sourceMappingURL=pgServiceRestartTest.js.map