-
Notifications
You must be signed in to change notification settings - Fork 11
Fix bug when connecting to the same stream name different vhosts #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
l4mby
merged 7 commits into
coders51:main
from
david-mohr:fix/same-stream-different-vhost
Apr 28, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
450d215
feat: add vhost prop to connection class
david-mohr e4295a6
fix: include vhost in cache key to avoid collision when using multipl…
david-mohr 27c7104
fix: vhost names don't have to include /
david-mohr c1b78d8
feat: add vhost to ConnectionInfo
david-mohr 521a5ce
chore: lint
david-mohr 3cffc16
chore: format
david-mohr 994dfae
fix: encode vhost when using it in an URL
david-mohr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { expect } from "chai" | ||
| import got from "got" | ||
| import { Client } from "../../src" | ||
| import { createClient, createStreamName } from "../support/fake_data" | ||
| import { Rabbit, RabbitConnectionResponse } from "../support/rabbit" | ||
| import { getTestNodesFromEnv, password, username } from "../support/util" | ||
|
|
||
| async function createVhost(vhost: string): Promise<undefined> { | ||
| const uriVhost = encodeURIComponent(vhost) | ||
| const port = process.env.RABBIT_MQ_MANAGEMENT_PORT || 15672 | ||
| const firstNode = getTestNodesFromEnv().shift()! | ||
| await got.put<RabbitConnectionResponse>(`http://${firstNode.host}:${port}/api/vhosts/${uriVhost}`, { | ||
| username: username, | ||
| password: password, | ||
| }) | ||
| await got | ||
| .put<RabbitConnectionResponse>(`http://${firstNode.host}:${port}/api/permissions/${uriVhost}/${username}`, { | ||
| json: { | ||
| read: ".*", | ||
| write: ".*", | ||
| configure: ".*", | ||
| }, | ||
| username: username, | ||
| password: password, | ||
| }) | ||
| .json() | ||
| } | ||
|
|
||
| async function deleteVhost(vhost: string): Promise<RabbitConnectionResponse> { | ||
| const uriVhost = encodeURIComponent(vhost) | ||
| const port = process.env.RABBIT_MQ_MANAGEMENT_PORT || 15672 | ||
| const firstNode = getTestNodesFromEnv().shift()! | ||
| const r = await got.delete<RabbitConnectionResponse>(`http://${firstNode.host}:${port}/api/vhosts/${uriVhost}`, { | ||
| username: username, | ||
| password: password, | ||
| }) | ||
|
|
||
| return r.body | ||
| } | ||
|
|
||
| describe("cache", () => { | ||
| const vhost1 = "vhost1" | ||
| let streamName: string | ||
| const rabbit = new Rabbit(username, password) | ||
| let client: Client | ||
| let client2: Client | ||
| before(async () => { | ||
| await createVhost(vhost1) | ||
| }) | ||
| beforeEach(async () => { | ||
| client = await createClient(username, password) | ||
| client2 = await createClient(username, password, undefined, undefined, undefined, undefined, undefined, vhost1) | ||
| streamName = createStreamName() | ||
| await client.createStream({ stream: streamName }) | ||
| await client2.createStream({ stream: streamName }) | ||
| }) | ||
| afterEach(async () => { | ||
| try { | ||
| await client.close() | ||
| await client2.close() | ||
| await deleteVhost(vhost1) | ||
| await rabbit.deleteStream(streamName) | ||
| await rabbit.closeAllConnections() | ||
| await rabbit.deleteAllQueues({ match: /my-stream-/ }) | ||
| } catch (_e) {} | ||
| }) | ||
|
|
||
| it("should cache using the vhost as well as the stream name", async () => { | ||
| const publisher1 = await client.declarePublisher({ | ||
| stream: streamName, | ||
| }) | ||
| expect(publisher1.getConnectionInfo().vhost).eql("/") | ||
| const publisher2 = await client2.declarePublisher({ | ||
| stream: streamName, | ||
| }) | ||
| expect(publisher2.getConnectionInfo().vhost).eql(vhost1) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.