From 970fdbb9b59a13bb6abbb00b342272ebf448e540 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 10 Feb 2022 01:32:15 +0100 Subject: [PATCH 1/6] use `bytes::Bytes` --- Cargo.lock | 1 + amqp_transport/Cargo.toml | 1 + amqp_transport/src/connection.rs | 2 +- amqp_transport/src/frame.rs | 8 +++++--- amqp_transport/src/tests.rs | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04a1a6e..e1a825e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,6 +58,7 @@ dependencies = [ "amqp_core", "amqp_messaging", "anyhow", + "bytes", "criterion", "nom", "once_cell", diff --git a/amqp_transport/Cargo.toml b/amqp_transport/Cargo.toml index a69d7a7..664ebd8 100644 --- a/amqp_transport/Cargo.toml +++ b/amqp_transport/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" amqp_core = { path = "../amqp_core" } amqp_messaging = { path = "../amqp_messaging" } anyhow = "1.0.53" +bytes = "1.1.0" nom = "7.1.0" once_cell = "1.9.0" rand = "0.8.4" diff --git a/amqp_transport/src/connection.rs b/amqp_transport/src/connection.rs index 2628fca..55a20e9 100644 --- a/amqp_transport/src/connection.rs +++ b/amqp_transport/src/connection.rs @@ -95,7 +95,7 @@ impl Connection { &Frame { kind: FrameType::Method, channel, - payload, + payload: payload.into(), }, &mut self.stream, ) diff --git a/amqp_transport/src/frame.rs b/amqp_transport/src/frame.rs index 689b5de..c548233 100644 --- a/amqp_transport/src/frame.rs +++ b/amqp_transport/src/frame.rs @@ -1,5 +1,6 @@ use crate::error::{ConException, ProtocolError, Result}; use anyhow::Context; +use bytes::Bytes; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tracing::trace; @@ -18,7 +19,7 @@ pub struct Frame { pub kind: FrameType, pub channel: u16, /// Includes the whole payload, also including the metadata from each type. - pub payload: Vec, + pub payload: Bytes, } #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -72,7 +73,7 @@ where let frame = Frame { kind, channel, - payload, + payload: payload.into(), }; trace!(?frame, "Received frame"); @@ -99,6 +100,7 @@ fn parse_frame_type(kind: u8, channel: u16) -> Result { #[cfg(test)] mod tests { use crate::frame::{Frame, FrameType}; + use bytes::Bytes; #[tokio::test] async fn read_small_body() { @@ -127,7 +129,7 @@ mod tests { Frame { kind: FrameType::Method, channel: 0, - payload: vec![1, 2, 3], + payload: Bytes::from_static(&[1, 2, 3]), } ); } diff --git a/amqp_transport/src/tests.rs b/amqp_transport/src/tests.rs index 1f6dc71..b6af887 100644 --- a/amqp_transport/src/tests.rs +++ b/amqp_transport/src/tests.rs @@ -22,7 +22,7 @@ async fn write_start_ok_frame() { let frame = frame::Frame { kind: FrameType::Method, channel: 0, - payload, + payload: payload.into(), }; let mut output = Vec::new(); From 4cf7d7558b722a74fadea9a357a1a6abf834cd60 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 10 Feb 2022 02:50:53 +0100 Subject: [PATCH 2/6] content frames --- Cargo.lock | 3 ++ amqp_core/Cargo.toml | 2 + amqp_core/src/lib.rs | 1 + amqp_core/src/message.rs | 23 ++++++++++++ amqp_transport/Cargo.toml | 1 + amqp_transport/src/connection.rs | 64 +++++++++++++++++++++++++++----- amqp_transport/src/frame.rs | 17 +++++++++ 7 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 amqp_core/src/message.rs diff --git a/Cargo.lock b/Cargo.lock index e1a825e..82808ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,7 +28,9 @@ dependencies = [ name = "amqp_core" version = "0.1.0" dependencies = [ + "bytes", "parking_lot", + "smallvec", "uuid", ] @@ -64,6 +66,7 @@ dependencies = [ "once_cell", "rand", "regex", + "smallvec", "thiserror", "tokio", "tracing", diff --git a/amqp_core/Cargo.toml b/amqp_core/Cargo.toml index cec72f4..4a10592 100644 --- a/amqp_core/Cargo.toml +++ b/amqp_core/Cargo.toml @@ -6,5 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +bytes = "1.1.0" parking_lot = "0.12.0" +smallvec = { version = "1.8.0", features = ["union"] } uuid = "0.8.2" diff --git a/amqp_core/src/lib.rs b/amqp_core/src/lib.rs index 8dfb2f7..f92416d 100644 --- a/amqp_core/src/lib.rs +++ b/amqp_core/src/lib.rs @@ -1,5 +1,6 @@ #![warn(rust_2018_idioms)] +mod message; pub mod methods; use parking_lot::Mutex; diff --git a/amqp_core/src/message.rs b/amqp_core/src/message.rs new file mode 100644 index 0000000..eba4c8d --- /dev/null +++ b/amqp_core/src/message.rs @@ -0,0 +1,23 @@ +#![allow(dead_code)] + +use crate::methods; +use bytes::Bytes; +use smallvec::SmallVec; +use std::sync::Arc; +use uuid::Uuid; + +pub type Message = Arc; + +pub struct RawMessage { + id: Uuid, + properties: methods::Table, + routing: RoutingInformation, + content: SmallVec<[Bytes; 1]>, +} + +pub struct RoutingInformation { + pub exchange: String, + pub routing_key: String, + pub mandatory: bool, + pub immediate: bool, +} diff --git a/amqp_transport/Cargo.toml b/amqp_transport/Cargo.toml index 664ebd8..9fcae77 100644 --- a/amqp_transport/Cargo.toml +++ b/amqp_transport/Cargo.toml @@ -14,6 +14,7 @@ nom = "7.1.0" once_cell = "1.9.0" rand = "0.8.4" regex = "1.5.4" +smallvec = { version = "1.8.0", features = ["union"] } thiserror = "1.0.30" tokio = { version = "1.16.1", features = ["full"] } tracing = "0.1.30" diff --git a/amqp_transport/src/connection.rs b/amqp_transport/src/connection.rs index 55a20e9..1a88f0b 100644 --- a/amqp_transport/src/connection.rs +++ b/amqp_transport/src/connection.rs @@ -1,19 +1,25 @@ -use crate::error::{ConException, ProtocolError, Result}; -use crate::frame::{Frame, FrameType}; -use crate::{frame, methods, sasl}; -use amqp_core::methods::{FieldValue, Method, Table}; -use amqp_core::GlobalData; -use anyhow::Context; +use std::cmp::Ordering; use std::collections::HashMap; use std::net::SocketAddr; use std::pin::Pin; use std::time::Duration; + +use anyhow::Context; +use bytes::Bytes; +use smallvec::SmallVec; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::TcpStream; use tokio::time; use tracing::{debug, error, info, warn}; use uuid::Uuid; +use amqp_core::methods::{FieldValue, Method, Table}; +use amqp_core::GlobalData; + +use crate::error::{ConException, ProtocolError, Result}; +use crate::frame::{ContentHeader, Frame, FrameType}; +use crate::{frame, methods, sasl}; + fn ensure_conn(condition: bool) -> Result<()> { if condition { Ok(()) @@ -47,6 +53,12 @@ pub struct Connection { const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30); +enum WaitForBodyStatus { + Method(Method), + Header(Method, ContentHeader, SmallVec<[Bytes; 1]>), + None, +} + impl Connection { pub fn new( id: Uuid, @@ -196,6 +208,9 @@ impl Connection { } async fn main_loop(&mut self) -> Result<()> { + // todo: find out how header/body frames can interleave between channels + let mut wait_for_body = WaitForBodyStatus::None; + loop { debug!("Waiting for next frame"); let frame = frame::read_frame(&mut self.stream, self.max_frame_size).await?; @@ -203,14 +218,42 @@ impl Connection { self.reset_timeout(); match frame.kind { - FrameType::Method => self.dispatch_method(frame).await?, + FrameType::Method => wait_for_body = self.dispatch_method(frame).await?, FrameType::Heartbeat => {} - _ => warn!(frame_type = ?frame.kind, "TODO"), + FrameType::Header => match wait_for_body { + WaitForBodyStatus::None => warn!(channel = %frame.channel, "unexpected header"), + WaitForBodyStatus::Method(method) => { + wait_for_body = + WaitForBodyStatus::Header(method, ContentHeader::new(), SmallVec::new()) + } + WaitForBodyStatus::Header(_, _, _) => { + warn!(channel = %frame.channel, "already got header") + } + }, + FrameType::Body => match &mut wait_for_body { + WaitForBodyStatus::None => warn!(channel = %frame.channel, "unexpected body"), + WaitForBodyStatus::Method(_) => { + warn!(channel = %frame.channel, "unexpected body") + } + WaitForBodyStatus::Header(_, header, vec) => { + vec.push(frame.payload); + match vec + .iter() + .map(Bytes::len) + .sum::() + .cmp(&usize::try_from(header.body_size).unwrap()) + { + Ordering::Equal => todo!("process body"), + Ordering::Greater => todo!("too much data!"), + Ordering::Less => {} // wait for next body + } + } + }, } } } - async fn dispatch_method(&mut self, frame: Frame) -> Result<()> { + async fn dispatch_method(&mut self, frame: Frame) -> Result { let method = methods::parse_method(&frame.payload)?; debug!(?method, "Received method"); @@ -219,6 +262,7 @@ impl Connection { // todo: handle closing } Method::ChannelOpen { .. } => self.channel_open(frame.channel).await?, + Method::BasicPublish { .. } => return Ok(WaitForBodyStatus::Method(method)), _ => { let channel_handle = self .channels @@ -235,7 +279,7 @@ impl Connection { } } - Ok(()) + Ok(WaitForBodyStatus::None) } async fn channel_open(&mut self, num: u16) -> Result<()> { diff --git a/amqp_transport/src/frame.rs b/amqp_transport/src/frame.rs index c548233..cd9c53c 100644 --- a/amqp_transport/src/frame.rs +++ b/amqp_transport/src/frame.rs @@ -1,6 +1,8 @@ use crate::error::{ConException, ProtocolError, Result}; +use amqp_core::methods::FieldValue; use anyhow::Context; use bytes::Bytes; +use smallvec::SmallVec; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tracing::trace; @@ -31,6 +33,21 @@ pub enum FrameType { Heartbeat = 8, } +#[derive(Debug, Clone, PartialEq)] +pub struct ContentHeader { + pub class_id: u16, + pub weight: u16, + pub body_size: u64, + pub property_flags: SmallVec<[u16; 1]>, + pub property_fields: Vec, +} + +impl ContentHeader { + pub fn new() -> Self { + todo!() + } +} + pub async fn write_frame(frame: &Frame, mut w: W) -> Result<()> where W: AsyncWriteExt + Unpin, From daf94f2d4faf1bebfb274f257e16710c07a10a11 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 10 Feb 2022 04:16:37 +0100 Subject: [PATCH 3/6] add ts tets --- tests-ts/.gitignore | 1 + tests-ts/package.json | 18 +++ tests-ts/src/send-single-message.ts | 11 ++ tests-ts/tsconfig.json | 64 ++++++++ tests-ts/yarn.lock | 223 ++++++++++++++++++++++++++++ 5 files changed, 317 insertions(+) create mode 100644 tests-ts/.gitignore create mode 100644 tests-ts/package.json create mode 100644 tests-ts/src/send-single-message.ts create mode 100644 tests-ts/tsconfig.json create mode 100644 tests-ts/yarn.lock diff --git a/tests-ts/.gitignore b/tests-ts/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/tests-ts/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/tests-ts/package.json b/tests-ts/package.json new file mode 100644 index 0000000..8d19cf2 --- /dev/null +++ b/tests-ts/package.json @@ -0,0 +1,18 @@ +{ + "name": "tests-ts", + "version": "0.0.0", + "main": "index.ts", + "license": "MIT", + "scripts": { + "fmt": "prettier -w ." + }, + "dependencies": { + "@types/amqplib": "^0.8.2", + "amqplib": "^0.8.0" + }, + "devDependencies": { + "prettier": "^2.5.1", + "ts-node": "^10.5.0", + "typescript": "^4.5.5" + } +} diff --git a/tests-ts/src/send-single-message.ts b/tests-ts/src/send-single-message.ts new file mode 100644 index 0000000..91cb95e --- /dev/null +++ b/tests-ts/src/send-single-message.ts @@ -0,0 +1,11 @@ +import {connect} from 'amqplib'; + +(async () => { + const connection = await connect('amqp://localhost'); + + const channel = await connection.createChannel(); + + channel.publish('exchange-1', 'queue-1', Buffer.from('hello')); + + console.log("Hello world!"); +})() diff --git a/tests-ts/tsconfig.json b/tests-ts/tsconfig.json new file mode 100644 index 0000000..1f2911a --- /dev/null +++ b/tests-ts/tsconfig.json @@ -0,0 +1,64 @@ +{ + "compilerOptions": { + // "incremental": true, /* Enable incremental compilation */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2017", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "lib": ["es2021"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ + // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + + /* Modules */ + "module": "commonjs", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "resolveJsonModule": true, /* Enable importing .json files */ + // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ + // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ + // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + } +} diff --git a/tests-ts/yarn.lock b/tests-ts/yarn.lock new file mode 100644 index 0000000..8f60d79 --- /dev/null +++ b/tests-ts/yarn.lock @@ -0,0 +1,223 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@cspotcode/source-map-consumer@0.8.0": + version "0.8.0" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b" + integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg== + +"@cspotcode/source-map-support@0.7.0": + version "0.7.0" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5" + integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA== + dependencies: + "@cspotcode/source-map-consumer" "0.8.0" + +"@tsconfig/node10@^1.0.7": + version "1.0.8" + resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9" + integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg== + +"@tsconfig/node12@^1.0.7": + version "1.0.9" + resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c" + integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw== + +"@tsconfig/node14@^1.0.0": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2" + integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg== + +"@tsconfig/node16@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" + integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== + +"@types/amqplib@^0.8.2": + version "0.8.2" + resolved "https://registry.yarnpkg.com/@types/amqplib/-/amqplib-0.8.2.tgz#9c46f2c7fac381e4f81bcb612c00d54549697d22" + integrity sha512-p+TFLzo52f8UanB+Nq6gyUi65yecAcRY3nYowU6MPGFtaJvEDxcnFWrxssSTkF+ts1W3zyQDvgVICLQem5WxRA== + dependencies: + "@types/bluebird" "*" + "@types/node" "*" + +"@types/bluebird@*": + version "3.5.36" + resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.36.tgz#00d9301d4dc35c2f6465a8aec634bb533674c652" + integrity sha512-HBNx4lhkxN7bx6P0++W8E289foSu8kO8GCk2unhuVggO+cE7rh9DhZUyPhUxNRG9m+5B5BTKxZQ5ZP92x/mx9Q== + +"@types/node@*": + version "17.0.19" + resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.19.tgz#726171367f404bfbe8512ba608a09ebad810c7e6" + integrity sha512-PfeQhvcMR4cPFVuYfBN4ifG7p9c+Dlh3yUZR6k+5yQK7wX3gDgVxBly4/WkBRs9x4dmcy1TVl08SY67wwtEvmA== + +acorn-walk@^8.1.1: + version "8.2.0" + resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" + integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA== + +acorn@^8.4.1: + version "8.7.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" + integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ== + +amqplib@^0.8.0: + version "0.8.0" + resolved "https://registry.yarnpkg.com/amqplib/-/amqplib-0.8.0.tgz#088d10bc61cc5ac5a49ac72033c7ac66c23aeb61" + integrity sha512-icU+a4kkq4Y1PS4NNi+YPDMwdlbFcZ1EZTQT2nigW3fvOb6AOgUQ9+Mk4ue0Zu5cBg/XpDzB40oH10ysrk2dmA== + dependencies: + bitsyntax "~0.1.0" + bluebird "^3.7.2" + buffer-more-ints "~1.0.0" + readable-stream "1.x >=1.1.9" + safe-buffer "~5.2.1" + url-parse "~1.5.1" + +arg@^4.1.0: + version "4.1.3" + resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" + integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== + +bitsyntax@~0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/bitsyntax/-/bitsyntax-0.1.0.tgz#b0c59acef03505de5a2ed62a2f763c56ae1d6205" + integrity sha512-ikAdCnrloKmFOugAfxWws89/fPc+nw0OOG1IzIE72uSOg/A3cYptKCjSUhDTuj7fhsJtzkzlv7l3b8PzRHLN0Q== + dependencies: + buffer-more-ints "~1.0.0" + debug "~2.6.9" + safe-buffer "~5.1.2" + +bluebird@^3.7.2: + version "3.7.2" + resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" + integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== + +buffer-more-ints@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/buffer-more-ints/-/buffer-more-ints-1.0.0.tgz#ef4f8e2dddbad429ed3828a9c55d44f05c611422" + integrity sha512-EMetuGFz5SLsT0QTnXzINh4Ksr+oo4i+UGTXEshiGCQWnsgSs7ZhJ8fzlwQ+OzEMs0MpDAMr1hxnblp5a4vcHg== + +core-util-is@~1.0.0: + version "1.0.3" + resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85" + integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ== + +create-require@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" + integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== + +debug@~2.6.9: + version "2.6.9" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== + dependencies: + ms "2.0.0" + +diff@^4.0.1: + version "4.0.2" + resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" + integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== + +inherits@~2.0.1: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +isarray@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" + integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8= + +make-error@^1.1.1: + version "1.3.6" + resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" + integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= + +prettier@^2.5.1: + version "2.5.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a" + integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg== + +querystringify@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6" + integrity sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ== + +"readable-stream@1.x >=1.1.9": + version "1.1.14" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.14.tgz#7cf4c54ef648e3813084c636dd2079e166c081d9" + integrity sha1-fPTFTvZI44EwhMY23SB54WbAgdk= + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + +requires-port@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" + integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8= + +safe-buffer@~5.1.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" + integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== + +safe-buffer@~5.2.1: + version "5.2.1" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" + integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== + +string_decoder@~0.10.x: + version "0.10.31" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" + integrity sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ= + +ts-node@^10.5.0: + version "10.5.0" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.5.0.tgz#618bef5854c1fbbedf5e31465cbb224a1d524ef9" + integrity sha512-6kEJKwVxAJ35W4akuiysfKwKmjkbYxwQMTBaAxo9KKAx/Yd26mPUyhGz3ji+EsJoAgrLqVsYHNuuYwQe22lbtw== + dependencies: + "@cspotcode/source-map-support" "0.7.0" + "@tsconfig/node10" "^1.0.7" + "@tsconfig/node12" "^1.0.7" + "@tsconfig/node14" "^1.0.0" + "@tsconfig/node16" "^1.0.2" + acorn "^8.4.1" + acorn-walk "^8.1.1" + arg "^4.1.0" + create-require "^1.1.0" + diff "^4.0.1" + make-error "^1.1.1" + v8-compile-cache-lib "^3.0.0" + yn "3.1.1" + +typescript@^4.5.5: + version "4.5.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3" + integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA== + +url-parse@~1.5.1: + version "1.5.9" + resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.9.tgz#05ff26484a0b5e4040ac64dcee4177223d74675e" + integrity sha512-HpOvhKBvre8wYez+QhHcYiVvVmeF6DVnuSOOPhe3cTum3BnqHhvKaZm8FU5yTiOu/Jut2ZpB2rA/SbBA1JIGlQ== + dependencies: + querystringify "^2.1.1" + requires-port "^1.0.0" + +v8-compile-cache-lib@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz#0582bcb1c74f3a2ee46487ceecf372e46bce53e8" + integrity sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA== + +yn@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" + integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== From f437754618892c8a13f9402e276dadaa7d445d41 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 10 Feb 2022 04:58:52 +0100 Subject: [PATCH 4/6] use javascript instead because startup times --- {tests-ts => tests-js}/.gitignore | 0 tests-js/.prettierrc.json | 3 + {tests-ts => tests-js}/package.json | 7 +-- tests-js/src/open-channel.js | 17 +++++ tests-js/src/send-single-message.js | 16 +++++ tests-js/src/utils.js | 1 + {tests-ts => tests-js}/yarn.lock | 96 ----------------------------- tests-ts/src/send-single-message.ts | 11 ---- tests-ts/tsconfig.json | 64 ------------------- 9 files changed, 40 insertions(+), 175 deletions(-) rename {tests-ts => tests-js}/.gitignore (100%) create mode 100644 tests-js/.prettierrc.json rename {tests-ts => tests-js}/package.json (68%) create mode 100644 tests-js/src/open-channel.js create mode 100644 tests-js/src/send-single-message.js create mode 100644 tests-js/src/utils.js rename {tests-ts => tests-js}/yarn.lock (54%) delete mode 100644 tests-ts/src/send-single-message.ts delete mode 100644 tests-ts/tsconfig.json diff --git a/tests-ts/.gitignore b/tests-js/.gitignore similarity index 100% rename from tests-ts/.gitignore rename to tests-js/.gitignore diff --git a/tests-js/.prettierrc.json b/tests-js/.prettierrc.json new file mode 100644 index 0000000..544138b --- /dev/null +++ b/tests-js/.prettierrc.json @@ -0,0 +1,3 @@ +{ + "singleQuote": true +} diff --git a/tests-ts/package.json b/tests-js/package.json similarity index 68% rename from tests-ts/package.json rename to tests-js/package.json index 8d19cf2..ccee7e0 100644 --- a/tests-ts/package.json +++ b/tests-js/package.json @@ -1,7 +1,8 @@ { - "name": "tests-ts", + "name": "tests-js", "version": "0.0.0", "main": "index.ts", + "type": "module", "license": "MIT", "scripts": { "fmt": "prettier -w ." @@ -11,8 +12,6 @@ "amqplib": "^0.8.0" }, "devDependencies": { - "prettier": "^2.5.1", - "ts-node": "^10.5.0", - "typescript": "^4.5.5" + "prettier": "^2.5.1" } } diff --git a/tests-js/src/open-channel.js b/tests-js/src/open-channel.js new file mode 100644 index 0000000..893970a --- /dev/null +++ b/tests-js/src/open-channel.js @@ -0,0 +1,17 @@ +import { connect } from 'amqplib'; +import { sleep } from './utils.js'; + +(async () => { + const connection = await connect('amqp://localhost'); + + const channel = await connection.createChannel(); + + console.log('Successfully opened channel'); + + await sleep(100_000); + + await channel.close(); + await connection.close(); + + console.log('Successfully shut down connection'); +})(); diff --git a/tests-js/src/send-single-message.js b/tests-js/src/send-single-message.js new file mode 100644 index 0000000..b84b3db --- /dev/null +++ b/tests-js/src/send-single-message.js @@ -0,0 +1,16 @@ +import { connect } from 'amqplib'; + +(async () => { + const connection = await connect('amqp://localhost'); + + const channel = await connection.createChannel(); + + channel.publish('exchange-1', 'queue-1', Buffer.from('hello')); + + console.log('Published message'); + + await channel.close(); + await connection.close(); + + console.log('Successfully shut down connection'); +})(); diff --git a/tests-js/src/utils.js b/tests-js/src/utils.js new file mode 100644 index 0000000..0e51ee3 --- /dev/null +++ b/tests-js/src/utils.js @@ -0,0 +1 @@ +export const sleep = (ms) => new Promise((res) => setTimeout(res, ms)); diff --git a/tests-ts/yarn.lock b/tests-js/yarn.lock similarity index 54% rename from tests-ts/yarn.lock rename to tests-js/yarn.lock index 8f60d79..f489366 100644 --- a/tests-ts/yarn.lock +++ b/tests-js/yarn.lock @@ -2,38 +2,6 @@ # yarn lockfile v1 -"@cspotcode/source-map-consumer@0.8.0": - version "0.8.0" - resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b" - integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg== - -"@cspotcode/source-map-support@0.7.0": - version "0.7.0" - resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5" - integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA== - dependencies: - "@cspotcode/source-map-consumer" "0.8.0" - -"@tsconfig/node10@^1.0.7": - version "1.0.8" - resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9" - integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg== - -"@tsconfig/node12@^1.0.7": - version "1.0.9" - resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c" - integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw== - -"@tsconfig/node14@^1.0.0": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2" - integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg== - -"@tsconfig/node16@^1.0.2": - version "1.0.2" - resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" - integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== - "@types/amqplib@^0.8.2": version "0.8.2" resolved "https://registry.yarnpkg.com/@types/amqplib/-/amqplib-0.8.2.tgz#9c46f2c7fac381e4f81bcb612c00d54549697d22" @@ -52,16 +20,6 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.19.tgz#726171367f404bfbe8512ba608a09ebad810c7e6" integrity sha512-PfeQhvcMR4cPFVuYfBN4ifG7p9c+Dlh3yUZR6k+5yQK7wX3gDgVxBly4/WkBRs9x4dmcy1TVl08SY67wwtEvmA== -acorn-walk@^8.1.1: - version "8.2.0" - resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" - integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA== - -acorn@^8.4.1: - version "8.7.0" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf" - integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ== - amqplib@^0.8.0: version "0.8.0" resolved "https://registry.yarnpkg.com/amqplib/-/amqplib-0.8.0.tgz#088d10bc61cc5ac5a49ac72033c7ac66c23aeb61" @@ -74,11 +32,6 @@ amqplib@^0.8.0: safe-buffer "~5.2.1" url-parse "~1.5.1" -arg@^4.1.0: - version "4.1.3" - resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" - integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== - bitsyntax@~0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/bitsyntax/-/bitsyntax-0.1.0.tgz#b0c59acef03505de5a2ed62a2f763c56ae1d6205" @@ -103,11 +56,6 @@ core-util-is@~1.0.0: resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85" integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ== -create-require@^1.1.0: - version "1.1.1" - resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" - integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== - debug@~2.6.9: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -115,11 +63,6 @@ debug@~2.6.9: dependencies: ms "2.0.0" -diff@^4.0.1: - version "4.0.2" - resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" - integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== - inherits@~2.0.1: version "2.0.4" resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" @@ -130,11 +73,6 @@ isarray@0.0.1: resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8= -make-error@^1.1.1: - version "1.3.6" - resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" - integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== - ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" @@ -180,30 +118,6 @@ string_decoder@~0.10.x: resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" integrity sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ= -ts-node@^10.5.0: - version "10.5.0" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.5.0.tgz#618bef5854c1fbbedf5e31465cbb224a1d524ef9" - integrity sha512-6kEJKwVxAJ35W4akuiysfKwKmjkbYxwQMTBaAxo9KKAx/Yd26mPUyhGz3ji+EsJoAgrLqVsYHNuuYwQe22lbtw== - dependencies: - "@cspotcode/source-map-support" "0.7.0" - "@tsconfig/node10" "^1.0.7" - "@tsconfig/node12" "^1.0.7" - "@tsconfig/node14" "^1.0.0" - "@tsconfig/node16" "^1.0.2" - acorn "^8.4.1" - acorn-walk "^8.1.1" - arg "^4.1.0" - create-require "^1.1.0" - diff "^4.0.1" - make-error "^1.1.1" - v8-compile-cache-lib "^3.0.0" - yn "3.1.1" - -typescript@^4.5.5: - version "4.5.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.5.tgz#d8c953832d28924a9e3d37c73d729c846c5896f3" - integrity sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA== - url-parse@~1.5.1: version "1.5.9" resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.9.tgz#05ff26484a0b5e4040ac64dcee4177223d74675e" @@ -211,13 +125,3 @@ url-parse@~1.5.1: dependencies: querystringify "^2.1.1" requires-port "^1.0.0" - -v8-compile-cache-lib@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz#0582bcb1c74f3a2ee46487ceecf372e46bce53e8" - integrity sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA== - -yn@3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" - integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== diff --git a/tests-ts/src/send-single-message.ts b/tests-ts/src/send-single-message.ts deleted file mode 100644 index 91cb95e..0000000 --- a/tests-ts/src/send-single-message.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {connect} from 'amqplib'; - -(async () => { - const connection = await connect('amqp://localhost'); - - const channel = await connection.createChannel(); - - channel.publish('exchange-1', 'queue-1', Buffer.from('hello')); - - console.log("Hello world!"); -})() diff --git a/tests-ts/tsconfig.json b/tests-ts/tsconfig.json deleted file mode 100644 index 1f2911a..0000000 --- a/tests-ts/tsconfig.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "compilerOptions": { - // "incremental": true, /* Enable incremental compilation */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - - /* Language and Environment */ - "target": "es2017", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - "lib": ["es2021"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - // "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ - // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ - // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - - /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ - // "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "resolveJsonModule": true, /* Enable importing .json files */ - // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ - - /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - - /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ - // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ - // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ - // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - } -} From a7dba0899086434e380bbef86f817473221e6990 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 10 Feb 2022 05:59:35 +0100 Subject: [PATCH 5/6] improve things --- .github/workflows/rust.yml | 4 +- Cargo.lock | 105 ++++++++++++++++++++++++++++++++++++- amqp_transport/src/sasl.rs | 2 +- tests-js/package.json | 3 +- xtask/Cargo.toml | 3 +- xtask/src/codegen/mod.rs | 21 ++++++-- xtask/src/main.rs | 49 +++++++++++------ xtask/src/test_js.rs | 20 +++++++ yarn.lock | 4 ++ 9 files changed, 185 insertions(+), 26 deletions(-) create mode 100644 xtask/src/test_js.rs create mode 100644 yarn.lock diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d422a95..af557e5 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -20,7 +20,7 @@ jobs: uses: creyD/prettier_action@v4.2 with: dry: true - prettier_options: --check **/*.{html,css,js,md} --ignore-path .gitignore + prettier_options: --check amqp_dashboard/assets/* --ignore-path .gitignore - name: Build run: cargo build --verbose - name: Run clippy -D clippy::all @@ -29,3 +29,5 @@ jobs: run: cargo fmt --verbose --all -- --check - name: Run tests run: cargo test --verbose --all + - name: Run client integration tests + run: cargo xtask tests-js diff --git a/Cargo.lock b/Cargo.lock index 82808ea..f07d9c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,10 +213,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "bitflags", - "textwrap", + "textwrap 0.11.0", "unicode-width", ] +[[package]] +name = "clap" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d76c22c9b9b215eeb8d016ad3a90417bd13cb24cf8142756e6472445876cab7" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", + "strsim", + "termcolor", + "textwrap 0.14.2", +] + +[[package]] +name = "clap_derive" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd1122e63869df2cb309f449da1ad54a7c6dfeb7c7e6ccd8e0825d9eb93bb72" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "criterion" version = "0.3.5" @@ -225,7 +255,7 @@ checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" dependencies = [ "atty", "cast", - "clap", + "clap 2.34.0", "criterion-plot", "csv", "itertools", @@ -397,6 +427,12 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + [[package]] name = "heck" version = "0.4.0" @@ -475,6 +511,16 @@ dependencies = [ "want", ] +[[package]] +name = "indexmap" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "itertools" version = "0.10.3" @@ -662,6 +708,15 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +dependencies = [ + "memchr", +] + [[package]] name = "parking_lot" version = "0.12.0" @@ -757,6 +812,30 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.36" @@ -1022,6 +1101,12 @@ dependencies = [ "syn", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" version = "1.0.86" @@ -1039,6 +1124,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -1048,6 +1142,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" + [[package]] name = "thiserror" version = "1.0.30" @@ -1468,6 +1568,7 @@ name = "xtask" version = "0.1.0" dependencies = [ "anyhow", + "clap 3.1.1", "heck", "itertools", "strong-xml", diff --git a/amqp_transport/src/sasl.rs b/amqp_transport/src/sasl.rs index 986dcb0..970d113 100644 --- a/amqp_transport/src/sasl.rs +++ b/amqp_transport/src/sasl.rs @@ -1,6 +1,6 @@ //! (Very) partial implementation of SASL Authentication (see [RFC 4422](https://datatracker.ietf.org/doc/html/rfc4422)) //! -//! Currently only supports PLAN (see [RFC 4616](https://datatracker.ietf.org/doc/html/rfc4616)) +//! Currently only supports PLAIN (see [RFC 4616](https://datatracker.ietf.org/doc/html/rfc4616)) use crate::error::{ConException, Result}; diff --git a/tests-js/package.json b/tests-js/package.json index ccee7e0..4b08626 100644 --- a/tests-js/package.json +++ b/tests-js/package.json @@ -5,7 +5,8 @@ "type": "module", "license": "MIT", "scripts": { - "fmt": "prettier -w ." + "fmt": "prettier -w .", + "test": "echo '✔️ Everything fine!'" }, "dependencies": { "@types/amqplib": "^0.8.2", diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index be38f42..ed4adde 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] anyhow = "1.0.54" +clap = { version = "3.1.1", features = ["derive"] } heck = "0.4.0" itertools = "0.10.3" -strong-xml = "0.6.3" \ No newline at end of file +strong-xml = "0.6.3" diff --git a/xtask/src/codegen/mod.rs b/xtask/src/codegen/mod.rs index f7a0d95..9600df1 100644 --- a/xtask/src/codegen/mod.rs +++ b/xtask/src/codegen/mod.rs @@ -4,13 +4,14 @@ mod parser; mod random; mod write; -use anyhow::Context; +use anyhow::{bail, Context}; use heck::ToUpperCamelCase; use std::fs; use std::fs::File; use std::io::Write; use std::iter::Peekable; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; +use std::process::Command; use std::str::FromStr; use strong_xml::XmlRead; @@ -105,6 +106,15 @@ struct Codegen { output: Box, } +fn fmt(path: &Path) -> anyhow::Result<()> { + println!("Formatting {path:?}..."); + let status = Command::new("rustfmt").arg(path).status()?; + if !status.success() { + bail!("error formatting {path:?}"); + } + Ok(()) +} + pub fn main() -> anyhow::Result<()> { let this_file = PathBuf::from_str(file!()).context("own file path")?; let xtask_root = this_file @@ -125,8 +135,8 @@ pub fn main() -> anyhow::Result<()> { let amqp = Amqp::from_str(&content).context("parse amqp spec file")?; let transport_output = - File::create(transport_generated_path).context("transport output file create")?; - let core_output = File::create(core_generated_path).context("core output file create")?; + File::create(&transport_generated_path).context("transport output file create")?; + let core_output = File::create(&core_generated_path).context("core output file create")?; Codegen { output: Box::new(transport_output), @@ -138,6 +148,9 @@ pub fn main() -> anyhow::Result<()> { } .core_codegen(&amqp); + fmt(&transport_generated_path)?; + fmt(&core_generated_path)?; + Ok(()) } impl Codegen { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index dfdacf5..0430f19 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,24 +1,41 @@ +use std::path::PathBuf; + mod codegen; +mod test_js; + +use clap::{Parser, Subcommand}; + +#[derive(Parser)] +#[clap(author)] +struct Args { + #[clap(subcommand)] + command: Commands, +} + +#[derive(Subcommand)] +enum Commands { + /// Generate method definitions/parser/writer + Generate, + /// Run Javascript integration tests + TestJs, +} fn main() -> anyhow::Result<()> { - let command = std::env::args().nth(1).unwrap_or_else(|| { - eprintln!("Error: No task provided"); - help(); - std::process::exit(1); - }); + let args: Args = Args::parse(); - match command.as_str() { - "generate" | "gen" => codegen::main(), - _ => { - eprintln!("Unknown command {command}."); - Ok(()) - } + match args.command { + Commands::Generate => codegen::main(), + Commands::TestJs => test_js::main(), } } -fn help() { - println!( - "Available tasks: - generate, gen - Generate amqp method code in `amqp_transport/src/methods/generated.rs and amqp_core/src/methods/generated.rs" - ); +pub fn project_root() -> PathBuf { + PathBuf::from(file!()) + .parent() + .expect("src directory path") + .parent() + .expect("xtask root path") + .parent() + .expect("project root path") + .to_path_buf() } diff --git a/xtask/src/test_js.rs b/xtask/src/test_js.rs new file mode 100644 index 0000000..aa41b52 --- /dev/null +++ b/xtask/src/test_js.rs @@ -0,0 +1,20 @@ +use crate::project_root; +use anyhow::{bail, Result}; +use std::process::Command; + +pub fn main() -> Result<()> { + let test_js_root = project_root().join("tests-js"); + let status = Command::new("yarn").current_dir(&test_js_root).status()?; + if !status.success() { + bail!("yarn install failed"); + } + let status = Command::new("yarn") + .arg("test") + .current_dir(&test_js_root) + .status()?; + if !status.success() { + bail!("yarn tests failed"); + } + + Ok(()) +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..fb57ccd --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + From 1cb4e21691f516527e555b47b14b75b391c91076 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 10 Feb 2022 06:55:07 +0100 Subject: [PATCH 6/6] more tests things --- .github/workflows/{rust.yml => ci.yml} | 2 +- amqp_transport/src/lib.rs | 1 - {tests-js => test-js}/.gitignore | 0 {tests-js => test-js}/.prettierrc.json | 0 {tests-js => test-js}/package.json | 2 +- test-js/src/dummy-test.js | 1 + test-js/src/open-channel.js | 15 +++++ test-js/src/send-single-message.js | 14 +++++ {tests-js/src => test-js/src/utils}/utils.js | 0 test-js/test-all.js | 58 ++++++++++++++++++++ {tests-js => test-js}/yarn.lock | 0 tests-js/src/open-channel.js | 17 ------ tests-js/src/send-single-message.js | 16 ------ xtask/src/test_js.rs | 12 ++-- 14 files changed, 98 insertions(+), 40 deletions(-) rename .github/workflows/{rust.yml => ci.yml} (95%) rename {tests-js => test-js}/.gitignore (100%) rename {tests-js => test-js}/.prettierrc.json (100%) rename {tests-js => test-js}/package.json (86%) create mode 100644 test-js/src/dummy-test.js create mode 100644 test-js/src/open-channel.js create mode 100644 test-js/src/send-single-message.js rename {tests-js/src => test-js/src/utils}/utils.js (100%) create mode 100644 test-js/test-all.js rename {tests-js => test-js}/yarn.lock (100%) delete mode 100644 tests-js/src/open-channel.js delete mode 100644 tests-js/src/send-single-message.js diff --git a/.github/workflows/rust.yml b/.github/workflows/ci.yml similarity index 95% rename from .github/workflows/rust.yml rename to .github/workflows/ci.yml index af557e5..f4c72be 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/ci.yml @@ -30,4 +30,4 @@ jobs: - name: Run tests run: cargo test --verbose --all - name: Run client integration tests - run: cargo xtask tests-js + run: cargo xtask test-js diff --git a/amqp_transport/src/lib.rs b/amqp_transport/src/lib.rs index 990217d..2575acc 100644 --- a/amqp_transport/src/lib.rs +++ b/amqp_transport/src/lib.rs @@ -8,7 +8,6 @@ mod sasl; #[cfg(test)] mod tests; - use crate::connection::Connection; use amqp_core::GlobalData; use anyhow::Result; diff --git a/tests-js/.gitignore b/test-js/.gitignore similarity index 100% rename from tests-js/.gitignore rename to test-js/.gitignore diff --git a/tests-js/.prettierrc.json b/test-js/.prettierrc.json similarity index 100% rename from tests-js/.prettierrc.json rename to test-js/.prettierrc.json diff --git a/tests-js/package.json b/test-js/package.json similarity index 86% rename from tests-js/package.json rename to test-js/package.json index 4b08626..a300bce 100644 --- a/tests-js/package.json +++ b/test-js/package.json @@ -6,7 +6,7 @@ "license": "MIT", "scripts": { "fmt": "prettier -w .", - "test": "echo '✔️ Everything fine!'" + "test": "node test-all.js" }, "dependencies": { "@types/amqplib": "^0.8.2", diff --git a/test-js/src/dummy-test.js b/test-js/src/dummy-test.js new file mode 100644 index 0000000..01668bd --- /dev/null +++ b/test-js/src/dummy-test.js @@ -0,0 +1 @@ +console.log('Passed :)'); diff --git a/test-js/src/open-channel.js b/test-js/src/open-channel.js new file mode 100644 index 0000000..b276f62 --- /dev/null +++ b/test-js/src/open-channel.js @@ -0,0 +1,15 @@ +import { connect } from 'amqplib'; +import { sleep } from './utils/utils.js'; + +const connection = await connect('amqp://localhost'); + +const channel = await connection.createChannel(); + +console.log('Successfully opened channel'); + +await sleep(100_000); + +await channel.close(); +await connection.close(); + +console.log('Successfully shut down connection'); diff --git a/test-js/src/send-single-message.js b/test-js/src/send-single-message.js new file mode 100644 index 0000000..f1070d5 --- /dev/null +++ b/test-js/src/send-single-message.js @@ -0,0 +1,14 @@ +import { connect } from 'amqplib'; + +const connection = await connect('amqp://localhost'); + +const channel = await connection.createChannel(); + +channel.publish('exchange-1', 'queue-1', Buffer.from('hello')); + +console.log('Published message'); + +await channel.close(); +await connection.close(); + +console.log('Successfully shut down connection'); diff --git a/tests-js/src/utils.js b/test-js/src/utils/utils.js similarity index 100% rename from tests-js/src/utils.js rename to test-js/src/utils/utils.js diff --git a/test-js/test-all.js b/test-js/test-all.js new file mode 100644 index 0000000..1e7343e --- /dev/null +++ b/test-js/test-all.js @@ -0,0 +1,58 @@ +import * as childProcess from 'child_process'; +import * as fsSync from 'fs'; +import * as fs from 'fs/promises'; +import * as path from 'path'; +import * as url from 'url'; + +const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); + +const srcDir = path.join(__dirname, 'src'); + +const src = await fs.readdir(srcDir); + +const tests = src + .map((test) => [path.join(srcDir, test), test]) + .filter(([testPath]) => { + const stats = fsSync.statSync(testPath); + return !stats.isDirectory(); + }); + +let done = 0; +const successes = []; +const failures = []; + +function maybeDone() { + if (done === tests.length) { + for (const success of successes) { + console.log(`✔️ Test ${success} successful`); + } + for (const { name, stderr } of failures) { + console.log( + `------------------- stderr test ${name} -------------------` + ); + console.log(stderr); + console.log(`------------------- stderr test ${name} ------------------- +❌ Test ${name} failed`); + } + + if (failures.length > 0) { + process.exit(1); + } + } +} + +function runTest(path, name) { + childProcess.exec(`node ${path}`, {}, (error, _, stderr) => { + if (!error) { + successes.push(name); + } else { + failures.push({ name, stderr }); + } + done += 1; + maybeDone(); + }); +} + +for (const [test, name] of tests) { + runTest(test, name); +} diff --git a/tests-js/yarn.lock b/test-js/yarn.lock similarity index 100% rename from tests-js/yarn.lock rename to test-js/yarn.lock diff --git a/tests-js/src/open-channel.js b/tests-js/src/open-channel.js deleted file mode 100644 index 893970a..0000000 --- a/tests-js/src/open-channel.js +++ /dev/null @@ -1,17 +0,0 @@ -import { connect } from 'amqplib'; -import { sleep } from './utils.js'; - -(async () => { - const connection = await connect('amqp://localhost'); - - const channel = await connection.createChannel(); - - console.log('Successfully opened channel'); - - await sleep(100_000); - - await channel.close(); - await connection.close(); - - console.log('Successfully shut down connection'); -})(); diff --git a/tests-js/src/send-single-message.js b/tests-js/src/send-single-message.js deleted file mode 100644 index b84b3db..0000000 --- a/tests-js/src/send-single-message.js +++ /dev/null @@ -1,16 +0,0 @@ -import { connect } from 'amqplib'; - -(async () => { - const connection = await connect('amqp://localhost'); - - const channel = await connection.createChannel(); - - channel.publish('exchange-1', 'queue-1', Buffer.from('hello')); - - console.log('Published message'); - - await channel.close(); - await connection.close(); - - console.log('Successfully shut down connection'); -})(); diff --git a/xtask/src/test_js.rs b/xtask/src/test_js.rs index aa41b52..f61343f 100644 --- a/xtask/src/test_js.rs +++ b/xtask/src/test_js.rs @@ -1,17 +1,21 @@ use crate::project_root; -use anyhow::{bail, Result}; +use anyhow::{bail, Context, Result}; use std::process::Command; pub fn main() -> Result<()> { - let test_js_root = project_root().join("tests-js"); - let status = Command::new("yarn").current_dir(&test_js_root).status()?; + let test_js_root = project_root().join("test-js"); + let status = Command::new("yarn") + .current_dir(&test_js_root) + .status() + .context("yarn install tests")?; if !status.success() { bail!("yarn install failed"); } let status = Command::new("yarn") .arg("test") .current_dir(&test_js_root) - .status()?; + .status() + .context("yarn test tests")?; if !status.success() { bail!("yarn tests failed"); }