@@ -281,7 +281,45 @@ struct RequestManagerConfig{
281281
282282
283283
284+ std::string random_string (size_t max_length){
285+ size_t length = rand () % max_length;
284286
287+ static const char TABLE[] = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ;
288+
289+ std::string ret;
290+ for (size_t c = 0 ; c < length; c++){
291+ ret += TABLE[rand () % 62 + 48 ];
292+ }
293+ return ret;
294+ }
295+
296+ void stress_test (Logger& logger, CancellableScope& scope){
297+ using namespace std ::chrono_literals;
298+
299+ MockDevice device (GlobalThreadPools::unlimited_normal ());
300+
301+ ReliableStreamConnection connection (
302+ &scope,
303+ logger, true ,
304+ GlobalThreadPools::unlimited_realtime (),
305+ device,
306+ 100ms,
307+ &device.print_lock ()
308+ );
309+
310+ // Connect
311+ connection.reset ();
312+ connection.send_request (PABB2_CONNECTION_OPCODE_ASK_VERSION);
313+ connection.wait_for_pending ();
314+ connection.send_request (PABB2_CONNECTION_OPCODE_ASK_PACKET_SIZE);
315+ connection.wait_for_pending ();
316+ connection.send_request (PABB2_CONNECTION_OPCODE_ASK_BUFFER_SLOTS);
317+ connection.wait_for_pending ();
318+
319+
320+
321+
322+ }
285323
286324
287325
@@ -309,7 +347,7 @@ void TestProgramComputer::program(ProgramEnvironment& env, CancellableScope& sco
309347 logger, true ,
310348 GlobalThreadPools::unlimited_realtime (),
311349 device,
312- 1s ,
350+ 100ms ,
313351 &device.print_lock ()
314352 );
315353
@@ -330,16 +368,35 @@ void TestProgramComputer::program(ProgramEnvironment& env, CancellableScope& sco
330368 connection.send (" zxcv" , 4 ); device.push_expected_stream_data (" zxcv" , 4 );
331369 connection.wait_for_pending ();
332370
333- cout << " sent = " << connection.send (" 0123456789abcdef" , 16 ) << endl;
371+ {
372+ std::lock_guard<Mutex> lg (device.print_lock ());
373+ cout << " sent = " << connection.send (" 0123456789abcdef" , 16 ) << endl;
374+ }
375+ device.push_expected_stream_data (" 0123456789abcdef" , 16 );
334376// connection.send("0123456789abcdef", 16);
335377// connection.send("0123456789abcdef", 16);
336378// connection.send("0123456789abcdef", 16);
337379
338- connection.print ();
339- device. print ();
380+ while ( connection.pending () != 0 || device. verify_stream_data ()){
381+ }
340382
341383 connection.wait_for_pending ();
342384
385+ {
386+ std::lock_guard<Mutex> lg (device.print_lock ());
387+ cout << " ============> Done" << endl;
388+ }
389+ device.verify_stream_data ();
390+
391+ connection.print ();
392+ device.print ();
393+
394+ {
395+ std::lock_guard<Mutex> lg (device.print_lock ());
396+ cout << " ============> Finishing up" << endl;
397+ }
398+ scope.wait_for (5s);
399+ device.verify_stream_data ();
343400
344401 scope.wait_for (60s);
345402 }
0 commit comments