Skip to content

Commit d82209c

Browse files
committed
address clippy concern about holding a sync mutex lock across an await boundary
1 parent 234a4f0 commit d82209c

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

tests/common/mod.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
use async_dup::{Arc, Mutex};
12
use async_std::fs::File;
23
use async_std::io::{self, Read, SeekFrom, Write};
34
use async_std::path::PathBuf;
4-
use async_std::sync::Arc;
5+
use async_std::prelude::*;
56
use async_std::task::{Context, Poll};
67
use std::pin::Pin;
7-
use std::sync::Mutex;
88

99
#[derive(Debug, Copy, Clone)]
1010
#[allow(dead_code)]
@@ -72,30 +72,25 @@ impl TestCase {
7272
}
7373

7474
#[allow(dead_code)]
75-
pub async fn read_result(&self) -> String {
76-
use async_std::prelude::*;
75+
pub async fn read_result(&mut self) -> String {
7776
let mut result = String::new();
78-
let mut file = self.result.lock().unwrap();
79-
file.seek(SeekFrom::Start(0)).await.unwrap();
80-
file.read_to_string(&mut result).await.unwrap();
77+
self.result.seek(SeekFrom::Start(0)).await.unwrap();
78+
self.result.read_to_string(&mut result).await.unwrap();
8179
result
8280
}
8381

8482
#[allow(dead_code)]
85-
pub async fn read_expected(&self) -> String {
86-
use async_std::prelude::*;
83+
pub async fn read_expected(&mut self) -> String {
8784
let mut expected = std::string::String::new();
8885
self.expected_fixture
89-
.lock()
90-
.unwrap()
9186
.read_to_string(&mut expected)
9287
.await
9388
.unwrap();
9489
expected
9590
}
9691

9792
#[allow(dead_code)]
98-
pub(crate) async fn assert(self) {
93+
pub(crate) async fn assert(mut self) {
9994
let mut actual = self.read_result().await;
10095
let mut expected = self.read_expected().await;
10196
assert!(!actual.is_empty(), "Received empty reply");
@@ -138,14 +133,14 @@ impl Read for TestCase {
138133

139134
impl Write for TestCase {
140135
fn poll_write(self: Pin<&mut Self>, cx: &mut Context, buf: &[u8]) -> Poll<io::Result<usize>> {
141-
Pin::new(&mut &*self.result.lock().unwrap()).poll_write(cx, buf)
136+
Pin::new(&mut &*self.result).poll_write(cx, buf)
142137
}
143138

144139
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> {
145-
Pin::new(&mut &*self.result.lock().unwrap()).poll_flush(cx)
140+
Pin::new(&mut &*self.result).poll_flush(cx)
146141
}
147142

148143
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> {
149-
Pin::new(&mut &*self.result.lock().unwrap()).poll_close(cx)
144+
Pin::new(&mut &*self.result).poll_close(cx)
150145
}
151146
}

tests/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ async fn test_unexpected_eof() {
122122

123123
#[async_std::test]
124124
async fn test_invalid_trailer() {
125-
let case = TestCase::new_server(
125+
let mut case = TestCase::new_server(
126126
"fixtures/request-invalid-trailer.txt",
127127
"fixtures/response-invalid-trailer.txt",
128128
)

0 commit comments

Comments
 (0)