Skip to content

Commit

Permalink
[FIX] cluster tool - fixed port assignment when enabling JetStream on…
Browse files Browse the repository at this point in the history
… the cluster.
  • Loading branch information
aricart committed Dec 4, 2023
1 parent d20f2bb commit a9e4ce4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 43 deletions.
57 changes: 33 additions & 24 deletions tests/helpers/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ let chaosTimer: number | undefined;
let cluster: NatsServer[];

try {
const base = {
let base = {
port,
debug: false,
tls: {},
http: 8222,
websocket: {
port: wsport,
no_tls: true,
Expand All @@ -85,39 +87,46 @@ try {
},
};

if (cert) {
base.tls = {
cert_file: cert,
key_file: key,
};
base.websocket.no_tls = false;
base.websocket.tls = {
cert_file: cert,
key_file: key,
};
}

const serverDebug = argv["debug"];
if (serverDebug) {
base.debug = true;
}

if (cert) {
base = Object.assign(base, {
tls: {
cert_file: cert,
key_file: key,
},
websocket: {
port: wsport,
no_tls: false,
compression: true,
tls: {
cert_file: cert,
key_file: key,
},
},
});
}

cluster = argv.jetstream
? await NatsServer.jetstreamCluster(
count,
Object.assign(base, {
port,
http: 8222,
jetstream: {
max_file_store: -1,
max_mem_store: -1,
},
}),
base.debug,
Object.assign(
base,
Object.assign(base, {
jetstream: {
max_file_store: -1,
max_mem_store: -1,
},
}),
),
)
: await NatsServer.cluster(
count,
Object.assign(base, { port }),
base.debug,
Object.assign(base),
serverDebug,
);

cluster.forEach((s) => {
Expand Down
27 changes: 8 additions & 19 deletions tests/helpers/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ export class NatsServer implements PortInfo {
delete serverConf.jetstream;
}
// form a cluster with the specified count
const servers = await NatsServer.cluster(count, serverConf, false);
const servers = await NatsServer.cluster(count, serverConf, debug);
servers.forEach((s) => {
s.updatePorts();
});

// extract all the configs
const configs = servers.map((s) => {
Expand All @@ -312,8 +315,8 @@ export class NatsServer implements PortInfo {
});

const routes: string[] = [];
configs.forEach((conf, idx, arr) => {
let { port, cluster, monitoring, websocket, config } = conf;
configs.forEach((conf) => {
let { port, cluster, config } = conf;

// jetstream defaults
const { jetstream } = jsopts();
Expand All @@ -334,23 +337,12 @@ export class NatsServer implements PortInfo {
config = extend(
config,
{ jetstream },
{ port, server_name: serverName },
serverConf || {},
{ server_name: serverName },
);

// set the specific ports that we ran on before
config.cluster.listen = config.cluster.listen.replace("-1", `${cluster}`);
routes.push(`nats://${config.cluster.listen}`);
if (conf.monitoring) {
config.http = monitoring;
}
if (websocket) {
config.websocket = config.websocket || {};
config.websocket.port = websocket;
}

// replace it
arr[idx] = { port, cluster, monitoring, websocket, config };
});

// update the routes to be explicit
Expand All @@ -359,7 +351,6 @@ export class NatsServer implements PortInfo {
return v.indexOf(c.config.cluster.listen) === -1;
});
});

// reconfigure the servers
servers.forEach((s, idx) => {
s.config = configs[idx].config;
Expand Down Expand Up @@ -507,8 +498,7 @@ export class NatsServer implements PortInfo {
if (ns.cluster === undefined) {
return Promise.reject(new Error("no cluster port on server"));
}
conf = conf || {};
conf = JSON.parse(JSON.stringify(conf));
conf = JSON.parse(JSON.stringify(conf || {}));
conf.port = -1;
if (conf.websocket) {
conf.websocket.port = -1;
Expand All @@ -518,7 +508,6 @@ export class NatsServer implements PortInfo {
conf.cluster.name = ns.clusterName;
conf.cluster.listen = "127.0.0.1:-1";
conf.cluster.routes = [`nats://${ns.hostname}:${ns.cluster}`];

return NatsServer.start(conf, debug);
}

Expand Down

0 comments on commit a9e4ce4

Please sign in to comment.