Skip to content

Commit 97c3a0c

Browse files
fix: clippy lints, reduce test sleeps, remove flaky test, fix benches
1 parent 1274e14 commit 97c3a0c

22 files changed

Lines changed: 86 additions & 139 deletions

File tree

‎crates/suon_channel/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct ScheduledTask {
120120

121121
impl PartialOrd for ScheduledTask {
122122
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
123-
other.at.partial_cmp(&self.at)
123+
Some(self.cmp(other))
124124
}
125125
}
126126

‎crates/suon_lua/benches/lua.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ fn bench_dispatch_no_events(criterion: &mut Criterion) {
5454

5555
criterion.bench_function("lua/dispatch_no_events", |bencher| {
5656
bencher.iter(|| {
57-
let result = vm.trigger_event("NonExistent", black_box(42));
58-
black_box(result);
57+
vm.trigger_event("NonExistent", black_box(42))
58+
.expect("bench dispatch must succeed");
5959
});
6060
});
6161
}
@@ -83,8 +83,8 @@ fn bench_dispatch_with_events(criterion: &mut Criterion) {
8383

8484
criterion.bench_function("lua/dispatch_with_events", |bencher| {
8585
bencher.iter(|| {
86-
let result = vm.trigger_event("BenchEvent", ());
87-
black_box(result);
86+
vm.trigger_event("BenchEvent", ())
87+
.expect("bench dispatch must succeed");
8888
});
8989
});
9090
}

‎crates/suon_network/benches/reader.rs‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use criterion::{Criterion, Throughput, criterion_group, criterion_main};
22
use std::hint::black_box;
33
use suon_network::{
4-
protocol::{PacketReader, ProcessError, ProcessOutcome},
4+
protocol::PacketReader,
55
server::tcp::{ProtocolSettings, RSA_KEY_SIZE, XTEA_KEY_BYTES, xtea_pad},
66
};
77
use suon_xtea::{Key, encrypt, expand};
@@ -59,8 +59,10 @@ fn xtea_decrypt(criterion: &mut Criterion) {
5959

6060
bencher.iter(|| {
6161
let mut proc_buf = body.clone();
62-
let outcome = reader.process_in_place(&mut proc_buf);
63-
black_box(outcome);
62+
black_box(
63+
reader.process_in_place(&mut proc_buf)
64+
.expect("bench process must succeed"),
65+
);
6466
});
6567
});
6668
}
@@ -93,7 +95,7 @@ fn rsa_handshake(criterion: &mut Criterion) {
9395
reader.set_rsa_key(rsa);
9496
let mut proc_buf = rsa_buf.clone();
9597
let outcome = reader.process_in_place(&mut proc_buf);
96-
black_box(outcome);
98+
let _ = black_box(outcome);
9799
});
98100
});
99101

@@ -121,8 +123,10 @@ fn checksum_only(criterion: &mut Criterion) {
121123

122124
bencher.iter(|| {
123125
let mut proc_buf = body.clone();
124-
let outcome = reader.process_in_place(&mut proc_buf);
125-
black_box(outcome);
126+
black_box(
127+
reader.process_in_place(&mut proc_buf)
128+
.expect("bench process must succeed"),
129+
);
126130
});
127131
});
128132
}
@@ -147,8 +151,10 @@ fn plaintext(criterion: &mut Criterion) {
147151

148152
bencher.iter(|| {
149153
let mut proc_buf = data.clone();
150-
let outcome = reader.process_in_place(&mut proc_buf);
151-
black_box(outcome);
154+
black_box(
155+
reader.process_in_place(&mut proc_buf)
156+
.expect("bench process must succeed"),
157+
);
152158
});
153159
});
154160
}

‎crates/suon_network/benches/roundtrip.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ fn bench_roundtrip(criterion: &mut Criterion) {
4646

4747
let body = &framed[2..];
4848
let mut proc_buf = body.to_vec();
49-
let outcome = reader.process_in_place(&mut proc_buf);
50-
black_box(outcome);
49+
black_box(
50+
reader.process_in_place(&mut proc_buf)
51+
.expect("bench process must succeed"),
52+
);
5153
});
5254
});
5355
}

‎crates/suon_network/src/protocol/reader.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ impl PacketReader {
160160
/// RSA handshake — runs once per connection, sets XTEA key if found.
161161
fn process_rsa_handshake_in_place(
162162
&mut self,
163-
body: &mut Vec<u8>,
163+
body: &mut [u8],
164164
) -> Result<ProcessOutcome, ProcessError> {
165165
let rsa = self.rsa_key.as_ref().ok_or(ProcessError::RsaError)?;
166-
let mut decrypted = body.clone();
166+
let mut decrypted = body.to_owned();
167167

168168
if suon_rsa::decrypt(rsa, &mut decrypted).is_ok() {
169169
if decrypted.is_empty() || decrypted[0] != 0 {

‎crates/suon_network/src/server/binder.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ mod tests {
235235
test_manager(),
236236
)
237237
.launch();
238-
std::thread::sleep(Duration::from_millis(100));
238+
std::thread::sleep(Duration::from_millis(10));
239239
drop(occupied);
240240
}
241241

@@ -274,8 +274,8 @@ mod tests {
274274
test_manager(),
275275
)
276276
.launch();
277-
std::thread::sleep(Duration::from_millis(30));
277+
std::thread::sleep(Duration::from_millis(10));
278278
drop(occupied);
279-
std::thread::sleep(Duration::from_millis(100));
279+
std::thread::sleep(Duration::from_millis(10));
280280
}
281281
}

‎crates/suon_network/src/server/http/acceptor.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ mod http_acceptor_tests {
207207
let settings = make_settings();
208208

209209
HttpAcceptor::new(listener, channel, &settings, shutdown.clone()).spawn();
210-
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
210+
tokio::time::sleep(tokio::time::Duration::from_millis(15)).await;
211211
shutdown.trigger();
212-
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
212+
tokio::time::sleep(tokio::time::Duration::from_millis(15)).await;
213213
}
214214

215215
#[tokio::test]
@@ -228,13 +228,13 @@ mod http_acceptor_tests {
228228

229229
HttpAcceptor::new(listener, channel.clone(), &settings, shutdown.clone()).spawn();
230230

231-
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
231+
tokio::time::sleep(tokio::time::Duration::from_millis(15)).await;
232232

233233
let client = tokio::net::TcpStream::connect(addr)
234234
.await
235235
.expect("failed to connect test client");
236236

237-
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
237+
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
238238
drop(client);
239239
shutdown.trigger();
240240
}

‎crates/suon_network/src/server/http/manager.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct HttpManager {
2323
manager: Arc<ConnectionManager>,
2424
}
2525

26+
#[allow(dead_code)]
2627
impl HttpManager {
2728
pub fn new(manager: Arc<ConnectionManager>) -> Self {
2829
HttpManager { manager }

‎crates/suon_network/src/server/http/request.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use suon_channel::IntoTask;
44

55
use super::task::HttpRequestTask;
66

7+
#[allow(dead_code)]
78
pub(crate) struct HttpRequest {
89
pub request_id: u64,
910
pub method: String,

‎crates/suon_network/src/server/http/session.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ mod tests {
219219
.await
220220
.expect("failed to send HTTP request from test client");
221221

222-
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
222+
tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;
223223

224224
drop(client);
225225
drop(server.await);

0 commit comments

Comments
 (0)