From 63cbcb46f9cb815885f798845fe17496dd3c7d47 Mon Sep 17 00:00:00 2001 From: nashaddams Date: Thu, 18 Apr 2024 21:02:36 +0200 Subject: [PATCH] Bringing deno-amqp up-to-date and further (#46) * 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 --- .github/workflows/ci.yml | 14 +++++--- bench.ts | 30 ++++++++-------- codegen/amqp_spec.ts | 2 +- codegen/generate_types.ts | 2 +- deno.lock | 64 ++++++++++++++++----------------- deps.ts | 3 +- deps_dev.ts | 10 +----- module_test/frame_error_test.ts | 1 - src/amqp_multiplexer.ts | 1 - src/amqp_multiplexer_test.ts | 18 +++++----- src/amqp_types.ts | 2 +- 11 files changed, 69 insertions(+), 78 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8388f7f..6a25820 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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/ diff --git a/bench.ts b/bench.ts index 65ecf24..7b29b88 100755 --- a/bench.ts +++ b/bench.ts @@ -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; diff --git a/codegen/amqp_spec.ts b/codegen/amqp_spec.ts index a28a478..b699bc3 100644 --- a/codegen/amqp_spec.ts +++ b/codegen/amqp_spec.ts @@ -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[]; diff --git a/codegen/generate_types.ts b/codegen/generate_types.ts index 89cd46d..f2e461a 100644 --- a/codegen/generate_types.ts +++ b/codegen/generate_types.ts @@ -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")} diff --git a/deno.lock b/deno.lock index 7b3802e..febf8db 100644 --- a/deno.lock +++ b/deno.lock @@ -1,34 +1,34 @@ { - "version": "2", - "remote": { - "https://deno.land/std@0.165.0/_util/asserts.ts": "d0844e9b62510f89ce1f9878b046f6a57bf88f208a10304aab50efcb48365272", - "https://deno.land/std@0.165.0/bytes/bytes_list.ts": "aba5e2369e77d426b10af1de0dcc4531acecec27f9b9056f4f7bfbf8ac147ab4", - "https://deno.land/std@0.165.0/bytes/equals.ts": "3c3558c3ae85526f84510aa2b48ab2ad7bdd899e2e0f5b7a8ffc85acb3a6043a", - "https://deno.land/std@0.165.0/bytes/mod.ts": "b2e342fd3669176a27a4e15061e9d588b89c1aaf5008ab71766e23669565d179", - "https://deno.land/std@0.165.0/crypto/_fnv/fnv32.ts": "aa9bddead8c6345087d3abd4ef35fb9655622afc333fc41fff382b36e64280b5", - "https://deno.land/std@0.165.0/crypto/_fnv/fnv64.ts": "625d7e7505b6cb2e9801b5fd6ed0a89256bac12b2bbb3e4664b85a88b0ec5bef", - "https://deno.land/std@0.165.0/crypto/_fnv/index.ts": "a8f6a361b4c6d54e5e89c16098f99b6962a1dd6ad1307dbc97fa1ecac5d7060a", - "https://deno.land/std@0.165.0/crypto/_fnv/util.ts": "4848313bed7f00f55be3cb080aa0583fc007812ba965b03e4009665bde614ce3", - "https://deno.land/std@0.165.0/crypto/_wasm/lib/deno_std_wasm_crypto.generated.mjs": "71c1ac20f32fdbdc9b31a14917779c7fa392dbc8b050059cbb2c35b400b975b1", - "https://deno.land/std@0.165.0/crypto/_wasm/mod.ts": "b49ec171049bbbaaed3c5a5a71dfcb3d09f880607c8d9c517638d0443bd0f874", - "https://deno.land/std@0.165.0/crypto/keystack.ts": "e481eed28007395e554a435e880fee83a5c73b9259ed8a135a75e4b1e4f381f7", - "https://deno.land/std@0.165.0/crypto/mod.ts": "ee76e7df2e3346a8233861ecb66659da37c7b7fa730b48d765f3fb80fff1819e", - "https://deno.land/std@0.165.0/crypto/timing_safe_equal.ts": "3784958e40a5fe10429a68b75cc5f8d34356bf0bc2eb93c80c3033e2a6f17821", - "https://deno.land/std@0.165.0/crypto/util.ts": "93fc9dbaa62421538ad60ee65337cbf1d8a0298fac3c4f70b37e5627e7e129eb", - "https://deno.land/std@0.165.0/encoding/base64.ts": "c57868ca7fa2fbe919f57f88a623ad34e3d970d675bdc1ff3a9d02bba7409db2", - "https://deno.land/std@0.165.0/encoding/base64url.ts": "a5f82a9fa703bd85a5eb8e7c1296bc6529e601ebd9642cc2b5eaa6b38fa9e05a", - "https://deno.land/std@0.165.0/encoding/hex.ts": "4cc5324417cbb4ac9b828453d35aed45b9cc29506fad658f1f138d981ae33795", - "https://deno.land/std@0.165.0/fmt/colors.ts": "9e36a716611dcd2e4865adea9c4bec916b5c60caad4cdcdc630d4974e6bb8bd4", - "https://deno.land/std@0.165.0/io/buffer.ts": "245f1762a949082ddc0a6e9b15589d0be2d29c150266decd04320b8a8318f9f6", - "https://deno.land/std@0.165.0/io/mod.ts": "6e781ebafd5cdccf9ab4afa1f499b08c513602d023cb08ceebc58758501f78bd", - "https://deno.land/std@0.165.0/io/readers.ts": "45847ad404afd2f605eae1cff193f223462bc55eeb9ae313c2f3db28aada0fd6", - "https://deno.land/std@0.165.0/io/types.d.ts": "107e1e64834c5ba917c783f446b407d33432c5d612c4b3430df64fc2b4ecf091", - "https://deno.land/std@0.165.0/io/util.ts": "294d163962e3310bd9485d3315c183dc3d0da1e6ddf23495c682f8e17e0413a8", - "https://deno.land/std@0.165.0/io/writers.ts": "2e1c63ffd0cfba411b1fd8374609abff9ea86187c9d4d885d42e6fc20325ef0e", - "https://deno.land/std@0.165.0/testing/_diff.ts": "a23e7fc2b4d8daa3e158fa06856bedf5334ce2a2831e8bf9e509717f455adb2c", - "https://deno.land/std@0.165.0/testing/_format.ts": "cd11136e1797791045e639e9f0f4640d5b4166148796cad37e6ef75f7d7f3832", - "https://deno.land/std@0.165.0/testing/asserts.ts": "1e340c589853e82e0807629ba31a43c84ebdcdeca910c4a9705715dfdb0f5ce8", - "https://deno.land/std@0.178.0/streams/write_all.ts": "3b2e1ce44913f966348ce353d02fa5369e94115181037cd8b602510853ec3033", - "https://deno.land/std@0.178.0/types.d.ts": "220ed56662a0bd393ba5d124aa6ae2ad36a00d2fcbc0e8666a65f4606aaa9784" - } + "version": "3", + "packages": { + "specifiers": { + "jsr:@std/assert": "jsr:@std/assert@0.222.1", + "jsr:@std/assert@^0.222.1": "jsr:@std/assert@0.222.1", + "jsr:@std/bytes@^0.222.1": "jsr:@std/bytes@0.222.1", + "jsr:@std/fmt@^0.222.1": "jsr:@std/fmt@0.222.1", + "jsr:@std/io": "jsr:@std/io@0.222.1" + }, + "jsr": { + "@std/assert@0.222.1": { + "integrity": "691637161ee584a9919d1f9950ddd1272feb8e0a19e83aa5b7563cedaf73d74c", + "dependencies": [ + "jsr:@std/fmt@^0.222.1" + ] + }, + "@std/bytes@0.222.1": { + "integrity": "04dbf33e889ed5f9f6a87bc6b6b882dc105fffae6d2b042f832d92d4f34771c0" + }, + "@std/fmt@0.222.1": { + "integrity": "ec3382f9b0261c1ab1a5c804aa355d816515fa984cdd827ed32edfb187c0a722" + }, + "@std/io@0.222.1": { + "integrity": "45c638370bccc0687d11e32481b276126201014516ffbe2f340700b8d81c015e", + "dependencies": [ + "jsr:@std/assert@^0.222.1", + "jsr:@std/bytes@^0.222.1" + ] + } + } + }, + "remote": {} } diff --git a/deps.ts b/deps.ts index 74e2320..7a2dd93 100644 --- a/deps.ts +++ b/deps.ts @@ -1,2 +1 @@ -export { Buffer, BufReader } from "https://deno.land/std@0.165.0/io/mod.ts"; -export { writeAll } from "https://deno.land/std@0.178.0/streams/write_all.ts"; +export { Buffer, BufReader, writeAll } from "jsr:@std/io"; diff --git a/deps_dev.ts b/deps_dev.ts index e568118..8ee7ac4 100644 --- a/deps_dev.ts +++ b/deps_dev.ts @@ -1,9 +1 @@ -export { - assert, - assertEquals, - assertMatch, - assertNotEquals, - assertRejects, - assertThrows, -} from "https://deno.land/std@0.165.0/testing/asserts.ts"; -export { crypto } from "https://deno.land/std@0.165.0/crypto/mod.ts"; +export { assert, assertEquals, assertMatch, assertNotEquals, assertRejects, assertThrows } from "jsr:@std/assert"; diff --git a/module_test/frame_error_test.ts b/module_test/frame_error_test.ts index 91758e6..411136f 100644 --- a/module_test/frame_error_test.ts +++ b/module_test/frame_error_test.ts @@ -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", diff --git a/src/amqp_multiplexer.ts b/src/amqp_multiplexer.ts index 572f735..d72b764 100644 --- a/src/amqp_multiplexer.ts +++ b/src/amqp_multiplexer.ts @@ -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( diff --git a/src/amqp_multiplexer_test.ts b/src/amqp_multiplexer_test.ts index 820c504..e89905f 100644 --- a/src/amqp_multiplexer_test.ts +++ b/src/amqp_multiplexer_test.ts @@ -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`); @@ -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); }); @@ -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); }); diff --git a/src/amqp_types.ts b/src/amqp_types.ts index 5e163d0..da0cb42 100644 --- a/src/amqp_types.ts +++ b/src/amqp_types.ts @@ -1,4 +1,4 @@ -// deno-lint-ignore-file +// deno-lint-ignore-file no-empty-interface export interface ConnectionProperties { }