Skip to content

Commit

Permalink
fix: duplicate logging of => false when testing if JS controller is…
Browse files Browse the repository at this point in the history
… running (#605)
  • Loading branch information
AlCalzone authored Apr 17, 2024
1 parent 107fc26 commit 0dfc034
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
14 changes: 8 additions & 6 deletions build/tests/integration/lib/controllerSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ class ControllerSetup {
debug("Testing if JS-Controller is running...");
return new Promise((resolve) => {
const client = new net_1.Socket();
const timeout = setTimeout(() => {
// Assume the connection failed after 1 s
client.destroy();
debug(` => false`);
resolve(false);
}, 1000);
// Try to connect to an existing ObjectsDB
client
.connect({
Expand All @@ -127,19 +133,15 @@ class ControllerSetup {
// The connection succeeded
client.destroy();
debug(` => true`);
clearTimeout(timeout);
resolve(true);
})
.on("error", () => {
client.destroy();
debug(` => false`);
clearTimeout(timeout);
resolve(false);
});
setTimeout(() => {
// Assume the connection failed after 1 s
client.destroy();
debug(` => false`);
resolve(false);
}, 1000);
});
}
// /**
Expand Down
19 changes: 11 additions & 8 deletions src/tests/integration/lib/controllerSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import type { DBConnection } from "./dbConnection";
import {
getTestAdapterDir,
getTestControllerDir,
getTestDataDir,
getTestDBDir,
getTestDataDir,
getTestLogDir,
} from "./tools";

Expand Down Expand Up @@ -131,6 +131,14 @@ export class ControllerSetup {
debug("Testing if JS-Controller is running...");
return new Promise<boolean>((resolve) => {
const client = new Socket();

const timeout = setTimeout(() => {
// Assume the connection failed after 1 s
client.destroy();
debug(` => false`);
resolve(false);
}, 1000);

// Try to connect to an existing ObjectsDB
client
.connect({
Expand All @@ -141,20 +149,15 @@ export class ControllerSetup {
// The connection succeeded
client.destroy();
debug(` => true`);
clearTimeout(timeout);
resolve(true);
})
.on("error", () => {
client.destroy();
debug(` => false`);
clearTimeout(timeout);
resolve(false);
});

setTimeout(() => {
// Assume the connection failed after 1 s
client.destroy();
debug(` => false`);
resolve(false);
}, 1000);
});
}

Expand Down

0 comments on commit 0dfc034

Please sign in to comment.