MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / msgpack_request_gets_msgpack_response

Function msgpack_request_gets_msgpack_response

nodedb/tests/native_protocol.rs:462–499  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

460/// the server responds with a MsgPack-encoded response.
461#[tokio::test]
462async fn msgpack_request_gets_msgpack_response() {
463 let server = NativeTestServer::start().await;
464
465 let (mut stream, _ack) = do_handshake(server.addr, &HelloFrame::current())
466 .await
467 .expect("handshake");
468
469 let req = NativeRequest {
470 op: OpCode::Ping,
471 seq: 99,
472 fields: RequestFields::Text(TextFields::default()),
473 };
474 let mp_bytes = zerompk::to_msgpack_vec(&req).expect("msgpack encode");
475 assert_ne!(mp_bytes[0], b'{', "MsgPack must NOT start with open brace");
476
477 write_frame(&mut stream, &mp_bytes).await;
478
479 let response_payload = tokio::time::timeout(Duration::from_secs(5), read_frame(&mut stream))
480 .await
481 .expect("timeout")
482 .expect("response");
483
484 server.shutdown().await;
485
486 // Response must NOT start with `{` (it is MsgPack).
487 assert_ne!(
488 response_payload[0], b'{',
489 "MsgPack session must produce MsgPack response, got first byte 0x{:02X}",
490 response_payload[0]
491 );
492 let resp: NativeResponse = zerompk::from_msgpack(&response_payload).expect("msgpack decode");
493 assert_eq!(resp.seq, 99, "seq must echo");
494 assert_eq!(
495 resp.status,
496 nodedb_types::protocol::opcodes::ResponseStatus::Ok,
497 "Ping must return Ok"
498 );
499}
500
501/// Mid-session encoding switch: if a JSON session receives a MsgPack frame (or
502/// vice versa), the server must NOT silently accept it. It must return an error

Callers

nothing calls this directly

Calls 6

do_handshakeFunction · 0.85
currentFunction · 0.85
write_frameFunction · 0.70
read_frameFunction · 0.70
expectMethod · 0.45
shutdownMethod · 0.45

Tested by

no test coverage detected