Commit ba6f9a5
authored
Fix action server goal expiration and correct broken test assertions (#1420)
## fix: action server goal expiration never removed expired goals
### Summary
Fixed two bugs in the action server goal expiration mechanism that caused expired goals to never be removed from memory, and a crash when they were. Also fixed 9 tautological test assertions that masked both bugs, and added deserialized goal info validation to the multi-goal expiration test.
### Bug 1 — Wrong buffer read in `_executeExpiredGoals` (`lib/action/server.js`)
`_executeExpiredGoals()` deserialized goal info from `result.data[i].refObject`, which are JavaScript wrapper objects each with their own empty `_refObject` buffer. The native `rcl_action_expire_goals()` writes into `result._refArray.buffer`, a completely separate memory block. The wrappers never see the native data, so the deserialized UUID was always all-zeros and `_goalHandles.delete(uuid)` never matched — goals were silently never expired.
**Fix:** Changed `goal.refObject` → `result._refArray[i]` to read directly from the native-written buffer.
### Bug 2 — Crash on zero-capacity buffer (`lib/node.js`)
After Bug 1 is fixed, expired goals are actually removed from `_goalHandles`. On the next spin cycle, `isGoalExpired` may still fire with `_goalHandles.size == 0`. Passing a zero-capacity buffer to `rcl_action_expire_goals` violates an RCL precondition and crashes:
> `expired_goals, expired_goals_capacity, and num_expired inconsistent`
**Fix:** Added `if (numGoals > 0)` guard to skip the native call when there are no goal handles.
### Bug 3 — Tautological test assertions (`test/test-action-server.js`)
9 instances of `assert.ok(value, expected)` where `assert.ok`'s second argument is a failure message, not a comparison. These always passed regardless of actual values.
**Fix:** Changed all 9 to `assert.strictEqual(value, expected)`.
### Enhanced test validation (`test/test-action-server.js`)
Added goal info validation to "Test expire goals multi" that wraps `_executeExpiredGoals` to intercept and verify the deserialized data from the native buffer:
- **Count:** exactly 3 expired goals reported
- **Non-zero UUIDs:** each deserialized UUID is not all-zeros (catches the original bug)
- **Uniqueness:** all 3 UUIDs are distinct (no buffer aliasing)
- **UUID match:** expired UUIDs are byte-identical to the accepted goal UUIDs
- **Non-zero stamps:** each `GoalInfo.stamp` has a non-zero acceptance time (validates full struct deserialization)
Also increased expiration delays from 1000ms to 3000ms for `resultTimeout: 1` (1 second) to provide adequate margin.
### Files changed
| File | Changes |
|------|---------|
| `lib/action/server.js` | Read from `result._refArray[i]` instead of `result.data[i].refObject` |
| `lib/node.js` | Guard `actionExpireGoals` call with `if (numGoals > 0)` |
| `test/test-action-server.js` | Fix 9 `assert.ok` → `assert.strictEqual`; add deserialized goal info validation; increase expire delays |
Fix: #14191 parent 7b89b67 commit ba6f9a5
3 files changed
Lines changed: 70 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
437 | 437 | | |
438 | 438 | | |
439 | 439 | | |
440 | | - | |
441 | | - | |
442 | 440 | | |
443 | | - | |
| 441 | + | |
444 | 442 | | |
445 | 443 | | |
446 | 444 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
437 | 441 | | |
438 | | - | |
439 | 442 | | |
440 | 443 | | |
441 | 444 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
446 | 446 | | |
447 | 447 | | |
448 | 448 | | |
449 | | - | |
| 449 | + | |
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
| |||
480 | 480 | | |
481 | 481 | | |
482 | 482 | | |
483 | | - | |
| 483 | + | |
484 | 484 | | |
485 | 485 | | |
486 | 486 | | |
| |||
515 | 515 | | |
516 | 516 | | |
517 | 517 | | |
518 | | - | |
| 518 | + | |
519 | 519 | | |
520 | 520 | | |
521 | 521 | | |
| |||
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
546 | | - | |
| 546 | + | |
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
| |||
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
570 | | - | |
| 570 | + | |
571 | 571 | | |
572 | 572 | | |
573 | 573 | | |
| |||
590 | 590 | | |
591 | 591 | | |
592 | 592 | | |
593 | | - | |
| 593 | + | |
594 | 594 | | |
595 | | - | |
596 | | - | |
| 595 | + | |
| 596 | + | |
597 | 597 | | |
598 | 598 | | |
599 | 599 | | |
| |||
610 | 610 | | |
611 | 611 | | |
612 | 612 | | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
613 | 631 | | |
614 | 632 | | |
615 | 633 | | |
| |||
620 | 638 | | |
621 | 639 | | |
622 | 640 | | |
623 | | - | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
624 | 653 | | |
625 | | - | |
626 | | - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
627 | 672 | | |
628 | 673 | | |
629 | 674 | | |
| |||
0 commit comments