Skip to content

Commit 553498b

Browse files
committed
Added async-test.
Test if this works on GHA
1 parent e884da1 commit 553498b

File tree

4 files changed

+25
-47
lines changed

4 files changed

+25
-47
lines changed

.github/workflows/pr.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ jobs:
5656
command: build
5757
args: --release --all
5858

59-
# - name: Cargo test
60-
# if: matrix.rust == 'stable'
61-
# uses: actions-rs/cargo@v1
62-
# with:
63-
# command: test
64-
# args: --release --all -- --test-threads=1
59+
- name: Cargo test
60+
if: matrix.rust == 'stable'
61+
uses: actions-rs/cargo@v1
62+
with:
63+
command: test
64+
args: --release --all -- --test-threads=1
6565

6666
- name: Cargo fmt
6767
uses: actions-rs/cargo@v1

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ async-trait = "0.1.24"
1616
futures = "0.3.4"
1717
futures-util = "0.3.4"
1818

19+
[dev-dependencies]
20+
async-std = { version = "1", features = ["attributes"] }
21+
1922
[profile.release]
2023
lto = true
2124
panic = 'abort'

src/juno_module.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ impl JunoModule {
198198
if *self.registered.read().await || request_type == 1 {
199199
self.connection.send(encoded).await;
200200
} else {
201-
self.message_buffer
202-
.write()
203-
.await
204-
.append(&mut encoded);
201+
self.message_buffer.write().await.append(&mut encoded);
205202
}
206203

207204
let (sender, receiver) = channel::<Result<Value>>();
@@ -255,7 +252,14 @@ async fn on_data_listener(
255252
Ok(Value::Null)
256253
}
257254
BaseMessage::TriggerHookResponse { .. } => {
258-
execute_hook_triggered(message, &message_buffer, &write_sender, &registered_store, &hook_listeners).await
255+
execute_hook_triggered(
256+
message,
257+
&message_buffer,
258+
&write_sender,
259+
&registered_store,
260+
&hook_listeners,
261+
)
262+
.await
259263
}
260264
BaseMessage::Error { error, .. } => Err(Error::FromJuno(error)),
261265
_ => Ok(Value::Null),

tests/connection/unix_socket_connection.rs

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ fn connection_object_should_create_successfully() {
88
let _socket_connection = UnixSocketConnection::new(String::from("socket_path"));
99
}
1010

11-
#[test]
12-
fn should_connect() -> Result<()> {
13-
task::block_on(should_connect_async())
14-
}
15-
11+
#[async_std::test]
1612
async fn should_connect_async() -> Result<()> {
1713
// Setup to try and connect to socket server
1814
let mut connection = UnixSocketConnection::new(String::from("./temp-1.sock"));
@@ -30,11 +26,7 @@ async fn should_connect_async() -> Result<()> {
3026
Ok(())
3127
}
3228

33-
#[test]
34-
fn should_connect_and_send_data() -> Result<()> {
35-
task::block_on(should_connect_and_send_data_async())
36-
}
37-
29+
#[async_std::test]
3830
async fn should_connect_and_send_data_async() -> Result<()> {
3931
// Setup to try and connect to socket server
4032
let mut connection = UnixSocketConnection::new(String::from("./temp-2.sock"));
@@ -62,11 +54,7 @@ async fn should_connect_and_send_data_async() -> Result<()> {
6254
Ok(())
6355
}
6456

65-
#[test]
66-
fn should_connect_and_read_data() -> Result<()> {
67-
task::block_on(should_connect_and_read_data_async())
68-
}
69-
57+
#[async_std::test]
7058
async fn should_connect_and_read_data_async() -> Result<()> {
7159
// Setup to try and connect to socket server
7260
let mut connection = UnixSocketConnection::new(String::from("./temp-3.sock"));
@@ -96,11 +84,7 @@ async fn should_connect_and_read_data_async() -> Result<()> {
9684
Ok(())
9785
}
9886

99-
#[test]
100-
fn should_connect_and_send_data_from_cloned_sender() -> Result<()> {
101-
task::block_on(should_connect_and_send_data_from_cloned_sender_async())
102-
}
103-
87+
#[async_std::test]
10488
async fn should_connect_and_send_data_from_cloned_sender_async() -> Result<()> {
10589
// Setup to try and connect to socket server
10690
let mut connection = UnixSocketConnection::new(String::from("./temp-4.sock"));
@@ -159,31 +143,18 @@ fn should_clone_write_sender_without_setup_and_panic() {
159143
connection.clone_write_sender();
160144
}
161145

162-
/*
163-
#[test]
146+
#[async_std::test]
164147
#[should_panic]
165-
fn should_setup_connection_twice_and_panic() {
166-
let handle = std::thread::spawn(|| {
167-
task::block_on(should_setup_connection_twice_and_panic_async()).unwrap();
168-
})
169-
.join();
170-
task::block_on(remove_file("./temp-5.sock")).unwrap();
171-
handle.unwrap();
172-
}
173-
174-
async fn should_setup_connection_twice_and_panic_async() -> Result<()> {
148+
async fn should_setup_connection_twice_and_panic_async() {
175149
// Setup to try and connect to socket server
176150
let mut connection = UnixSocketConnection::new(String::from("./temp-5.sock"));
177151

178152
// Listen for unix socket connections
179-
let socket = UnixListener::bind("./temp-5.sock").await?;
153+
let socket = UnixListener::bind("./temp-5.sock").await.unwrap();
180154
let mut incoming = socket.incoming();
181155
let (_stream, result) = future::join(incoming.next(), connection.setup_connection()).await;
182156
result.unwrap();
183157
let (_, result) = future::join(incoming.next(), connection.setup_connection()).await;
184158
result.unwrap();
185159
drop(socket);
186-
187-
Ok(())
188160
}
189-
*/

0 commit comments

Comments
 (0)