Repository navigation
feat: Add support for QoS profiles #1291
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
Open
bjsowa
wants to merge
8
commits into
develop
Choose a base branch
from
feat/add-qos-profiles
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3e4da48
feat: Add QoS profile support
bjsowa 21ebed9
Add topic qos tests
bjsowa 156eb70
Add pubsub qos tests
bjsowa fcac8b3
Make RosbridgeDuration type public
bjsowa 0dce6ed
Add RosbridgeDuration type import
bjsowa 2543e97
Merge branch 'develop' into feat/add-qos-profiles
bjsowa 83f67f4
fix: Connect to ROS in beforeAll callback
bjsowa f08cfa5
Fix lint errors
bjsowa 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import { | |
| isRosbridgePublishMessage, | ||
| type RosbridgeAdvertiseMessage, | ||
| type RosbridgeMessage, | ||
| type RosbridgeQosProfile, | ||
| type RosbridgeSubscribeMessage, | ||
| } from "../types/protocol.ts"; | ||
| import type { rosapi } from "../types/rosapi.ts"; | ||
|
|
@@ -39,6 +40,7 @@ export default class Topic<T = unknown> extends EventEmitter<{ | |
| latch: boolean; | ||
| queue_size: number; | ||
| queue_length: number; | ||
| qos?: RosbridgeQosProfile; | ||
| reconnect_on_close: boolean; | ||
| callForSubscribeAndAdvertise: ( | ||
| message: RosbridgeSubscribeMessage | RosbridgeAdvertiseMessage, | ||
|
|
@@ -55,6 +57,7 @@ export default class Topic<T = unknown> extends EventEmitter<{ | |
| * @param [options.queue_size=100] - The queue created at bridge side for re-publishing webtopics. | ||
| * @param [options.latch=false] - Latch the topic when publishing. | ||
| * @param [options.queue_length=0] - The queue length at bridge side used when subscribing. | ||
| * @param [options.qos] - QoS profile for the topic. When provided, `latch` and `queue_size` are ignored. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a new union type for this options object that makes {
qos?: RosBridgeQosProfile;
latch: never;
queue_size: never;
}and one with {
latch: boolean;
queue_size: number;
qos: never;
} |
||
| * @param [options.reconnect_on_close=true] - The flag to enable resubscription and readvertisement on close event. | ||
| */ | ||
| constructor({ | ||
|
|
@@ -66,6 +69,7 @@ export default class Topic<T = unknown> extends EventEmitter<{ | |
| latch = false, | ||
| queue_size = 100, | ||
| queue_length = 0, | ||
| qos, | ||
| reconnect_on_close = true, | ||
| }: { | ||
| ros: Ros; | ||
|
|
@@ -76,6 +80,7 @@ export default class Topic<T = unknown> extends EventEmitter<{ | |
| queue_size?: number; | ||
| latch?: boolean; | ||
| queue_length?: number; | ||
| qos?: RosbridgeQosProfile; | ||
| reconnect_on_close?: boolean; | ||
| }) { | ||
| super(); | ||
|
|
@@ -88,6 +93,7 @@ export default class Topic<T = unknown> extends EventEmitter<{ | |
| this.latch = latch; | ||
| this.queue_size = queue_size; | ||
| this.queue_length = queue_length; | ||
| this.qos = qos; | ||
| this.reconnect_on_close = reconnect_on_close; | ||
|
|
||
| // Check for valid compression types | ||
|
|
@@ -171,6 +177,7 @@ export default class Topic<T = unknown> extends EventEmitter<{ | |
| compression: this.compression, | ||
| throttle_rate: this.throttle_rate, | ||
| queue_length: this.queue_length, | ||
| qos: this.qos, | ||
| }); | ||
| } | ||
| /** | ||
|
|
@@ -221,6 +228,7 @@ export default class Topic<T = unknown> extends EventEmitter<{ | |
| topic: this.name, | ||
| latch: this.latch, | ||
| queue_size: this.queue_size, | ||
| qos: this.qos, | ||
| }); | ||
| this.isAdvertised = true; | ||
|
|
||
|
|
||
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,127 @@ | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; | ||
| import { EventEmitter } from "eventemitter3"; | ||
| import Topic from "../src/core/Topic.ts"; | ||
| import type Ros from "../src/core/Ros.ts"; | ||
| import type { | ||
| RosbridgeMessage, | ||
| RosbridgeQosProfile, | ||
| } from "../src/types/protocol.ts"; | ||
|
|
||
| const qos: RosbridgeQosProfile = { | ||
| history: "keep_last", | ||
| depth: 5, | ||
| reliability: "best_effort", | ||
| durability: "transient_local", | ||
| deadline: { secs: 1, nsecs: 500000000 }, | ||
| lifespan: "infinite", | ||
| }; | ||
|
|
||
| describe("Topic QoS", () => { | ||
| let mockRos: Ros & EventEmitter; | ||
| let callOnConnection: ReturnType< | ||
| typeof vi.fn<(msg: RosbridgeMessage) => void> | ||
| >; | ||
|
|
||
| /** All messages sent to the server with the given op, as they go over the wire */ | ||
| function sent(op: string): Record<string, unknown>[] { | ||
| return callOnConnection.mock.calls | ||
| .map( | ||
| ([msg]) => JSON.parse(JSON.stringify(msg)) as Record<string, unknown>, | ||
| ) | ||
| .filter((msg) => msg["op"] === op); | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| callOnConnection = vi.fn<(msg: RosbridgeMessage) => void>(); | ||
| mockRos = Object.assign(new EventEmitter(), { | ||
| callOnConnection, | ||
| }) as unknown as Ros & EventEmitter; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| function makeTopic(options: { qos?: RosbridgeQosProfile } = {}) { | ||
| return new Topic({ | ||
| ros: mockRos, | ||
| name: "/chatter", | ||
| messageType: "std_msgs/msg/String", | ||
| ...options, | ||
| }); | ||
| } | ||
|
|
||
| it("sends the qos profile when advertising", () => { | ||
| makeTopic({ qos }).advertise(); | ||
|
|
||
| const [advertise] = sent("advertise"); | ||
| expect(advertise).toMatchObject({ | ||
| topic: "/chatter", | ||
| type: "std_msgs/msg/String", | ||
| qos, | ||
| }); | ||
| }); | ||
|
|
||
| it("sends the qos profile when subscribing", () => { | ||
| makeTopic({ qos }).subscribe(() => undefined); | ||
|
|
||
| const [subscribe] = sent("subscribe"); | ||
| expect(subscribe).toMatchObject({ | ||
| topic: "/chatter", | ||
| type: "std_msgs/msg/String", | ||
| qos, | ||
| }); | ||
| }); | ||
|
|
||
| it("advertises with qos before the first publish", () => { | ||
| const topic = makeTopic({ qos }); | ||
| topic.publish({ data: "hello" }); | ||
| topic.publish({ data: "again" }); | ||
|
|
||
| expect(sent("advertise")).toHaveLength(1); | ||
| expect(sent("advertise")[0]).toMatchObject({ qos }); | ||
| expect(sent("publish")).toHaveLength(2); | ||
| // QoS belongs to the advertisement; the publish messages don't repeat it | ||
| for (const publish of sent("publish")) { | ||
| expect(publish).not.toHaveProperty("qos"); | ||
| } | ||
| }); | ||
|
|
||
| it("passes an empty profile through to request full system-default QoS", () => { | ||
| makeTopic({ qos: {} }).advertise(); | ||
|
|
||
| expect(sent("advertise")[0]).toHaveProperty("qos", {}); | ||
| }); | ||
|
|
||
| it("omits the qos field when no profile is given", () => { | ||
| const topic = makeTopic(); | ||
| topic.advertise(); | ||
| topic.subscribe(() => undefined); | ||
|
|
||
| expect(sent("advertise")[0]).not.toHaveProperty("qos"); | ||
| expect(sent("subscribe")[0]).not.toHaveProperty("qos"); | ||
| // Old servers still get the legacy fields | ||
| expect(sent("advertise")[0]).toMatchObject({ | ||
| latch: false, | ||
| queue_size: 100, | ||
| }); | ||
| }); | ||
|
|
||
| it("re-sends the qos profile when re-advertising after reconnect", () => { | ||
| makeTopic({ qos }).advertise(); | ||
|
|
||
| mockRos.emit("close"); | ||
|
|
||
| expect(sent("advertise")).toHaveLength(2); | ||
| expect(sent("advertise")[1]).toMatchObject({ qos }); | ||
| }); | ||
|
|
||
| it("re-sends the qos profile when re-subscribing after reconnect", () => { | ||
| makeTopic({ qos }).subscribe(() => undefined); | ||
|
|
||
| mockRos.emit("close"); | ||
|
|
||
| expect(sent("subscribe")).toHaveLength(2); | ||
| expect(sent("subscribe")[1]).toMatchObject({ qos }); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.