Skip to content

Commit a0b6022

Browse files
committed
[FIX] simpler way to noResolve
1 parent d657906 commit a0b6022

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

nats-base-client/core.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,14 @@ export interface Server {
340340
tlsName: string;
341341

342342
resolve(
343-
opts: Partial<{ fn: DnsResolveFn; randomize: boolean; debug?: boolean }>,
343+
opts: Partial<
344+
{
345+
fn: DnsResolveFn;
346+
randomize: boolean;
347+
debug?: boolean;
348+
resolve?: boolean;
349+
}
350+
>,
344351
): Promise<Server[]>;
345352
}
346353

nats-base-client/protocol.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,12 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
594594
}
595595

596596
async _doDial(srv: Server): Promise<void> {
597-
const alts = await srv.resolve({
597+
const resolve = this.options.noResolve !== true;
598+
const alts = this.options.noResolve === true ? [srv] : await srv.resolve({
598599
fn: getResolveFn(),
599600
debug: this.options.debug,
600601
randomize: !this.options.noRandomize,
602+
resolve,
601603
});
602604

603605
let lastErr: Error | null = null;

nats-base-client/servers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ export class ServerImpl implements Server {
138138
fn: DnsResolveFn;
139139
randomize: boolean;
140140
resolve: boolean;
141-
debug?: boolean;
141+
debug: boolean;
142142
}
143143
>,
144144
): Promise<Server[]> {
145-
if (!opts.fn) {
145+
if (!opts.fn || !opts.resolve) {
146146
// we cannot resolve - transport doesn't support it
147147
// don't add - to resolves or we get a circ reference
148148
return [this];

src/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function connect(opts: ConnectionOptions = {}): Promise<NatsConnection> {
2727
factory: (): Transport => {
2828
return new DenoTransport();
2929
},
30-
dnsResolveFn: opts.noResolve === true ? undefined : denoResolveHost,
30+
dnsResolveFn: denoResolveHost,
3131
} as TransportFactory);
3232

3333
return NatsConnectionImpl.connect(opts);

tests/basics_test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import {
4848
collect,
4949
deferred,
5050
delay,
51-
getResolveFn,
5251
headers,
5352
isIP,
5453
NatsConnectionImpl,
@@ -1427,9 +1426,23 @@ Deno.test("basics - respond message", async () => {
14271426
});
14281427

14291428
Deno.test("basics - noResolve", async () => {
1430-
const { ns, nc } = await setup({}, { noResolve: true });
1431-
assertEquals(getResolveFn(), undefined);
1432-
await cleanup(ns, nc);
1429+
const token = Deno.env.get("NGS_CI_USER");
1430+
if (token === undefined) {
1431+
disabled(
1432+
`skipping: NGS_CI_USER is not available in the environment`,
1433+
);
1434+
return;
1435+
}
1436+
1437+
const nci = await connect({
1438+
servers: "connect.ngs.global",
1439+
authenticator: jwtAuthenticator(token),
1440+
noResolve: true,
1441+
}) as NatsConnectionImpl;
1442+
1443+
const srv = nci.protocol.servers.getCurrentServer();
1444+
assertEquals(srv.resolves, undefined);
1445+
await nci.close();
14331446
});
14341447

14351448
class MM implements Msg {

0 commit comments

Comments
 (0)