Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/core/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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,
})
}
}
Expand Down
34 changes: 1 addition & 33 deletions test/core/pup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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)
})