| 691 | } |
| 692 | |
| 693 | export async function stopApp(server: http.Server | undefined) { |
| 694 | if (!server) { |
| 695 | return |
| 696 | } |
| 697 | |
| 698 | if (server['__app']) { |
| 699 | await server['__app'].close() |
| 700 | } |
| 701 | |
| 702 | // Node.js's http::close() prevents new connections from being accepted, |
| 703 | // but doesn't close existing connections and if there are any leftover |
| 704 | // whole process teardown will wait until it's being closed. |
| 705 | // Instead, force close connections since this is teardown fn that we expect |
| 706 | // any connections to be closed already. |
| 707 | server['__socketSet']?.forEach(function (socket) { |
| 708 | if (!socket.closed && !socket.destroyed) { |
| 709 | socket.destroy() |
| 710 | } |
| 711 | }) |
| 712 | |
| 713 | await promisify(server.close).apply(server) |
| 714 | } |
| 715 | |
| 716 | export async function waitFor( |
| 717 | millisOrCondition: number | (() => boolean) |