Skip to content

Commit

Permalink
add test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
b23r0 committed Aug 27, 2022
1 parent 7d9e459 commit e2fd4b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async fn serve(){
let mut listener = RaknetListener::bind("127.0.0.1:19132".parse().unwrap()).await.unwrap();
listener.listen().await;
loop{
let mut socket = listener.accept().await.unwrap();
let socket = listener.accept().await.unwrap();
let buf = socket.recv().await.unwrap();
if buf[0] == 0xfe{
//do something
Expand All @@ -65,7 +65,7 @@ async fn serve(){
//client

async fn connect(){
let mut socket = RaknetSocket::connect("127.0.0.1:19132".parse().unwrap()).await.unwrap();
let socket = RaknetSocket::connect("127.0.0.1:19132".parse().unwrap()).await.unwrap();
socket.send(&[0xfe], Reliability::ReliableOrdered).await.unwrap();
let buf = socket.recv().await.unwrap();
if buf[0] == 0xfe{
Expand Down Expand Up @@ -99,4 +99,4 @@ Options :
* Add an example of using rust-raknet
* Supplement the documentation on using rust-raknet

This project exists thanks to all the people who contribute.
Everyone for me, I for everyone.
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,31 @@ async fn test_raknet_server_close(){
server2.listen().await;

}

#[tokio::test]
async fn test_send_recv_full_packet(){
let mut server = RaknetListener::bind(&"127.0.0.1:0".parse().unwrap()).await.unwrap();
let remote_addr = format!("127.0.0.1:{}", server.local_addr().unwrap().port());
tokio::spawn(async move {
server.listen().await;
let client = server.accept().await.unwrap();

for _ in 0..50{
client.send(&vec![0xfe;1000], Reliability::ReliableSequenced).await.unwrap();
}

client.close().await.unwrap();
server.close().await.unwrap();
});

let client = RaknetSocket::connect(&remote_addr.parse().unwrap()).await.unwrap();

for _ in 0..50{
let buf = client.recv().await.unwrap();
assert!(buf == [0xfe;1000]);
}
}

/*
#[tokio::test]
async fn chore2(){
Expand Down

0 comments on commit e2fd4b9

Please sign in to comment.