Skip to content

Commit 02ff571

Browse files
committed
MLE-24722 - make sure the done() method called within each test once and only once. Set reasonable timeouts for some of the bulk operations and remove infinite timeouts which can hang the test.
1 parent 0c36e94 commit 02ff571

12 files changed

+178
-81
lines changed

test-basic/annTopK.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ describe('tests for annTopK', function () {
8989
planAnnTopKOptionsMap)
9090
.orderBy(p.col('name'))
9191
);
92+
done(new Error('Expecting an error to be thrown due to invalid key in options argument'));
9293
} catch(error){
9394
assert(error.message.toString().includes('options argument at 4 of PlanModifyPlan.annTopK() has invalid key- invalid'))
9495
done();

test-basic/basePath-test.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ describe('basePath tests', function() {
1717
testconfig.restWriterConnectionWithBasePath.basePath = 'invalid';
1818
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
1919
dbWriter.documents.write(writeObject)
20-
.result(function(response){})
20+
.result(function(response){
21+
done(new Error('Expecting an error to be thrown due to invalid basePath'));
22+
})
2123
.catch(err=>
2224
{
2325
assert(err.toString().includes('path: invalid/v1/documents'));
@@ -29,7 +31,9 @@ describe('basePath tests', function() {
2931
testconfig.restWriterConnectionWithBasePath.basePath = '/invalid';
3032
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
3133
dbWriter.documents.write(writeObject)
32-
.result(function(response){})
34+
.result(function(response){
35+
done(new Error('Expecting an error to be thrown due to invalid basePath with a leading slash'));
36+
})
3337
.catch(err=>
3438
{
3539
assert(err.toString().includes('path: /invalid/v1/documents'));
@@ -41,7 +45,9 @@ describe('basePath tests', function() {
4145
testconfig.restWriterConnectionWithBasePath.basePath = 'invalid/';
4246
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
4347
dbWriter.documents.write(writeObject)
44-
.result(function(response){})
48+
.result(function(response){
49+
done(new Error('Expecting an error to be thrown due to invalid basePath with a trailing slash'));
50+
})
4551
.catch(err=>
4652
{
4753
assert(err.toString().includes('path: invalid/v1/documents'));
@@ -53,7 +59,9 @@ describe('basePath tests', function() {
5359
testconfig.restWriterConnectionWithBasePath.basePath = '/invalid/';
5460
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
5561
dbWriter.documents.write(writeObject)
56-
.result(function(response){})
62+
.result(function(response){
63+
done(new Error('Expecting an error to be thrown due to invalid basePath with starting and trailing slashes'));
64+
})
5765
.catch(err=>
5866
{
5967
assert(err.toString().includes('path: /invalid/v1/documents'));
@@ -65,7 +73,9 @@ describe('basePath tests', function() {
6573
testconfig.restWriterConnectionWithBasePath.basePath = '//invalid//';
6674
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
6775
dbWriter.documents.write(writeObject)
68-
.result(function(response){})
76+
.result(function(response){
77+
done(new Error('Expecting an error to be thrown due to invalid basePath with multiple starting and trailing slashes'));
78+
})
6979
.catch(err=>
7080
{
7181
try{

test-basic/bindingFromParam.js

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ describe('optic-update fromParam tests', function(){
111111
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
112112
const temp = {myDocs: rows};
113113
db.rows.query(planBuilderTemplate,null, temp);
114+
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
114115
} catch (e) {
115116
e.toString().should.equal('Error: row-col-types argument at 2 of PlanBuilder.fromParam() has invalid argument for PlanRowColTypes value: [object Object]');
116117
done();
@@ -157,6 +158,7 @@ describe('optic-update fromParam tests', function(){
157158
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
158159
const temp = {myDocs: rows};
159160
db.rows.query(planBuilderTemplate, null, temp);
161+
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
160162
} catch (e) {
161163
e.toString().should.equal('Error: row-col-types argument at 2 of PlanBuilder.fromParam() has another type than string');
162164
done();
@@ -205,7 +207,11 @@ describe('optic-update fromParam tests', function(){
205207
}, {"column": "lastName", "type": "string"}];
206208
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
207209
const temp = {myDocs: rows};
208-
db.rows.query(planBuilderTemplate, null, temp).catch(e => {
210+
db.rows.query(planBuilderTemplate, null, temp)
211+
.then(function(response){
212+
done(new Error('Expecting an error to be thrown due to null value for non-nullable column'));
213+
})
214+
.catch(e => {
209215
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
210216
done();
211217
});
@@ -221,7 +227,11 @@ describe('optic-update fromParam tests', function(){
221227
}, {"column": "lastName", "type": "string", "nullable": true}];
222228
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
223229
const temp = {myDocs: rows};
224-
db.rows.query(planBuilderTemplate, null,temp).catch(e => {
230+
db.rows.query(planBuilderTemplate, null,temp)
231+
.then(function(response){
232+
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
233+
})
234+
.catch(e => {
225235
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
226236
done();
227237
});
@@ -237,7 +247,11 @@ describe('optic-update fromParam tests', function(){
237247
}, {"column": "lastName", "type": "string", "nullable": true}];
238248
const planBuilderTemplate = op.fromParam('myDocs', 'qualifier', outputCols);
239249
const temp = {myDocs: rows};
240-
db.rows.query(planBuilderTemplate,null, temp).catch(e => {
250+
db.rows.query(planBuilderTemplate,null, temp)
251+
.then(function(response){
252+
done(new Error('Expecting an error to be thrown due to invalid row-col-types argument'));
253+
})
254+
.catch(e => {
241255
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
242256
done();
243257
});
@@ -255,10 +269,13 @@ describe('optic-update fromParam tests', function(){
255269
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
256270
const temp = {myDocs: rows};
257271
db.rows.query(planBuilderTemplate,null, temp)
258-
.catch(e => {
259-
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
260-
done();
261-
});
272+
.then(function(response){
273+
done(new Error('Expecting an error to be thrown due to null value for non-nullable column'));
274+
})
275+
.catch(e => {
276+
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
277+
done();
278+
});
262279
} catch (e) {
263280
done();
264281
}
@@ -274,10 +291,13 @@ describe('optic-update fromParam tests', function(){
274291
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
275292
const temp = {myDocs: rows};
276293
db.rows.query(planBuilderTemplate, null,temp)
277-
.catch(e => {
278-
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
279-
done();
280-
});
294+
.then(function(response){
295+
done(new Error('Expecting an error to be thrown due to extra non-defined column types'));
296+
})
297+
.catch(e => {
298+
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
299+
done();
300+
});
281301

282302
});
283303

@@ -290,10 +310,13 @@ describe('optic-update fromParam tests', function(){
290310
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
291311
const temp = {bindingParam: rows};
292312
db.rows.query(planBuilderTemplate, null, temp)
293-
.catch(e => {
294-
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
295-
done();
296-
});
313+
.then(function(response){
314+
done(new Error('Expecting an error to be thrown due to non-consistent binding argument name'));
315+
})
316+
.catch(e => {
317+
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
318+
done();
319+
});
297320

298321
});
299322

@@ -311,10 +334,13 @@ describe('optic-update fromParam tests', function(){
311334
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
312335
const temp = {myDocs: rows};
313336
db.rows.query(planBuilderTemplate, null, temp)
314-
.catch(e => {
315-
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
316-
done();
317-
});
337+
.then(function(response){
338+
done(new Error('Expecting an error to be thrown due to mismatch type'));
339+
})
340+
.catch(e => {
341+
e.toString().includes('Error: binding arguments /v1/rows: cannot process response with 500 status');
342+
done();
343+
});
318344

319345
});
320346

@@ -333,6 +359,7 @@ describe('optic-update fromParam tests', function(){
333359
const planBuilderTemplate = op.fromParam('myDocs', 1234, outputCols);
334360
const temp = {myDocs: rows};
335361
db.rows.query(planBuilderTemplate, null, temp);
362+
done(new Error('Expecting an error to be thrown due to invalid qualifier argument'));
336363
} catch (e) {
337364
e.toString().includes('Error: qualifier argument at 1 of PlanBuilder.fromParam() must be a XsString value');
338365
done();
@@ -353,11 +380,17 @@ describe('optic-update fromParam tests', function(){
353380
const planBuilderTemplate = op.fromParam('myDocs', null, outputCols);
354381
const temp = {myDocs: rows};
355382
db.rows.query(planBuilderTemplate, null, temp).then(res => {
356-
const rows = res.rows;
357-
rows[0].id.value.should.equal(1);
358-
rows[0].firstName.value.should.equal("firstName_1");
359-
rows[0].lastName.value.should.equal("lastName_1");
360-
done();
383+
try {
384+
const rows = res.rows;
385+
rows[0].id.value.should.equal(1);
386+
rows[0].firstName.value.should.equal("firstName_1");
387+
rows[0].lastName.value.should.equal("lastName_1");
388+
done();
389+
} catch (e) {
390+
done(e);
391+
}
392+
}).catch(e => {
393+
done(e);
361394
});
362395

363396
});

test-basic/client.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,21 @@ describe('database clients', function () {
8787
done();
8888
});
8989
it('should use a custom agent', function (done) {
90-
agentDb.connectionParams.agent.options.keepAliveTimeoutMsecs.should.equal(1000);
91-
done();
90+
try {
91+
agentDb.connectionParams.agent.options.keepAliveTimeoutMsecs.should.equal(1000);
92+
done();
93+
} catch(e){
94+
done(e);
95+
}
9296
});
9397
it('should create a timestamp', function (done) {
9498
let timestamp = db.createTimestamp('123');
95-
timestamp.value.should.equal('123');
96-
done();
99+
try {
100+
timestamp.value.should.equal('123');
101+
done();
102+
} catch(e){
103+
done(e);
104+
}
97105
});
98106
it('should throw Error when server expects DIGEST and authType is CERTIFICATE', function (done) {
99107
const db = marklogic.createDatabaseClient({
@@ -108,6 +116,7 @@ describe('database clients', function () {
108116
.result(function (documents) {
109117
documents.forEach(function (document) {
110118
});
119+
done(new Error('Expecting an error to be thrown due to invalid authentication configuration'));
111120
})
112121
.catch(error => {
113122
assert(error.toString().includes('response with invalid 401 status with path: /v1/search'));
@@ -143,7 +152,9 @@ describe('database clients', function () {
143152
contentType: 'application/json',
144153
content: '{"key1":"value 1"}'
145154
})
146-
.result()
155+
.result(function (document) {
156+
done(new Error('Expecting an error to be thrown due to invalid SSL configuration'));
157+
})
147158
.catch(error => {
148159
try{
149160
assert(error.message.toString().includes('You have attempted to access an HTTP server using HTTPS. Please check your configuration.') ||
@@ -158,6 +169,7 @@ describe('database clients', function () {
158169
it('should throw error when authType is OAuth and oauthToken is missing', function(done){
159170
try {
160171
marklogic.createDatabaseClient(testconfig.restConnectionForOauth);
172+
done(new Error('Expecting an error to be thrown due to missing oauthToken'));
161173
} catch(error){
162174
assert(error.message.toString().includes('oauthToken required for OAuth authentication. '));
163175
done();

test-basic/cloud_authentication-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('cloud-authentication tests', function() {
1515
host: 'invalid',
1616
authType: 'cloud'
1717
});
18+
done(new Error('Expecting an error to be thrown due to missing apiKey'));
1819
} catch(error) {
1920
assert(error.toString().includes('apiKey needed for MarkLogic cloud authentication.'));
2021
done();

test-basic/digestauth-fips-nomd5load.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
const should = require('should');
77

88
describe('FIPS test - ensure MD5 hash digester object is not loaded by default on require of www-authenticate module', function () {
9-
it('should not automatically load MD5 digest algorithm function when requiring www-authenticate module', function () {
9+
it('should not automatically load MD5 digest algorithm function when requiring www-authenticate module', function (done) {
1010
/**
1111
* Attempt to load/require the www-authenticate module after applying a monkey-patch
1212
* to the crypto.createHash function to intercept any attempts to create an MD5 hash
@@ -42,7 +42,9 @@ describe('FIPS test - ensure MD5 hash digester object is not loaded by default o
4242
// Require the module - should not call to get MD5 digester so should not throw
4343
(() => require('../lib/www-authenticate-patched/md5')).should.not.throw();
4444
(() => require('../lib/www-authenticate-patched/www-authenticate')).should.not.throw();
45-
45+
done();
46+
} catch (e) {
47+
done(e);
4648
} finally {
4749
// Restore the original createHash function to avoid side effects
4850
// This MUST execute to avoid breaking other tests!

test-basic/docColTypes-test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ describe('optic-update docColTypes tests', function() {
116116

117117
try {
118118
db.rows.query(op.fromDocDescriptors(docsDescriptor).write(op.docColTypes()));
119+
done(new Error('Expecting an error to be thrown due to invalid document descriptor'));
119120
} catch (e) {
120121
e.toString().includes('Error: doc-cols argument at 0 of PlanModifyPlan.write() must have type PlanDocColsIdentifier');
121122
done();

0 commit comments

Comments
 (0)