Skip to content

Commit 2116955

Browse files
W-A-Jamesnbbeeken
authored andcommitted
Address lint failures
1 parent 8d9fde3 commit 2116955

File tree

6 files changed

+93
-27
lines changed

6 files changed

+93
-27
lines changed

src/sdam/server.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -338,42 +338,33 @@ export class Server extends TypedEventEmitter<ServerEvents> {
338338
};
339339

340340
// FIXME: This is where withConnection logic should go
341-
if (conn) {
342-
// send operation, possibly reauthenticating and return without checking back in
341+
if (!conn) {
343342
try {
344-
return await runCommand(conn);
343+
conn = await this.pool.checkOut();
345344
} catch (e) {
346-
if (shouldReauth(e)) {
347-
conn = await this.pool.reauthenticateAsync(conn);
348-
return await runCommand(conn);
349-
}
345+
if (!e) throw new MongoRuntimeError('Failed to create connection without error');
346+
if (!(e instanceof PoolClearedError)) this.handleError(e);
347+
350348
throw e;
351349
}
352350
}
353351

354-
// check out connection
352+
// Reauth flow
353+
let rv;
355354
try {
356-
conn = await this.pool.checkOut();
355+
rv = await runCommand(conn);
357356
} catch (e) {
358-
if (!e) throw new MongoRuntimeError('Failed to create connection without error');
359-
if (!(e instanceof PoolClearedError)) this.handleError(e);
360-
361-
throw e;
362-
}
363-
// call executeCommandAsync with that checked out connection
364-
try {
365-
return await runCommand(conn);
366-
} catch (e) {
367-
// if it errors
368-
// check if we should reauthenticate
369357
if (shouldReauth(e)) {
370358
conn = await this.pool.reauthenticateAsync(conn);
371-
return await runCommand(conn);
359+
rv = await runCommand(conn);
360+
} else {
361+
throw e;
372362
}
373-
throw e;
374363
} finally {
375364
this.pool.checkIn(conn);
376365
}
366+
367+
return rv;
377368
}
378369

379370
/**
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"description": "standalone-heartbeat",
3+
"schemaVersion": "1.16",
4+
"runOnRequirements": [
5+
{
6+
"topologies": [
7+
"single"
8+
],
9+
"minServerVersion": "4.4"
10+
}
11+
],
12+
"createEntities": [
13+
{
14+
"client": {
15+
"id": "setupClient"
16+
}
17+
}
18+
],
19+
"tests": [
20+
{
21+
"description": "Topology lifecycle",
22+
"operations": [
23+
{
24+
"name": "createEntities",
25+
"object": "testRunner",
26+
"arguments": {
27+
"entities": [
28+
{
29+
"client": {
30+
"id": "client",
31+
"observeEvents": [
32+
"topologyDescriptionChangedEvent",
33+
"serverDescriptionChangedEvent"
34+
]
35+
}
36+
}
37+
]
38+
}
39+
},
40+
{
41+
"name": "waitForEvent",
42+
"object": "testRunner",
43+
"arguments": {
44+
"client": "client",
45+
"event": {
46+
"topologyDescriptionChangedEvent": {}
47+
},
48+
"count": 2
49+
}
50+
},
51+
{
52+
"name": "close",
53+
"object": "client"
54+
}
55+
],
56+
"expectEvents": [
57+
{
58+
"client": "client",
59+
"eventType": "sdam",
60+
"events": [
61+
{
62+
"topologyDescriptionChangedEvent": {}
63+
},
64+
{
65+
"serverDescriptionChangedEvent": {}
66+
},
67+
{
68+
"topologyDescriptionChangedEvent": {}
69+
},
70+
{
71+
"topologyDescriptionChangedEvent": {}
72+
}
73+
],
74+
"ignoreExtraEvents": true
75+
}
76+
]
77+
}
78+
]
79+
}

test/unit/assorted/server_discovery_and_monitoring.spec.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { expect } from 'chai';
33
import * as fs from 'fs';
44
import * as path from 'path';
55
import * as sinon from 'sinon';
6-
import { promisify } from 'util';
76

87
import {
98
ConnectionPool,

test/unit/cmap/connection_pool.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ const mock = require('../../tools/mongodb-mock/index');
66
const sinon = require('sinon');
77
const { expect } = require('chai');
88
const { setImmediate } = require('timers');
9-
const { promisify } = require('util');
109
const { ns, isHello } = require('../../mongodb');
11-
const { LEGACY_HELLO_COMMAND } = require('../../mongodb');
1210
const { createTimerSandbox } = require('../timer_sandbox');
1311
const { topologyWithPlaceholderClient } = require('../../tools/utils');
1412
const { MongoClientAuthProviders } = require('../../mongodb');

test/unit/operations/get_more.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('GetMoreOperation', function () {
5454
);
5555
const opts = { ...options, documentsReturnedIn: 'nextBatch', returnFieldSelector: null };
5656
const operation = new GetMoreOperation(namespace, cursorId, server, opts);
57-
const stub = sinon.stub(server, 'command').callsFake((_, __, ___) => {});
57+
const stub = sinon.stub(server, 'command').returns(Promise.resolve({}));
5858

5959
const expectedGetMoreCommand = {
6060
getMore: cursorId,

test/unit/sdam/server.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
MongoErrorLabel,
1010
MongoNetworkError,
1111
MongoNetworkTimeoutError,
12-
ns,
1312
ObjectId,
1413
Server,
1514
ServerDescription,

0 commit comments

Comments
 (0)