diff options
Diffstat (limited to 'src/test.cpp')
-rw-r--r-- | src/test.cpp | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/src/test.cpp b/src/test.cpp index 6b9ef4b6f..c1f04b2ef 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -819,7 +819,10 @@ struct TestConnection /* Test some real connections + + NOTE: This mostly tests the legacy interface. */ + u32 proto_id = 0xad26846a; Handler hand_server("server"); @@ -843,11 +846,30 @@ struct TestConnection sleep_ms(50); + // Client should not have added client yet + assert(hand_client.count == 0); + + try + { + u16 peer_id; + u8 data[100]; + infostream<<"** running client.Receive()"<<std::endl; + u32 size = client.Receive(peer_id, data, 100); + infostream<<"** Client received: peer_id="<<peer_id + <<", size="<<size + <<std::endl; + } + catch(con::NoIncomingDataException &e) + { + } + // Client should have added server now assert(hand_client.count == 1); assert(hand_client.last_id == 1); - // But server should not have added client + // Server should not have added client yet assert(hand_server.count == 0); + + sleep_ms(50); try { @@ -930,7 +952,7 @@ struct TestConnection } u16 peer_id_client = 2; - +#if 0 { /* Send consequent packets in different order @@ -941,13 +963,13 @@ struct TestConnection SharedBuffer<u8> data2 = SharedBufferFromString("Hello2"); Address client_address = - server.GetPeer(peer_id_client)->address; + server.GetPeerAddress(peer_id_client); infostream<<"*** Sending packets in wrong order (2,1,2)" <<std::endl; u8 chn = 0; - con::Channel *ch = &server.GetPeer(peer_id_client)->channels[chn]; + con::Channel *ch = &server.getPeer(peer_id_client)->channels[chn]; u16 sn = ch->next_outgoing_seqnum; ch->next_outgoing_seqnum = sn+1; server.Send(peer_id_client, chn, data2, true); @@ -1004,6 +1026,7 @@ struct TestConnection } assert(got_exception); } +#endif { const int datasize = 30000; SharedBuffer<u8> data1(datasize); @@ -1022,12 +1045,25 @@ struct TestConnection server.Send(peer_id_client, 0, data1, true); - sleep_ms(50); + sleep_ms(3000); u8 recvdata[datasize + 1000]; infostream<<"** running client.Receive()"<<std::endl; u16 peer_id = 132; - u16 size = client.Receive(peer_id, recvdata, datasize + 1000); + u16 size = 0; + bool received = false; + u32 timems0 = porting::getTimeMs(); + for(;;){ + if(porting::getTimeMs() - timems0 > 5000) + break; + try{ + size = client.Receive(peer_id, recvdata, datasize + 1000); + received = true; + }catch(con::NoIncomingDataException &e){ + } + sleep_ms(10); + } + assert(received); infostream<<"** Client received: peer_id="<<peer_id <<", size="<<size <<std::endl; |