make "fountain" test optionally terminate

any characters typed as an argument after "fountain" will cause
it to terminate in 10 iterations
This commit is contained in:
bunnie 2022-05-13 14:50:29 +08:00
parent b470588285
commit 6f1597b1e7

View file

@ -139,7 +139,6 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
let bi = boot_instant.clone(); let bi = boot_instant.clone();
move || { move || {
handle_connection(stream, bi); handle_connection(stream, bi);
log::info!("connection closed");
} }
}); });
} }
@ -150,7 +149,10 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
write!(ret, "TCP listener started on port 80").unwrap(); write!(ret, "TCP listener started on port 80").unwrap();
} }
"fountain" => { "fountain" => {
// anything typed after fountain will cause this to be a short test
let short_test = tokens.next().is_some();
thread::spawn({ thread::spawn({
let short_test = short_test.clone();
move || { move || {
let tp = threadpool::ThreadPool::new(4); let tp = threadpool::ThreadPool::new(4);
loop { loop {
@ -180,7 +182,7 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
_ => {} _ => {}
} }
count += 1; count += 1;
if count == 10 { if count == 10 && short_test {
stream.flush().unwrap(); stream.flush().unwrap();
break; break;
} }
@ -538,7 +540,7 @@ impl Worker {
match message { match message {
Message::NewJob(job) => { Message::NewJob(job) => {
log::info!("Worker {} got a job; executing.", id); log::debug!("Worker {} got a job; executing.", id);
job(); job();
} }