Skip to content

Commit

Permalink
[LINT] linter
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Jul 9, 2024
1 parent 99c4954 commit f5e8707
Show file tree
Hide file tree
Showing 25 changed files with 102 additions and 106 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"exclude": ["*/lib", "*/build", "docs/"]
},
"lint": {
"exclude": ["*/lib", "*/build", "docs/", "transport-node/"]
"exclude": ["*/lib", "*/build", "docs/"]
},
"scopes": {
"*": {
Expand Down
3 changes: 2 additions & 1 deletion transport-node/src/node_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export class NodeTransport implements Transport {
this.setupHandlers();
this.signal.resolve();
return Promise.resolve();
} catch (err) {
} catch (ex) {
let err = ex;
if (!err) {
// this seems to be possible in Kubernetes
// where an error is thrown, but it is undefined
Expand Down
3 changes: 2 additions & 1 deletion transport-node/tests/auth.js → transport-node/test/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ describe(
const iterErr = deferred();
const sub = nc.subscribe("foo");
(async () => {
for await (const m of sub) {
for await (const _ of sub) {
// nothing
}
})().catch((err) => {
iterErr.resolve(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe(
const subj = createInbox();
const sub = nc.subscribe(subj, { max: 20 });
const iter = (async () => {
for await (const m of sub) {
for await (const _ of sub) {
break;
}
})();
Expand Down Expand Up @@ -111,7 +111,7 @@ describe(
await nc.request(subj);
await nc.drain();

let counts = subs.map((s) => {
const counts = subs.map((s) => {
return s.getReceived();
});
const count = counts.reduce((a, v) => a + v);
Expand Down Expand Up @@ -142,22 +142,22 @@ describe(
});

it("check subscription leaks", async () => {
let nc = await connect({ servers: u });
let subj = createInbox();
let sub = nc.subscribe(subj);
const nc = await connect({ servers: u });
const subj = createInbox();
const sub = nc.subscribe(subj);
sub.unsubscribe();
assert.equal(nc.protocol.subscriptions.size(), 0);
await nc.close();
});

it("check request leaks", async () => {
let nc = await connect({ servers: u });
let subj = createInbox();
const nc = await connect({ servers: u });
const subj = createInbox();

// should have no subscriptions
assert.equal(nc.protocol.subscriptions.size(), 0);

let sub = nc.subscribe(subj);
const sub = nc.subscribe(subj);
const _ = (async () => {
for await (const m of sub) {
m.respond();
Expand All @@ -167,7 +167,7 @@ describe(
// should have one subscription
assert.equal(nc.protocol.subscriptions.size(), 1);

let msgs = [];
const msgs = [];
msgs.push(nc.request(subj));
msgs.push(nc.request(subj));

Expand All @@ -186,13 +186,13 @@ describe(
});

it("check cancelled request leaks", async () => {
let nc = await connect({ servers: u });
let subj = createInbox();
const nc = await connect({ servers: u });
const subj = createInbox();

// should have no subscriptions
assert.equal(nc.protocol.subscriptions.size(), 0);

let rp = nc.request(subj, Empty, { timeout: 100 });
const rp = nc.request(subj, Empty, { timeout: 100 });

assert.equal(nc.protocol.subscriptions.size(), 1);
assert.equal(nc.protocol.muxSubscriptions.size(), 1);
Expand Down
40 changes: 20 additions & 20 deletions transport-node/tests/basics.js → transport-node/test/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const { describe, it, test, suite } = require("node:test");
const { describe, it } = require("node:test");
const assert = require("node:assert").strict;
const {
connect,
Expand All @@ -29,8 +29,6 @@ const { AckPolicy, jetstream, jetstreamManager } = require(
"@nats-io/jetstream",
);

const net = require("net");

const { deferred, delay, nuid } = require(
"@nats-io/nats-core/internal",
);
Expand Down Expand Up @@ -110,7 +108,7 @@ describe(
const nc = await connect({ servers: u });
const sub = nc.subscribe(subj);
const iter = (async () => {
for await (const m of sub) {
for await (const _ of sub) {
break;
}
})();
Expand Down Expand Up @@ -161,7 +159,7 @@ describe(
const subj = createInbox();
const sub = nc.subscribe(subj);
const _ = (async () => {
for await (const m of sub) {
for await (const _ of sub) {
lock.unlock();
}
})();
Expand Down Expand Up @@ -210,7 +208,7 @@ describe(
const partial = 2;
const full = 5;

let nc = await connect({ servers: u });
const nc = await connect({ servers: u });
const s = createInbox();

const sub = nc.subscribe(`${s}.*`);
Expand Down Expand Up @@ -272,8 +270,8 @@ describe(
});

it("basics - respond returns false if no reply subject set", async () => {
let nc = await connect({ servers: u });
let s = createInbox();
const nc = await connect({ servers: u });
const s = createInbox();
const dr = deferred();
const sub = nc.subscribe(s);
const _ = (async () => {
Expand All @@ -289,34 +287,34 @@ describe(
});

it("basics - closed cannot subscribe", async () => {
let nc = await connect({ servers: u });
const nc = await connect({ servers: u });
await nc.close();
let failed = false;
try {
nc.subscribe(createInbox());
assert.fail("should have not been able to subscribe");
} catch (err) {
} catch (_) {
failed = true;
}
assert.ok(failed);
});

it("basics - close cannot request", async () => {
let nc = await connect({ servers: u });
const nc = await connect({ servers: u });
await nc.close();
let failed = false;
try {
await nc.request(createInbox());
assert.fail("should have not been able to request");
} catch (err) {
} catch (_) {
failed = true;
}
assert.ok(failed);
});

it("basics - flush returns promise", async () => {
const nc = await connect({ servers: u });
let p = nc.flush();
const p = nc.flush();
if (!p) {
assert.fail("should have returned a promise");
}
Expand All @@ -325,8 +323,8 @@ describe(
});

it("basics - unsubscribe after close no error", async () => {
let nc = await connect({ servers: u });
let sub = nc.subscribe(createInbox());
const nc = await connect({ servers: u });
const sub = nc.subscribe(createInbox());
await nc.close();
sub.unsubscribe();
});
Expand Down Expand Up @@ -496,7 +494,8 @@ describe(
const lock = Lock(1);
const sub = nc.subscribe(createInbox(), { max: 1, timeout: 250 });
(async () => {
for await (const m of sub) {
for await (const _m of sub) {
// nothing
}
})().catch((err) => {
assert.equal(err.code, ErrorCode.Timeout);
Expand All @@ -511,7 +510,8 @@ describe(
const subj = createInbox();
const sub = nc.subscribe(subj, { max: 2, timeout: 500 });
(async () => {
for await (const m of sub) {
for await (const _m of sub) {
// nothing
}
})().catch((err) => {
assert.fail(err);
Expand All @@ -531,7 +531,7 @@ describe(
let c = 0;
const sub = nc.subscribe(subj, { max: 2, timeout: 300 });
(async () => {
for await (const m of sub) {
for await (const _m of sub) {
c++;
}
})().catch((err) => {
Expand Down Expand Up @@ -701,7 +701,7 @@ describe(

const lock = new Lock(5);
nc2.subscribe(subj, {
callback: (err, m) => {
callback: (_err, _m) => {
lock.unlock();
},
});
Expand All @@ -716,7 +716,7 @@ describe(
await nc2.close();
});

it("basics - createinbox", (t) => {
it("basics - createinbox", () => {
assert.ok(createInbox());
});

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe(
{ timeout: 20_000, concurrency: true, forceExit: true },
() => {
it("buffers don't clobber", async () => {
let iters = 250 * 1024;
const iters = 250 * 1024;
const data = makeBuffer(iters * 1024);
const ns = await NatsServer.start();
const nc = await connect({ port: ns.port });
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ exports.check = function check(
opts = Object.assign(opts, { interval: 50 });

const d = deferred();
let timer;
let to;

to = setTimeout(() => {
const to = setTimeout(() => {
clearTimeout(to);
clearInterval(timer);
const m = opts.name ? `${opts.name} timeout` : "timeout";
return d.reject(new Error(m));
}, timeout);

timer = setInterval(async () => {
const timer = setInterval(async () => {
try {
const v = await fn();
if (v) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ export interface NatsServer extends PortInfo {
getLog(): string;
stop(): Promise<void>;
signal(s: "KILL" | "QUIT" | "STOP" | "REOPEN" | "RELOAD" | "LDM");
varz(): Promise<any>;
varz(): Promise<unknown>;
}
Loading

0 comments on commit f5e8707

Please sign in to comment.