Skip to content
32 changes: 22 additions & 10 deletions integrationTests/utils/harperLifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { getNextAvailableLoopbackAddress, releaseLoopbackAddress } from './loopb

// Constants
const HTTP_PORT = 9926;
const OPERATIONS_API_PORT = 9925;
const DEFAULT_ADMIN_USERNAME = 'admin';
const DEFAULT_ADMIN_PASSWORD = 'Abc1234!';
export const OPERATIONS_API_PORT = 9925;
export const DEFAULT_ADMIN_USERNAME = 'admin';
export const DEFAULT_ADMIN_PASSWORD = 'Abc1234!';
const DEFAULT_STARTUP_TIMEOUT_MS = parseInt(process.env.HARPER_INTEGRATION_TEST_STARTUP_TIMEOUT_MS, 10) || 30000;

/**
Expand Down Expand Up @@ -89,7 +89,7 @@ function getHarperScript(): string {
*/
function runHarperCommand(args: string[], env: any, completionMessage?: string): Promise<ChildProcess> {
const harperScript = getHarperScript();
const proc = spawn('node', [harperScript, ...args], {
const proc = spawn('node', ['--trace-warnings', harperScript, ...args], {
env: { ...process.env, ...env },
});
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -121,9 +121,6 @@ function runHarperCommand(args: string[], env: any, completionMessage?: string):
resolve(proc);
} else {
let errorMessage = `Harper process failed with exit code ${statusCode}`;
if (stdout) {
errorMessage += `\n\nstdout:\n${stdout}`;
}
if (stderr) {
errorMessage += `\n\nstderr:\n${stderr}`;
}
Expand Down Expand Up @@ -173,7 +170,7 @@ export async function setupHarper(ctx: ContextWithHarper, options?: SetupHarperO
*
* @param ctx - The test context with Harper installation details
*/
async function startHarper(ctx: ContextWithHarper, options?: SetupHarperOptions): Promise<ContextWithHarper> {
export async function startHarper(ctx: ContextWithHarper, options?: SetupHarperOptions): Promise<ContextWithHarper> {
// Create a directory for this Harper installation
// Use the system temp directory by default, or a custom parent directory if specified
const installDirPrefix = join(
Expand All @@ -182,7 +179,7 @@ async function startHarper(ctx: ContextWithHarper, options?: SetupHarperOptions)
);
const installDir = await mkdtemp(installDirPrefix);

const loopbackAddress = await getNextAvailableLoopbackAddress();
const loopbackAddress = ctx.hostname ?? (await getNextAvailableLoopbackAddress());
const harperProcess = await runHarperCommand(
[
`--ROOTPATH=${installDir}`,
Expand Down Expand Up @@ -238,7 +235,22 @@ async function startHarper(ctx: ContextWithHarper, options?: SetupHarperOptions)
* ```
*/
export async function teardownHarper(ctx: ContextWithHarper): Promise<void> {
ctx.harper.process.kill();
await new Promise((resolve) => {
let timer: NodeJS.Timeout;
ctx.harper.process.on('exit', () => {
resolve();
clearTimeout(timer);
});
ctx.harper.process.kill();
timer = setTimeout(() => {
try {
ctx.harper.process.kill('SIGKILL');
} catch {
// possible that the process terminated but the exit event hasn't reached us yet
}
resolve();
}, 200);
});

await releaseLoopbackAddress(ctx.harper.hostname);

Expand Down
8 changes: 5 additions & 3 deletions resources/analytics/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ const SAMPLING_INTERVAL_IN_MICROSECONDS = 50000;
// start the profiler
timeProfiler.start({ intervalMicros: SAMPLING_INTERVAL_IN_MICROSECONDS });
const PROFILE_PERIOD = (envGet(CONFIG_PARAMS.ANALYTICS_AGGREGATEPERIOD) || 60) * 1000;
setTimeout(() => {
captureProfile(PROFILE_PERIOD);
}, PROFILE_PERIOD).unref();
if (PROFILE_PERIOD > 0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sure caused a lot of bizarre problems until I figured it out.

setTimeout(() => {
captureProfile(PROFILE_PERIOD);
}, PROFILE_PERIOD).unref();
}
})();

export async function captureProfile(delayToNextCapture?: number): Promise<void> {
Expand Down
8 changes: 6 additions & 2 deletions server/nodeName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ function getPortFromListeningPort(key: string) {
}

export function hostnameToUrl(hostname) {
let port = getPortFromListeningPort('operationsapi_network_port');
let port = getPortFromListeningPort('replication_port');
if (port) return `ws://${hostname}:${port}`;
port = getPortFromListeningPort('replication_secureport');
if (port) return `wss://${hostname}:${port}`;
port = getPortFromListeningPort('operationsapi_network_port');
if (port) return `ws://${hostname}:${port}`;
port = getPortFromListeningPort('operationsapi_network_secureport');
if (port) return `wss://${hostname}:${port}`;
Expand All @@ -65,7 +69,7 @@ export function urlToNodeName(nodeUrl?: string | URL): string | undefined {
}

export function getThisNodeUrl() {
const url: string | undefined = env.get(CONFIG_PARAMS.NODE_URL);
const url: string | undefined = env.get(CONFIG_PARAMS.REPLICATION_URL);
if (url) return url;
return hostnameToUrl(getThisNodeName());
}
9 changes: 5 additions & 4 deletions utility/environment/environmentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ function doesPropFileExist() {
*/
function initSync(force = false) {
try {
// If readPropsFile returns false, we are installing and don't need to read anything yet.
if (propFileExists || doesPropFileExist() || commonUtils.noBootFile() || force) {
configUtils.initConfig(force);
installProps[hdbTerms.HDB_SETTINGS_NAMES.HDB_ROOT_KEY] = configUtils.getConfigValue(
hdbTerms.HDB_SETTINGS_NAMES.HDB_ROOT_KEY
);
const configHdbRoot = configUtils.getConfigValue(hdbTerms.HDB_SETTINGS_NAMES.HDB_ROOT_KEY);
// Only overwrite if we actually got a value from config
if (configHdbRoot !== undefined) {
installProps[hdbTerms.HDB_SETTINGS_NAMES.HDB_ROOT_KEY] = configHdbRoot;
}
}
} catch (err) {
log.error(INIT_ERR);
Expand Down
Loading