Skip to content

Commit af2d37f

Browse files
committed
refactor(test_runner): define the default timeout in one place
1 parent f9be42c commit af2d37f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/r3_test_runner/src/targets/rp_pico.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,22 @@ async fn program_and_run_by_picoboot(exe: &std::path::Path) -> Result<()> {
132132
Ok(())
133133
}
134134

135+
const DEFAULE_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(5);
136+
135137
async fn write_bulk_all(
136138
device_handle: rusb::DeviceHandle<rusb::GlobalContext>,
137139
endpoint: u8,
138140
buf: &[u8],
139141
) -> (rusb::Result<usize>, rusb::DeviceHandle<rusb::GlobalContext>) {
140142
let buf = buf.to_owned(); // sigh
141143
spawn_blocking(move || {
142-
let timeout = std::time::Duration::from_secs(5);
143144
let mut buf = &buf[..];
144145
let mut num_bytes_written = 0;
145146

146147
log::trace!("write_bulk_all({})", endpoint);
147148

148149
while buf.len() > 0 {
149-
match device_handle.write_bulk(endpoint, buf, timeout) {
150+
match device_handle.write_bulk(endpoint, buf, DEFAULE_TIMEOUT) {
150151
Ok(0) => break,
151152
Ok(num_bytes) => {
152153
num_bytes_written += num_bytes;
@@ -167,11 +168,9 @@ async fn read_bulk_empty(
167168
endpoint: u8,
168169
) -> (rusb::Result<()>, rusb::DeviceHandle<rusb::GlobalContext>) {
169170
spawn_blocking(move || {
170-
let timeout = std::time::Duration::from_secs(5);
171-
172171
log::trace!("read_bulk_empty({})", endpoint);
173172

174-
let result = match device_handle.read_bulk(endpoint, &mut [], timeout) {
173+
let result = match device_handle.read_bulk(endpoint, &mut [], DEFAULE_TIMEOUT) {
175174
Ok(0) => Ok(()),
176175
Ok(_) => unreachable!(),
177176
Err(e) => Err(e),

0 commit comments

Comments
 (0)