first test passes uwu

This commit is contained in:
nora 2022-02-22 13:15:59 +01:00
parent 6f5fef2f23
commit 9a819bc3f4
7 changed files with 30 additions and 24 deletions

View file

@ -257,8 +257,15 @@ impl Connection {
debug!(?method, "Received method"); debug!(?method, "Received method");
match method { match method {
Method::ConnectionClose { .. } => { Method::ConnectionClose {
// todo: handle closing reply_code,
reply_text,
class_id,
method_id,
} => {
info!(%reply_code, %reply_text, %class_id, %method_id, "Closing connection");
self.send_method(0, Method::ConnectionCloseOk {}).await?;
return Err(ProtocolError::GracefulClose.into());
} }
Method::ChannelOpen { .. } => self.channel_open(frame.channel).await?, Method::ChannelOpen { .. } => self.channel_open(frame.channel).await?,
Method::ChannelClose { .. } => self.channel_close(frame.channel, method).await?, Method::ChannelClose { .. } => self.channel_close(frame.channel, method).await?,

View file

@ -209,9 +209,6 @@ pub mod parse {
let (input, _) = tag(31_u16.to_be_bytes())(input)?; let (input, _) = tag(31_u16.to_be_bytes())(input)?;
let (input, channel_max) = let (input, channel_max) =
domain_short(input).map_err(fail_err("field channel-max in method tune-ok"))?; domain_short(input).map_err(fail_err("field channel-max in method tune-ok"))?;
if channel_max == 0 {
fail!("number was 0 for field channel_max")
}
let (input, frame_max) = let (input, frame_max) =
domain_long(input).map_err(fail_err("field frame-max in method tune-ok"))?; domain_long(input).map_err(fail_err("field frame-max in method tune-ok"))?;
let (input, heartbeat) = let (input, heartbeat) =

View file

@ -6,7 +6,7 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"fmt": "prettier -w .", "fmt": "prettier -w .",
"test": "node test-all.js" "test": "prettier -c . && node test-all.js"
}, },
"dependencies": { "dependencies": {
"@types/amqplib": "^0.8.2", "@types/amqplib": "^0.8.2",

View file

@ -1,4 +1,4 @@
import {connectAmqp, sleep} from './utils/utils.js'; import { connectAmqp, sleep } from './utils/utils.js';
const connection = await connectAmqp(); const connection = await connectAmqp();
@ -6,8 +6,6 @@ const channel = await connection.createChannel();
console.log('Successfully opened channel'); console.log('Successfully opened channel');
await sleep(100_000);
await channel.close(); await channel.close();
await connection.close(); await connection.close();

View file

@ -1,4 +1,4 @@
import {connectAmqp} from "./utils/utils.js"; import { connectAmqp } from './utils/utils.js';
const connection = await connectAmqp(); const connection = await connectAmqp();

View file

@ -1,17 +1,18 @@
import {connect} from "amqplib"; import { connect } from 'amqplib';
export const sleep = (ms) => new Promise((res) => setTimeout(res, ms)); export const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
export const connectAmqp = async () => { export const connectAmqp = async () => {
return connect({ return connect(
protocol: 'amqp', {
hostname: 'localhost', protocol: 'amqp',
port: 5672, hostname: 'localhost',
username: 'admin', port: 5672,
password: '', username: 'admin',
frameMax: 238556565673829, password: '',
}, { frameMax: 0,
channelMax: 1000,
}); },
} {}
);
};

View file

@ -176,11 +176,14 @@ pub type IResult<'a, T> = nom::IResult<&'a [u8], T, TransError>;
).ok(); ).ok();
} }
"short" => { "short" => {
writeln!( // todo https://github.com/amqp-node/amqplib/issues/672
if var_name != "channel_max" {
writeln!(
self.output, self.output,
r#" if {var_name} == 0 {{ fail!("number was 0 for field {var_name}") }}"# r#" if {var_name} == 0 {{ fail!("number was 0 for field {var_name}") }}"#
) )
.ok(); .ok();
}
} }
_ => unimplemented!(), _ => unimplemented!(),
}, },