diff --git a/lib/core/cluster.ts b/lib/core/cluster.ts index 4b844ab..0184786 100644 --- a/lib/core/cluster.ts +++ b/lib/core/cluster.ts @@ -55,7 +55,7 @@ class Cluster extends Process { modConfig.env = structuredClone(this.config.env || {}) modConfig.env.PUP_CLUSTER_INSTANCE = i.toString() - // Expose PUP_CLUSTER_PORT whenever a start port is configured + // Add PUP_CLUSTER_PORT if startPort is defined (regardless of whether the built-in load balancer is activated via commonPort) if (this.config.cluster?.startPort !== undefined) { modConfig.env.PUP_CLUSTER_PORT = (this.config.cluster.startPort + i).toString() } @@ -71,7 +71,7 @@ class Cluster extends Process { if (this.config.cluster?.commonPort && this.config.cluster.startPort) { backends.push({ host: "127.0.0.1", - port: (this.config.cluster.startPort + i), + port: this.config.cluster.startPort + i, }) } } diff --git a/test/core/pup.test.ts b/test/core/pup.test.ts index e67c480..5d694ac 100644 --- a/test/core/pup.test.ts +++ b/test/core/pup.test.ts @@ -7,8 +7,7 @@ import type { Configuration } from "../../lib/core/configuration.ts" import { ApiProcessState } from "@pup/api-definitions" import { Pup } from "../../lib/core/pup.ts" -import { Cluster } from "../../lib/core/cluster.ts" -import { assert, assertEquals, assertNotEquals } from "@std/assert" +import { assertEquals, assertNotEquals } from "@std/assert" import { test } from "@cross/test" test("Create test process. Test start, block, stop, start, unblock, start in sequence.", async () => { @@ -121,34 +120,3 @@ test("Create test cluster. Test start, block, stop, start, unblock, start in seq // Terminate pup, allow 2.5 seconds for graceful shutdown await pup.terminate(2500) }) - -test("Cluster sets PUP_CLUSTER_PORT for each instance without common port", async () => { - const TEST_PROCESS_ID = "test-3" - const TEST_PROCESS_COMMAND = "deno run -A lib/test/core/test-data/test_process.ts" - - const config: Configuration = { - processes: [ - { - "id": TEST_PROCESS_ID, - "cmd": TEST_PROCESS_COMMAND, - "cluster": { - "instances": 2, - "startPort": 8000, - }, - }, - ], - } - const pup = new Pup(config) - await pup.init() - - const testProcess = pup.processes.findLast((p) => p.getConfig().id === TEST_PROCESS_ID) - assert(testProcess instanceof Cluster) - - const [instance0, instance1] = testProcess.processes - assertEquals(instance0.getConfig().env?.PUP_CLUSTER_INSTANCE, "0") - assertEquals(instance0.getConfig().env?.PUP_CLUSTER_PORT, "8000") - assertEquals(instance1.getConfig().env?.PUP_CLUSTER_INSTANCE, "1") - assertEquals(instance1.getConfig().env?.PUP_CLUSTER_PORT, "8001") - - await pup.terminate(2500) -})