Skip to content

Commit

Permalink
Bringing deno-amqp up-to-date and further (#46)
Browse files Browse the repository at this point in the history
* chore: update dependencies to jsr

* chore(multiplexer): remove linting exception for banned types

* chore(codegen): update json import

* style(codegen): specify lint ignore to no empty interface

* test(module): remove obsolete crypto import

* test(multiplexer): avoid leaking ops from timeout

* chore(bench): replace deno run with deno command

* ci: update actions to use latest stable and canary deno versions

---------

Co-authored-by: Nash Addams <[email protected]>
  • Loading branch information
nashaddams and Nash Addams authored Apr 18, 2024
1 parent a088dff commit 63cbcb4
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 78 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,30 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
services:
rabbitmq:
image: rabbitmq:3-management
ports:
- 5672:5672
- 15672:15672
strategy:
matrix:
os: [ubuntu-latest]
deno: [v1.x, canary]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup Deno environment
uses: denolib/setup-deno@v2.3.0
uses: denoland/setup-deno@v1
with:
deno-version: v1.28.1
deno-version: ${{ matrix.deno }}

- name: Check formatting
run: deno fmt --check

- name: Lint
run: deno lint --unstable src/ module_test/
run: deno lint src/ module_test/

- name: Run unit tests
run: deno test src/
Expand Down
30 changes: 14 additions & 16 deletions bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@ function isBench(file: Deno.DirEntry) {

async function runBench(name: string) {
const path = await Deno.realPath("./benchmark/" + name);

const now = Date.now();
const process = Deno.run(
{
cmd: [
"deno",
"run",
"--allow-net",
"--allow-write",
"--allow-read",
path,
],
},
);

const status = await process.status();
const command = new Deno.Command(Deno.execPath(), {
args: [
"run",
"--allow-net",
"--allow-write",
"--allow-read",
path,
],
});

const { code, stderr } = command.outputSync();
const time = Date.now() - now;
if (!status.success) {
throw new Error(`Failed ${path} - ${status}`);

if (code !== 0) {
throw new Error(`Failed ${path} - ${stderr}`);
}

return time;
Expand Down
2 changes: 1 addition & 1 deletion codegen/amqp_spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import spec from "./amqp-rabbitmq-0.9.1.json" assert { type: "json" };
import spec from "./amqp-rabbitmq-0.9.1.json" with { type: "json" };

export interface Spec {
classes: ClassDefinition[];
Expand Down
2 changes: 1 addition & 1 deletion codegen/generate_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { printClassPropertyInterface, printMethodArgsInterface, printMethodValue
import spec, { Spec } from "./amqp_spec.ts";

const template = (spec: Spec) => `
// deno-lint-ignore-file
// deno-lint-ignore-file no-empty-interface
${spec.classes.map(printClassPropertyInterface).join("\n")}
${spec.classes.flatMap((clazz) => clazz.methods.map((m) => printMethodArgsInterface(spec, clazz, m))).join("\n")}
${spec.classes.flatMap((clazz) => clazz.methods.map((m) => printMethodValueInterface(spec, clazz, m))).join("\n")}
Expand Down
64 changes: 32 additions & 32 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { Buffer, BufReader } from "https://deno.land/[email protected]/io/mod.ts";
export { writeAll } from "https://deno.land/[email protected]/streams/write_all.ts";
export { Buffer, BufReader, writeAll } from "jsr:@std/io";
10 changes: 1 addition & 9 deletions deps_dev.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
export {
assert,
assertEquals,
assertMatch,
assertNotEquals,
assertRejects,
assertThrows,
} from "https://deno.land/[email protected]/testing/asserts.ts";
export { crypto } from "https://deno.land/[email protected]/crypto/mod.ts";
export { assert, assertEquals, assertMatch, assertNotEquals, assertRejects, assertThrows } from "jsr:@std/assert";
1 change: 0 additions & 1 deletion module_test/frame_error_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { connect } from "../src/amqp_connect.ts";
import { crypto } from "../deps_dev.ts";

Deno.test(
"should not crash when sending large content frames concurrently",
Expand Down
1 change: 0 additions & 1 deletion src/amqp_multiplexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ function createSocketMux(writer: AmqpSocketWriter): AmqpSink {
channel: number,
classId: number,
methodId: number,
// deno-lint-ignore ban-types
args: object,
) {
return writer.write(
Expand Down
18 changes: 9 additions & 9 deletions src/amqp_multiplexer_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ function createSocket() {
};
}

function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
function flush() {
return Promise.resolve();
}

function createMockReader(frames: IncomingFrame[]) {
return async function mockRead() {
await sleep(0);
await flush();
const frame = frames.shift();
if (!frame) {
throw new Error(`EOF`);
Expand Down Expand Up @@ -367,8 +367,8 @@ test("receive - stops reading on error", async () => {
});

createAmqpMux(conn);
await sleep(0);
await sleep(0);
await flush();
await flush();
assertEquals(conn.read.mock.calls.length, 1);
});

Expand All @@ -380,10 +380,10 @@ test("receive - reads until error", async () => {
]));

createAmqpMux(conn);
await sleep(0);
await sleep(0);
await sleep(0);
await sleep(0);
await flush();
await flush();
await flush();
await flush();
assertEquals(conn.read.mock.calls.length, 3);
});

Expand Down
2 changes: 1 addition & 1 deletion src/amqp_types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// deno-lint-ignore-file
// deno-lint-ignore-file no-empty-interface

export interface ConnectionProperties {
}
Expand Down

0 comments on commit 63cbcb4

Please sign in to comment.