Skip to content

Commit 6613ee2

Browse files
qiuzhongMinggang Wang
authored andcommitted
Rebase actionlib test cases on develop branch
* Add libraries build for `ros1_actions` package. * Copy built packages to ros2 package to avoid load new ROS2 enviroment.
1 parent a7537d5 commit 6613ee2

File tree

5 files changed

+91
-24
lines changed

5 files changed

+91
-24
lines changed

scripts/compile_tests.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,23 @@ function copyAll(fileList, dest) {
6666
});
6767
}
6868

69-
var subProcess = child.spawn('colcon', ['build',
70-
'--event-handlers', 'console_cohesion+', '--base-paths', path.join(rootDir, 'test', 'rclnodejs_test_msgs')]);
71-
subProcess.on('close', (code) => {
69+
function copyPkgToRos2(pkgName) {
70+
let srcDir = path.join(rootDir, 'install', pkgName);
71+
let destDir = process.env.COLCON_PREFIX_PATH;
7272
if (os.platform() === 'win32') {
7373
child.spawn('cmd.exe',
74-
['/c', `xcopy ${path.join(rootDir, 'install', 'rclnodejs_test_msgs')} ${process.env.AMENT_PREFIX_PATH} /O /X /E /K`]);
74+
['/c', `xcopy ${srcDir} ${destDir} /O /X /E /K`]);
7575
} else {
7676
child.spawn('sh',
77-
['-c', `cp -r ${path.join(rootDir, 'install', 'rclnodejs_test_msgs') + '/.'} ${process.env.AMENT_PREFIX_PATH}`]);
77+
['-c ', '"' + `cp -fr ${srcDir}/. ${destDir}` + '"'],
78+
{shell: true});
7879
}
80+
}
81+
82+
var subProcess = child.spawn('colcon', ['build',
83+
'--event-handlers', 'console_cohesion+', '--base-paths', path.join(rootDir, 'test', 'rclnodejs_test_msgs')]);
84+
subProcess.on('close', (code) => {
85+
copyPkgToRos2('rclnodejs_test_msgs');
7986
});
8087
subProcess.stdout.on('data', (data) => {
8188
console.log(`${data}`);
@@ -99,4 +106,26 @@ if (!fs.existsSync(publisherPath) && !fs.existsSync(subscriptionPath) &&
99106
} else {
100107
copyAll([publisherPath, subscriptionPath, , listenerPath, clientPath], testCppDir);
101108
}
109+
110+
let actionPath = path.join(rootDir, 'test', 'ros1_actions');
111+
process.env.AMENT_PREFIX_PATH = process.env.AMENT_PREFIX_PATH + path.delimiter + actionPath;
112+
113+
const generator = require('../rosidl_gen/index.js');
114+
115+
generator.generateAll(true).then(() => {
116+
console.log('Generation is done.');
117+
118+
let actionBuildProcess = child.spawn('colcon', ['build', '--base-paths', actionPath]);
119+
actionBuildProcess.on('close', (code) => {
120+
copyPkgToRos2('ros1_actions');
121+
});
122+
actionBuildProcess.stdout.on('data', (data) => {
123+
console.log(`${data}`);
124+
});
125+
actionBuildProcess.stderr.on('data', (data) => {
126+
console.log(`${data}`);
127+
});
128+
}).catch((e) => {
129+
console.log(`Caught error: ${e}`);
130+
});
102131
/* eslint-enable */

scripts/run_test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ const Mocha = require('mocha');
1919
const os = require('os');
2020
const path = require('path');
2121

22-
let actionPath = path.join(path.dirname(__dirname), 'test', 'ros1_actions');
22+
let rootDir = path.dirname(__dirname);
23+
let actionPath = path.join(rootDir, 'test', 'ros1_actions');
2324
process.env.AMENT_PREFIX_PATH = process.env.AMENT_PREFIX_PATH + path.delimiter + actionPath;
25+
let msgPath = path.join(rootDir, 'test', 'rclnodejs_test_msgs');
26+
process.env.AMENT_PREFIX_PATH = process.env.AMENT_PREFIX_PATH + path.delimiter + msgPath;
2427

2528
fs.remove(path.join(path.dirname(__dirname), 'generated'), (err)=> {
2629
if (!err) {

test/blacklist.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"Linux": ["test-actionlib.js"],
3-
"Darwin": ["test-actionlib.js"],
4-
"Windows_NT": ["test-actionlib.js"]
2+
"Linux": [],
3+
"Darwin": [],
4+
"Windows_NT": []
55
}

test/test-actionlib.js

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ const assert = require('assert');
2020
const rclnodejs = require('../index.js');
2121

2222
describe('Testing message files generated from an action file', function() {
23-
// let testRootDir = __dirname;
24-
// let testActionDir = path.join(testRootDir, 'ros1_actions');
25-
// let pkgRootDir = path.dirname(testRootDir);
26-
// let msgGenRootDir = path.join(pkgRootDir, 'generated');
2723

2824
this.timeout(60 * 1000);
2925

@@ -66,6 +62,7 @@ describe('Testing message files generated from an action file', function() {
6662
rclnodejs: rclnodejs
6763
});
6864
as.on('goal', function(goal) {
65+
clearInterval(timer);
6966
done();
7067
});
7168
as.start();
@@ -76,6 +73,9 @@ describe('Testing message files generated from an action file', function() {
7673
rclnodejs: rclnodejs
7774
});
7875
ac.sendGoal({ goal: {dishwasher_id: 4}});
76+
let timer = setInterval(() => {
77+
ac.sendGoal({ goal: {dishwasher_id: 4}});
78+
}, 50);
7979
});
8080

8181
it('ActionLib client feedback accepted', function(done) {
@@ -101,9 +101,14 @@ describe('Testing message files generated from an action file', function() {
101101
});
102102
ac.on('feedback', function(feedback) {
103103
assert.strictEqual(feedback.percent_complete, 70);
104+
clearInterval(timer);
104105
done();
105106
});
107+
106108
ac.sendGoal({ goal: {dishwasher_id: 5}});
109+
let timer = setInterval(() => {
110+
ac.sendGoal({ goal: {dishwasher_id: 5}});
111+
}, 50);
107112
});
108113

109114
it('ActionLib server goal cancelled', function(done) {
@@ -128,9 +133,14 @@ describe('Testing message files generated from an action file', function() {
128133
}, Error);
129134
});
130135
ac.on('status', function(status) {
136+
clearInterval(timer);
131137
done();
132138
});
139+
133140
ac.sendGoal({ goal: {dishwasher_id: 6}});
141+
let timer = setInterval(() => {
142+
ac.sendGoal({ goal: {dishwasher_id: 6}});
143+
}, 50);
134144
});
135145

136146
it('ActionLib server goal setCancelled', function(done) {
@@ -141,13 +151,12 @@ describe('Testing message files generated from an action file', function() {
141151
});
142152
as.on('goal', function(goal) {
143153
goal.setAccepted('goal accepted');
144-
145-
ac.cancel(goal.id);
146-
147154
as.on('cancel', function(goalHandle) {
148155
goal.setCancelled({total_dishes_cleaned: 10}, 'canceled');
156+
clearInterval(timer);
149157
done();
150158
});
159+
ac.cancel(goal.id);
151160
});
152161

153162
as.start();
@@ -158,6 +167,9 @@ describe('Testing message files generated from an action file', function() {
158167
rclnodejs: rclnodejs
159168
});
160169
ac.sendGoal({ goal: {dishwasher_id: 7}});
170+
let timer = setInterval(() => {
171+
ac.sendGoal({ goal: {dishwasher_id: 7}});
172+
}, 50);
161173
});
162174

163175
it('ActionLib server goal setRejected', function(done) {
@@ -181,10 +193,14 @@ describe('Testing message files generated from an action file', function() {
181193
ac.on('status', function(status) {
182194
if (count++ == 1) {
183195
assert.strictEqual(status.status_list[0].text, 'rejected');
196+
clearInterval(timer);
184197
done();
185198
}
186199
});
187200
ac.sendGoal({ goal: {dishwasher_id: 8}});
201+
let timer = setInterval(() => {
202+
ac.sendGoal({ goal: {dishwasher_id: 8}});
203+
}, 50);
188204
});
189205

190206
it('ActionLib server goal setAborted', function(done) {
@@ -207,10 +223,13 @@ describe('Testing message files generated from an action file', function() {
207223
});
208224
ac.on('result', function(result) {
209225
assert.strictEqual(result.total_dishes_cleaned, 0);
210-
226+
clearInterval(timer);
211227
done();
212228
});
213-
ac.sendGoal({ goal: {dishwasher_id: 9}});
229+
ac.sendGoal({ goal: {dishwasher_id: 9}});
230+
let timer = setInterval(() => {
231+
ac.sendGoal({ goal: {dishwasher_id: 9}});
232+
}, 50);
214233
});
215234

216235
it('ActionLib sever goal setSucceeded', function(done) {
@@ -232,10 +251,14 @@ describe('Testing message files generated from an action file', function() {
232251
});
233252
ac.on('result', function(result) {
234253
assert.strictEqual(result.total_dishes_cleaned, 100);
254+
clearInterval(timer);
235255
done();
236256
});
237257

238-
ac.sendGoal({ goal: {dishwasher_id: 9}});
258+
ac.sendGoal({ goal: {dishwasher_id: 10}});
259+
let timer = setInterval(() => {
260+
ac.sendGoal({ goal: {dishwasher_id: 10}});
261+
}, 50);
239262
});
240263

241264
it('ActionLib complete process', function(done) {
@@ -265,10 +288,14 @@ describe('Testing message files generated from an action file', function() {
265288
});
266289
ac.on('result', function(result) {
267290
assert.strictEqual(result.total_dishes_cleaned, 100);
291+
clearInterval(timer);
268292
done();
269293
});
270294

271295
ac.sendGoal({ goal: {dishwasher_id: 11}});
296+
let timer = setInterval(() => {
297+
ac.sendGoal({ goal: {dishwasher_id: 11}});
298+
}, 50);
272299
});
273300

274301
it('ActionClient cancel', function(done) {
@@ -281,7 +308,8 @@ describe('Testing message files generated from an action file', function() {
281308
goal.setAccepted('goal accepted');
282309
ac.cancel(gGoal.goal_id.id);
283310
});
284-
as.on('cancel', function(goalHandle) {
311+
as.on('cancel', function(goalHandle) {
312+
clearInterval(timer);
285313
done();
286314
});
287315
as.start();
@@ -291,7 +319,10 @@ describe('Testing message files generated from an action file', function() {
291319
actionServer: 'dishes12',
292320
rclnodejs: rclnodejs
293321
});
294-
let gGoal = ac.sendGoal({ goal: {dishwasher_id: 12}});
322+
var gGoal = ac.sendGoal({ goal: {dishwasher_id: 12}});
323+
let timer = setInterval(() => {
324+
gGoal = ac.sendGoal({ goal: {dishwasher_id: 12}});
325+
}, 50);
295326
});
296327

297328
it('ActionClient shutdown', function() {
@@ -310,7 +341,7 @@ describe('Testing message files generated from an action file', function() {
310341
actionServer: 'dishes13',
311342
rclnodejs: rclnodejs
312343
});
313-
ac.sendGoal({ goal: {dishwasher_id: 12}});
344+
ac.sendGoal({ goal: {dishwasher_id: 13}});
314345
ac.shutdown();
315346
});
316347

@@ -337,11 +368,15 @@ describe('Testing message files generated from an action file', function() {
337368
status.status_list.forEach((s) =>{
338369
if (count++ == 1 && s.goal_id.id === goal.goal_id.id &&
339370
s.status === GoalStatus.SUCCEEDED) {
371+
clearInterval(timer);
340372
done();
341373
}
342374
});
343375
});
344376

345-
let goal = ac.sendGoal({ goal: {dishwasher_id: 12}});
377+
var goal = ac.sendGoal({ goal: {dishwasher_id: 14}});
378+
let timer = setInterval(() => {
379+
goal = ac.sendGoal({ goal: {dishwasher_id: 14}});
380+
}, 50);
346381
});
347382
});

tutorials/actionlib.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $ node scripts/generate_messages.js
3838

3939
### Build the shared library from the msg files
4040
```
41-
$ cd test/ros1_action
41+
$ cd test/ros1_actions
4242
$ colcon build
4343
```
4444

0 commit comments

Comments
 (0)