fix(tapbundle_serverside): add TapNodeTools cleanup hooks to stop SmartNetwork processes after tests
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
import { TestFileProvider } from './classes.testfileprovider.js';
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
class TapNodeTools {
|
||||
export interface ITapCleanupTarget {
|
||||
registerCleanup: (fn: () => Promise<void> | void) => void;
|
||||
}
|
||||
|
||||
export class TapNodeTools {
|
||||
private smartshellInstance: plugins.smartshell.Smartshell;
|
||||
private smartnetworkInstance: plugins.smartnetwork.SmartNetwork;
|
||||
public testFileProvider = new TestFileProvider();
|
||||
|
||||
constructor() {}
|
||||
constructor(tapArg: ITapCleanupTarget) {
|
||||
tapArg.registerCleanup(() => this.cleanup());
|
||||
}
|
||||
|
||||
private qenv: plugins.qenv.Qenv;
|
||||
public async getQenv(): Promise<plugins.qenv.Qenv> {
|
||||
@@ -75,7 +81,7 @@ class TapNodeTools {
|
||||
/**
|
||||
* create and return a smartmongo instance
|
||||
*/
|
||||
public async createSmartmongo() {
|
||||
public async createSmartmongo() {
|
||||
const smartmongoMod = await import('@push.rocks/smartmongo');
|
||||
const smartmongoInstance = new smartmongoMod.SmartMongo();
|
||||
await smartmongoInstance.start();
|
||||
@@ -217,6 +223,15 @@ class TapNodeTools {
|
||||
`Could not find ${countArg} consecutive free ports in range ${options.startPort}-${options.endPort}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const tapNodeTools = new TapNodeTools();
|
||||
/**
|
||||
* Clean up long-lived resources (e.g. the SmartNetwork Rust bridge process)
|
||||
* so the Node.js event loop can drain naturally.
|
||||
*/
|
||||
public async cleanup() {
|
||||
if (this.smartnetworkInstance) {
|
||||
await this.smartnetworkInstance.stop();
|
||||
this.smartnetworkInstance = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user