Skip to content

Commit

Permalink
chore: test recovery procedure when finally traps (#4841)
Browse files Browse the repository at this point in the history
This PR adds a substitution variable `$PRINCIPAL` to `.drun` scripts, encoding a message argument `{ canister_id = $ID }`.
Using this information we can invoke the management canister's `start_canister`/`stop_canister` methods and with this we can implement a test for the recovery sequence detailed in #4840, to upgrade even if there are continuations in the futures table, e.g. due to trapping `finally` block.


Fixes #4840.
  • Loading branch information
ggreif authored Jan 8, 2025
1 parent d87550d commit cef9238
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/drun-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ export RUST_MIN_STACK=$((10*1024*1024))
# drun creates canisters with this ID:
ID=rwlgt-iiaaa-aaaaa-aaaaa-cai

# encoded `{ canister_id = $ID }`
# this is useful for `ingress aaaaa-aa start/stop_canister $PRINCIPAL`
PRINCIPAL=0x4449444c016c01b3c4b1f204680100010a00000000000000000101

if [ "${1: -5}" = ".drun" ]
then
# work around different IDs in ic-ref-run and drun
( echo "create"
LANG=C perl -npe 's,\$ID,'$ID',g' $1
LANG=C perl -npe 's,\$ID,'$ID',g; s,\$PRINCIPAL,'$PRINCIPAL',g' $1
) | drun -c "$CONFIG" --extra-batches $EXTRA_BATCHES /dev/stdin
else
( echo "create"
Expand Down
9 changes: 9 additions & 0 deletions test/run-drun/ok/try-finally-trap.drun.ok
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {rts_callback_table_count = 0}
ingress Completed: Reply: 0x4449444c0000
ingress Completed: Reply: 0x4449444c0000
debug.print: {rts_callback_table_count = 0}
ingress Completed: Reply: 0x4449444c0000
debug.print: trap in finally!
ingress Err: IC0503: Error from Canister rwlgt-iiaaa-aaaaa-aaaaa-cai: Canister called `ic0.trap` with message: assertion failed at try-finally-trap.mo:8.7-8.19
Expand All @@ -13,3 +17,8 @@ ingress Err: IC0503: Error from Canister rwlgt-iiaaa-aaaaa-aaaaa-cai: Canister c
Consider gracefully handling failures from this canister or altering the canister to handle exceptions. See documentation: http://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly
debug.print: {rts_callback_table_count = 1}
ingress Completed: Reply: 0x4449444c0000
ingress Completed: Reply: 0x4449444c0000
ingress Completed: Reply: 0x4449444c0000
ingress Completed: Reply: 0x4449444c0000
debug.print: {rts_callback_table_count = 0}
ingress Completed: Reply: 0x4449444c0000
6 changes: 6 additions & 0 deletions test/run-drun/try-finally-trap.drun
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
install $ID try-finally-trap/try-finally-trap.mo ""
ingress $ID show "DIDL\x00\x00"
upgrade $ID try-finally-trap/try-finally-trap.mo ""
ingress $ID show "DIDL\x00\x00"
ingress $ID go "DIDL\x00\x00"
ingress $ID show "DIDL\x00\x00"
upgrade $ID try-finally-trap/try-finally-trap.mo ""
ingress $ID show "DIDL\x00\x00"
ingress aaaaa-aa stop_canister $PRINCIPAL
upgrade $ID try-finally-trap/try-finally-trap.mo ""
ingress aaaaa-aa start_canister $PRINCIPAL
ingress $ID show "DIDL\x00\x00"

0 comments on commit cef9238

Please sign in to comment.