Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/test-message-translator-complex.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,33 @@ describe('Rclnodejs message translation: complex types', function () {
const MessageType = testData.pkg + '/msg/' + testData.type;
const publisher = node.createPublisher(MessageType, topic);
return new Promise((resolve, reject) => {
let timer;
const sub = node.createSubscription(MessageType, topic, (value) => {
if (deepEqual(value, v)) {
clearInterval(timer);
node.destroy();
resolve();
} else {
clearInterval(timer);
node.destroy();
console.log('got', value);
console.log('expected', v);
reject('case ' + i + '. Expected: ' + v + ', Got: ' + value);
}
Comment on lines 218 to 224
});
// Keep republishing until the subscription is matched and the
// message is received; a single publish can be lost while pub/sub
// discovery is still in progress.
const start = Date.now();
timer = setInterval(() => {
if (Date.now() - start > 55 * 1000) {
clearInterval(timer);
node.destroy();
reject('Timed out waiting for message');
return;
}
publisher.publish(v);
}, 100);
publisher.publish(v);
rclnodejs.spin(node);
});
Expand Down
62 changes: 58 additions & 4 deletions test/test-message-translator-primitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,31 @@ describe('Rclnodejs message translation: primitive types', function () {
const MessageType = 'std_msgs/msg/' + testData.type;
const publisher = node.createPublisher(MessageType, topic);
return new Promise((resolve, reject) => {
let timer;
const sub = node.createSubscription(MessageType, topic, (value) => {
// For primitive types, msgs are defined as a single `.data` field
if (value.data === v) {
clearInterval(timer);
node.destroy();
resolve();
} else {
clearInterval(timer);
node.destroy();
reject(
'case ' + i + '. Expected: ' + v + ', Got: ' + value.data
);
}
});
const start = Date.now();
timer = setInterval(() => {
if (Date.now() - start > 55 * 1000) {
clearInterval(timer);
node.destroy();
reject('Timed out waiting for message');
return;
}
publisher.publish(v);
}, 100);
publisher.publish(v); // Short-cut form of publishing primitive types
rclnodejs.spin(node);
});
Expand All @@ -119,18 +132,31 @@ describe('Rclnodejs message translation: primitive types', function () {
const MessageType = 'std_msgs/msg/' + testData.type;
const publisher = node.createPublisher(MessageType, topic);
return new Promise((resolve, reject) => {
let timer;
const sub = node.createSubscription(MessageType, topic, (value) => {
// For primitive types, msgs are defined as a single `.data` field
if (value.data === v) {
clearInterval(timer);
node.destroy();
resolve();
} else {
clearInterval(timer);
node.destroy();
reject(
'case ' + i + '. Expected: ' + v + ', Got: ' + value.data
);
}
});
const start = Date.now();
timer = setInterval(() => {
if (Date.now() - start > 55 * 1000) {
clearInterval(timer);
node.destroy();
reject('Timed out waiting for message');
return;
}
publisher.publish({ data: v });
}, 100);
publisher.publish({ data: v }); // Ensure the original form of the message can be used
rclnodejs.spin(node);
});
Expand Down Expand Up @@ -221,27 +247,41 @@ describe('Rclnodejs message translation: primitive types array', function () {
const MessageType = 'std_msgs/msg/' + testData.type;
const publisher = node.createPublisher(MessageType, topic);
return new Promise((resolve, reject) => {
let timer;
const sub = node.createSubscription(MessageType, topic, (value) => {
// For primitive types, msgs are defined as a single `.data` field
if (
(isTypedArray(value.data) &&
deepEqual(Array.from(value.data), testData.values)) ||
deepEqual(value.data, testData.values)
) {
clearInterval(timer);
node.destroy();
resolve();
} else {
clearInterval(timer);
node.destroy();
reject('Expected: ' + testData.values + ', Got: ' + value.data);
}
});
publisher.publish({
const msg = {
layout: {
dim: [{ label: 'length', size: 0, stride: 0 }],
data_offset: 0,
},
data: testData.values,
});
};
const start = Date.now();
timer = setInterval(() => {
if (Date.now() - start > 55 * 1000) {
clearInterval(timer);
node.destroy();
reject('Timed out waiting for message');
return;
}
publisher.publish(msg);
}, 100);
publisher.publish(msg);
rclnodejs.spin(node);
});
}
Expand Down Expand Up @@ -478,16 +518,19 @@ describe('Rclnodejs message translation: TypedArray large data', function () {
const MessageType = 'std_msgs/msg/' + testData.type;
const publisher = node.createPublisher(MessageType, topic);
return new Promise((resolve, reject) => {
let timer;
const sub = node.createSubscription(MessageType, topic, (value) => {
// For primitive types, msgs are defined as a single `.data` field
if (
(isTypedArray(value.data) &&
deepEqual(Array.from(value.data), testData.values)) ||
deepEqual(value.data, testData.values)
) {
clearInterval(timer);
node.destroy();
resolve();
} else {
clearInterval(timer);
node.destroy();
reject(
'Expected: ' +
Expand All @@ -497,13 +540,24 @@ describe('Rclnodejs message translation: TypedArray large data', function () {
);
}
});
publisher.publish({
const msg = {
layout: {
dim: [{ label: 'length', size: 0, stride: 0 }],
data_offset: 0,
},
data: testData.values,
});
};
const start = Date.now();
timer = setInterval(() => {
if (Date.now() - start > 55 * 1000) {
clearInterval(timer);
node.destroy();
reject('Timed out waiting for message');
return;
}
publisher.publish(msg);
}, 100);
publisher.publish(msg);
rclnodejs.spin(node);
Comment on lines +550 to 561
});
}
Expand Down
Loading