Skip to content

Commit 3cffc16

Browse files
committed
chore: format
1 parent 521a5ce commit 3cffc16

File tree

4 files changed

+33
-44
lines changed

4 files changed

+33
-44
lines changed

src/client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,12 @@ export class Client {
611611
if (!chosenNode) {
612612
throw new Error(`Stream was not found on any node`)
613613
}
614-
const cachedConnection = ConnectionPool.getUsableCachedConnection(purpose, streamName, this.connection.vhost, chosenNode.host)
614+
const cachedConnection = ConnectionPool.getUsableCachedConnection(
615+
purpose,
616+
streamName,
617+
this.connection.vhost,
618+
chosenNode.host
619+
)
615620
if (cachedConnection) return cachedConnection
616621

617622
const newConnection = await this.getConnectionOnChosenNode(

src/connection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ export class Connection {
377377
writable: this.socket.writable,
378378
localPort: this.socket.localPort,
379379
ready: this.ready,
380-
vhost: this.vhost
380+
vhost: this.vhost,
381381
}
382382
}
383383

src/connection_pool.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ export class ConnectionPool {
1818
return refCount !== undefined && refCount < getMaxSharedConnectionInstances() ? connection : undefined
1919
}
2020

21-
public static cacheConnection(purpose: ConnectionPurpose, streamName: string, vhost: string, host: string, client: Connection) {
21+
public static cacheConnection(
22+
purpose: ConnectionPurpose,
23+
streamName: string,
24+
vhost: string,
25+
host: string,
26+
client: Connection
27+
) {
2228
const map =
2329
purpose === "publisher" ? ConnectionPool.publisherConnectionProxies : ConnectionPool.consumerConnectionProxies
2430
const key = ConnectionPool.getCacheKey(streamName, vhost, host)

test/e2e/stream_cache.test.ts

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,37 @@
11
import { expect } from "chai"
22
import got from "got"
33
import { Client } from "../../src"
4-
import {
5-
createClient,
6-
createStreamName,
7-
} from "../support/fake_data"
4+
import { createClient, createStreamName } from "../support/fake_data"
85
import { Rabbit, RabbitConnectionResponse } from "../support/rabbit"
9-
import {
10-
getTestNodesFromEnv,
11-
password,
12-
username,
13-
} from "../support/util"
6+
import { getTestNodesFromEnv, password, username } from "../support/util"
147

158
async function createVhost(vhost: string): Promise<undefined> {
169
const port = process.env.RABBIT_MQ_MANAGEMENT_PORT || 15672
1710
const firstNode = getTestNodesFromEnv().shift()!
18-
await got.put<RabbitConnectionResponse>(
19-
`http://${firstNode.host}:${port}/api/vhosts/${vhost}`,
20-
{
21-
username: username,
22-
password: password,
23-
}
24-
)
25-
await got.put<RabbitConnectionResponse>(
26-
`http://${firstNode.host}:${port}/api/permissions/${vhost}/${username}`,
27-
{
11+
await got.put<RabbitConnectionResponse>(`http://${firstNode.host}:${port}/api/vhosts/${vhost}`, {
12+
username: username,
13+
password: password,
14+
})
15+
await got
16+
.put<RabbitConnectionResponse>(`http://${firstNode.host}:${port}/api/permissions/${vhost}/${username}`, {
2817
json: {
29-
read: '.*',
30-
write: '.*',
31-
configure: '.*'
18+
read: ".*",
19+
write: ".*",
20+
configure: ".*",
3221
},
3322
username: username,
3423
password: password,
35-
}
36-
).json()
24+
})
25+
.json()
3726
}
3827

3928
async function deleteVhost(vhost: string): Promise<RabbitConnectionResponse> {
4029
const port = process.env.RABBIT_MQ_MANAGEMENT_PORT || 15672
4130
const firstNode = getTestNodesFromEnv().shift()!
42-
const r = await got.delete<RabbitConnectionResponse>(
43-
`http://${firstNode.host}:${port}/api/vhosts/${vhost}`,
44-
{
45-
username: username,
46-
password: password,
47-
}
48-
)
31+
const r = await got.delete<RabbitConnectionResponse>(`http://${firstNode.host}:${port}/api/vhosts/${vhost}`, {
32+
username: username,
33+
password: password,
34+
})
4935

5036
return r.body
5137
}
@@ -61,15 +47,7 @@ describe("cache", () => {
6147
})
6248
beforeEach(async () => {
6349
client = await createClient(username, password)
64-
client2 = await createClient(
65-
username,
66-
password,
67-
undefined,
68-
undefined,
69-
undefined,
70-
undefined,
71-
undefined,
72-
vhost1)
50+
client2 = await createClient(username, password, undefined, undefined, undefined, undefined, undefined, vhost1)
7351
streamName = createStreamName()
7452
await client.createStream({ stream: streamName })
7553
await client2.createStream({ stream: streamName })
@@ -82,7 +60,7 @@ describe("cache", () => {
8260
await rabbit.deleteStream(streamName)
8361
await rabbit.closeAllConnections()
8462
await rabbit.deleteAllQueues({ match: /my-stream-/ })
85-
} catch (_e) { }
63+
} catch (_e) {}
8664
})
8765

8866
it("should cache using the vhost as well as the stream name", async () => {

0 commit comments

Comments
 (0)