e2e: phones unregister before their container is removed

Killing the baresip container left 'Avail' contacts in Asterisk; the
next script's phones (same IP) then had two contacts each and m5-t3's
presence check saw no state change. stop() now sends baresip SIGTERM
(found via /proc: no procps in the image) and waits before removing.

Task: M6-T8
This commit is contained in:
iamdoubz committed 2026-10-18 14:11:40 -05:00
1 parent 4fc0fb4084
commit 9808a602a9
1 file changed
+16 -1
+16 -1
View File
@@ -63,6 +63,21 @@ export function startPhones({ name, net, ast, phones }) {
const f = join(dir, ext, 'log'); const f = join(dir, ext, 'log');
return existsSync(f) ? readFileSync(f, 'utf8') : ''; return existsSync(f) ? readFileSync(f, 'utf8') : '';
}, },
stop: () => docker('rm', '-f', name), /**
* baresip unregisters on SIGTERM; killing the container would leave stale "Avail" contacts
* behind (Asterisk keeps them until they expire) that a later script's phones then share.
*/
stop: () => {
// No procps in the image: find baresip through /proc.
docker(
'exec',
name,
'sh',
'-c',
'for p in /proc/[0-9]*; do [ "$(cat $p/comm 2>/dev/null)" = baresip ] && kill -TERM ${p#/proc/}; done; true',
);
spawnSync('sleep', ['2']);
docker('rm', '-f', name);
},
}; };
} }