Skip to content

Commit 747b186

Browse files
committed
Merge branch 'tim/maint' into 'master'
Upgrade to Tokio 1.3 See merge request TankerHQ/sdk-rust!26
2 parents c14ab83 + 206bf13 commit 747b186

File tree

7 files changed

+48
-47
lines changed

7 files changed

+48
-47
lines changed

Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ include = ["native", "src", "tests", "build.rs"]
1111
futures = "0.3"
1212
num_enum = "0.5"
1313
lazy_static = "1.4"
14-
tokio = { version = "0.2", features = ["sync"] }
14+
tokio = { version = "1.3", features = ["sync"] }
15+
# Tokio's mpsc::sync channel has a bug in try_recv(), in the meantime we use async_channel
16+
async-channel = "1.6.1"
1517

1618
[dev-dependencies]
17-
tokio = { version = "0.2", features = ["macros", "rt-threaded"] }
18-
reqwest = { version = "0.10.8", features = ["json"] }
19+
tokio = { version = "1.3", features = ["macros", "rt-multi-thread"] }
20+
reqwest = { version = "0.11", features = ["json"] }
1921
openssl = { version = "0.10", features = ["vendored"] }
2022
serde_json = "1.0"
2123
double-checked-cell-async = "2.0.2"
2224
rand = "0.7.3"
23-
base64 = "0.12"
25+
base64 = "0.13"
2426
variant_count = "1.0"
2527
blake2 = "0.9"
2628
ed25519-dalek = "1.0"

src/ctanker/cstream.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::ctanker::*;
2525
use crate::error::Error;
2626

2727
use ::core::pin::Pin;
28+
use async_channel::{bounded, Receiver, Sender, TryRecvError};
2829
use futures::executor::block_on;
2930
use futures::future::{select, Either};
3031
use futures::io::{AsyncRead, AsyncReadExt};
@@ -34,8 +35,6 @@ use futures::FutureExt;
3435
use std::cmp::min;
3536
use std::future::Future;
3637
use std::sync::Mutex;
37-
use tokio::sync::mpsc::error::TryRecvError;
38-
use tokio::sync::mpsc::{channel, Receiver, Sender};
3938

4039
#[derive(Debug, Clone)]
4140
struct ReadOperation {
@@ -64,7 +63,7 @@ struct TankerStream<UserStream: AsyncRead + Unpin> {
6463

6564
impl<UserStream: AsyncRead + Unpin> TankerStream<UserStream> {
6665
fn new() -> Self {
67-
let (sender, receiver) = channel(1);
66+
let (sender, receiver) = bounded(1);
6867
TankerStream {
6968
user_stream: None,
7069
tanker_stream_handle: std::ptr::null_mut(),
@@ -184,10 +183,10 @@ impl<UserStream: AsyncRead + Unpin> AsyncRead for TankerStream<UserStream> {
184183
);
185184
self.read_operation = Some(read_operation);
186185
}
187-
Err(TryRecvError::Empty) => {} // No work to do
188-
Err(e) => {
189-
panic!("error reading channel: {}", e);
186+
Err(TryRecvError::Closed) => {
187+
panic!("error reading channel: closed");
190188
}
189+
Err(TryRecvError::Empty) => {} // Channel still open, but no message
191190
}
192191

193192
// Process the ReadOperation if there is one in progress

tests/encryption_session_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use futures::AsyncReadExt;
44
use identity::TestApp;
55
use tankersdk::*;
66

7-
#[tokio::test(threaded_scheduler)]
7+
#[tokio::test(flavor = "multi_thread")]
88
async fn open_close_enc_sess() -> Result<(), Error> {
99
let app = TestApp::get().await;
1010
let tanker = app.start_anonymous(&app.create_identity(None)).await?;
@@ -16,7 +16,7 @@ async fn open_close_enc_sess() -> Result<(), Error> {
1616
Ok(())
1717
}
1818

19-
#[tokio::test(threaded_scheduler)]
19+
#[tokio::test(flavor = "multi_thread")]
2020
async fn share_with_enc_sess() -> Result<(), Error> {
2121
let app = TestApp::get().await;
2222
let alice = app.start_anonymous(&app.create_identity(None)).await?;
@@ -32,7 +32,7 @@ async fn share_with_enc_sess() -> Result<(), Error> {
3232
Ok(())
3333
}
3434

35-
#[tokio::test(threaded_scheduler)]
35+
#[tokio::test(flavor = "multi_thread")]
3636
async fn encrypt_stream_with_enc_sess() -> Result<(), Error> {
3737
let app = TestApp::get().await;
3838
let alice = app.start_anonymous(&app.create_identity(None)).await?;
@@ -52,7 +52,7 @@ async fn encrypt_stream_with_enc_sess() -> Result<(), Error> {
5252
Ok(())
5353
}
5454

55-
#[tokio::test(threaded_scheduler)]
55+
#[tokio::test(flavor = "multi_thread")]
5656
async fn resource_id_of_enc_sess_matches_ciphertext() -> Result<(), Error> {
5757
let app = TestApp::get().await;
5858
let tanker = app.start_anonymous(&app.create_identity(None)).await?;
@@ -67,7 +67,7 @@ async fn resource_id_of_enc_sess_matches_ciphertext() -> Result<(), Error> {
6767
Ok(())
6868
}
6969

70-
#[tokio::test(threaded_scheduler)]
70+
#[tokio::test(flavor = "multi_thread")]
7171
async fn resource_id_of_different_enc_sess_are_different() -> Result<(), Error> {
7272
let app = TestApp::get().await;
7373
let alice = app.start_anonymous(&app.create_identity(None)).await?;

tests/group_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use identity::TestApp;
44
use std::iter;
55
use tankersdk::*;
66

7-
#[tokio::test(threaded_scheduler)]
7+
#[tokio::test(flavor = "multi_thread")]
88
async fn cannot_create_empty_group() -> Result<(), Error> {
99
let app = TestApp::get().await;
1010
let tanker = app.start_anonymous(&app.create_identity(None)).await?;
@@ -20,7 +20,7 @@ async fn cannot_create_empty_group() -> Result<(), Error> {
2020
Ok(())
2121
}
2222

23-
#[tokio::test(threaded_scheduler)]
23+
#[tokio::test(flavor = "multi_thread")]
2424
async fn create_valid_group() -> Result<(), Error> {
2525
let app = TestApp::get().await;
2626
let alice = app.start_anonymous(&app.create_identity(None)).await?;
@@ -36,7 +36,7 @@ async fn create_valid_group() -> Result<(), Error> {
3636
Ok(())
3737
}
3838

39-
#[tokio::test(threaded_scheduler)]
39+
#[tokio::test(flavor = "multi_thread")]
4040
async fn encrypt_and_share_with_external_group() -> Result<(), Error> {
4141
let app = TestApp::get().await;
4242
let alice_id = app.create_identity(None);
@@ -58,7 +58,7 @@ async fn encrypt_and_share_with_external_group() -> Result<(), Error> {
5858
Ok(())
5959
}
6060

61-
#[tokio::test(threaded_scheduler)]
61+
#[tokio::test(flavor = "multi_thread")]
6262
async fn share_with_external_group() -> Result<(), Error> {
6363
let app = TestApp::get().await;
6464
let alice_id = app.create_identity(None);
@@ -83,7 +83,7 @@ async fn share_with_external_group() -> Result<(), Error> {
8383
Ok(())
8484
}
8585

86-
#[tokio::test(threaded_scheduler)]
86+
#[tokio::test(flavor = "multi_thread")]
8787
async fn add_member_to_group() -> Result<(), Error> {
8888
let app = TestApp::get().await;
8989
let alice_id = app.create_identity(None);

tests/stream_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::pin::Pin;
88
use std::task::{Context, Poll};
99
use tankersdk::{Error, ErrorCode};
1010

11-
#[tokio::test(threaded_scheduler)]
11+
#[tokio::test(flavor = "multi_thread")]
1212
async fn encrypt_stream_and_decrypt() -> Result<(), Error> {
1313
let app = TestApp::get().await;
1414
let tanker = app.start_anonymous(&app.create_identity(None)).await?;
@@ -26,7 +26,7 @@ async fn encrypt_stream_and_decrypt() -> Result<(), Error> {
2626
Ok(())
2727
}
2828

29-
#[tokio::test(threaded_scheduler)]
29+
#[tokio::test(flavor = "multi_thread")]
3030
async fn encrypt_and_decrypt_stream() -> Result<(), futures::io::Error> {
3131
let app = TestApp::get().await;
3232
let tanker = app.start_anonymous(&app.create_identity(None)).await?;
@@ -42,7 +42,7 @@ async fn encrypt_and_decrypt_stream() -> Result<(), futures::io::Error> {
4242
Ok(())
4343
}
4444

45-
#[tokio::test(threaded_scheduler)]
45+
#[tokio::test(flavor = "multi_thread")]
4646
async fn encrypt_stream_and_decrypt_stream() -> Result<(), futures::io::Error> {
4747
let app = TestApp::get().await;
4848
let tanker = app.start_anonymous(&app.create_identity(None)).await?;
@@ -84,7 +84,7 @@ impl AsyncRead for ErrorAfter {
8484
}
8585
}
8686

87-
#[tokio::test(threaded_scheduler)]
87+
#[tokio::test(flavor = "multi_thread")]
8888
async fn encrypt_stream_with_error() -> Result<(), Error> {
8989
let app = TestApp::get().await;
9090
let tanker = app.start_anonymous(&app.create_identity(None)).await?;
@@ -104,7 +104,7 @@ async fn encrypt_stream_with_error() -> Result<(), Error> {
104104
Ok(())
105105
}
106106

107-
#[tokio::test(threaded_scheduler)]
107+
#[tokio::test(flavor = "multi_thread")]
108108
async fn decrypt_stream_with_early_error() -> Result<(), Error> {
109109
let app = TestApp::get().await;
110110
let tanker = app.start_anonymous(&app.create_identity(None)).await?;
@@ -123,7 +123,7 @@ async fn decrypt_stream_with_early_error() -> Result<(), Error> {
123123
Ok(())
124124
}
125125

126-
#[tokio::test(threaded_scheduler)]
126+
#[tokio::test(flavor = "multi_thread")]
127127
async fn decrypt_stream_with_tanker_error() -> Result<(), Error> {
128128
let app = TestApp::get().await;
129129
let tanker = app.start_anonymous(&app.create_identity(None)).await?;

tests/tanker_tests.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn core_native_version() {
1313
assert!(!Core::native_version().is_empty())
1414
}
1515

16-
#[tokio::test(threaded_scheduler)]
16+
#[tokio::test(flavor = "multi_thread")]
1717
async fn tanker_create() -> Result<(), Error> {
1818
let app = TestApp::get().await;
1919
let opts = Options::new(app.id().to_owned(), ":memory:".to_string())
@@ -23,7 +23,7 @@ async fn tanker_create() -> Result<(), Error> {
2323
Ok(())
2424
}
2525

26-
#[tokio::test(threaded_scheduler)]
26+
#[tokio::test(flavor = "multi_thread")]
2727
async fn tanker_bad_create() {
2828
let opts = Options::new("bad-app-id".to_string(), ":memory:".to_string())
2929
.with_sdk_type("sdk-rust-test".to_string());
@@ -33,7 +33,7 @@ async fn tanker_bad_create() {
3333
assert_eq!(err.code(), ErrorCode::InvalidArgument);
3434
}
3535

36-
#[tokio::test(threaded_scheduler)]
36+
#[tokio::test(flavor = "multi_thread")]
3737
async fn start_stop_session() -> Result<(), Error> {
3838
let app = TestApp::get().await;
3939
let tanker = Core::new(app.make_options()).await?;
@@ -49,7 +49,7 @@ async fn start_stop_session() -> Result<(), Error> {
4949
Ok(())
5050
}
5151

52-
#[tokio::test(threaded_scheduler)]
52+
#[tokio::test(flavor = "multi_thread")]
5353
async fn self_revoke() -> Result<(), Error> {
5454
let app = TestApp::get().await;
5555
let tanker = app.start_anonymous(&app.create_identity(None)).await?;
@@ -62,7 +62,7 @@ async fn self_revoke() -> Result<(), Error> {
6262
tanker.stop().await
6363
}
6464

65-
#[tokio::test(threaded_scheduler)]
65+
#[tokio::test(flavor = "multi_thread")]
6666
async fn has_correct_device_list() -> Result<(), Error> {
6767
let app = TestApp::get().await;
6868
let tanker = app.start_anonymous(&app.create_identity(None)).await?;
@@ -75,7 +75,7 @@ async fn has_correct_device_list() -> Result<(), Error> {
7575
tanker.stop().await
7676
}
7777

78-
#[tokio::test(threaded_scheduler)]
78+
#[tokio::test(flavor = "multi_thread")]
7979
async fn encrypt_and_decrypt() -> Result<(), Error> {
8080
let app = TestApp::get().await;
8181
let tanker = app.start_anonymous(&app.create_identity(None)).await?;
@@ -89,7 +89,7 @@ async fn encrypt_and_decrypt() -> Result<(), Error> {
8989
Ok(())
9090
}
9191

92-
#[tokio::test(threaded_scheduler)]
92+
#[tokio::test(flavor = "multi_thread")]
9393
async fn share_then_decrypt() -> Result<(), Error> {
9494
let app = TestApp::get().await;
9595
let alice = app.start_anonymous(&app.create_identity(None)).await?;
@@ -112,7 +112,7 @@ async fn share_then_decrypt() -> Result<(), Error> {
112112
Ok(())
113113
}
114114

115-
#[tokio::test(threaded_scheduler)]
115+
#[tokio::test(flavor = "multi_thread")]
116116
async fn encrypt_and_share_then_decrypt() -> Result<(), Error> {
117117
let app = TestApp::get().await;
118118
let alice = app.start_anonymous(&app.create_identity(None)).await?;
@@ -131,7 +131,7 @@ async fn encrypt_and_share_then_decrypt() -> Result<(), Error> {
131131
Ok(())
132132
}
133133

134-
#[tokio::test(threaded_scheduler)]
134+
#[tokio::test(flavor = "multi_thread")]
135135
async fn encrypt_no_share_with_self() -> Result<(), Error> {
136136
let app = TestApp::get().await;
137137
let alice = app.start_anonymous(&app.create_identity(None)).await?;
@@ -155,7 +155,7 @@ async fn encrypt_no_share_with_self() -> Result<(), Error> {
155155
Ok(())
156156
}
157157

158-
#[tokio::test(threaded_scheduler)]
158+
#[tokio::test(flavor = "multi_thread")]
159159
async fn share_with_provisional_user() -> Result<(), Error> {
160160
let message = b"Variable 'message' is never used";
161161
let app = TestApp::get().await;
@@ -190,7 +190,7 @@ async fn share_with_provisional_user() -> Result<(), Error> {
190190
Ok(())
191191
}
192192

193-
#[tokio::test(threaded_scheduler)]
193+
#[tokio::test(flavor = "multi_thread")]
194194
async fn attach_provisional_with_single_verif() -> Result<(), Error> {
195195
let message = b"Variable 'message' is never used";
196196
let app = TestApp::get().await;
@@ -223,14 +223,14 @@ async fn attach_provisional_with_single_verif() -> Result<(), Error> {
223223
Ok(())
224224
}
225225

226-
#[tokio::test(threaded_scheduler)]
226+
#[tokio::test(flavor = "multi_thread")]
227227
async fn prehash_password_empty() -> Result<(), Error> {
228228
let err = Core::prehash_password("").unwrap_err();
229229
assert_eq!(err.code(), ErrorCode::InvalidArgument);
230230
Ok(())
231231
}
232232

233-
#[tokio::test(threaded_scheduler)]
233+
#[tokio::test(flavor = "multi_thread")]
234234
async fn prehash_password_test_vector_1() -> Result<(), Error> {
235235
let input = "super secretive password";
236236
let expected = "UYNRgDLSClFWKsJ7dl9uPJjhpIoEzadksv/Mf44gSHI=";
@@ -239,7 +239,7 @@ async fn prehash_password_test_vector_1() -> Result<(), Error> {
239239
Ok(())
240240
}
241241

242-
#[tokio::test(threaded_scheduler)]
242+
#[tokio::test(flavor = "multi_thread")]
243243
async fn prehash_password_test_vector_2() -> Result<(), Error> {
244244
let input = "test éå 한국어 😃";
245245
let expected = "Pkn/pjub2uwkBDpt2HUieWOXP5xLn0Zlen16ID4C7jI=";

tests/verify_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use identity::TestApp;
44
use serde_json::{json, Value};
55
use tankersdk::*;
66

7-
#[tokio::test(threaded_scheduler)]
7+
#[tokio::test(flavor = "multi_thread")]
88
async fn validate_new_device_with_verif_key() -> Result<(), Error> {
99
let app = TestApp::get().await;
1010
let id = &app.create_identity(None);
@@ -23,7 +23,7 @@ async fn validate_new_device_with_verif_key() -> Result<(), Error> {
2323
tanker.stop().await
2424
}
2525

26-
#[tokio::test(threaded_scheduler)]
26+
#[tokio::test(flavor = "multi_thread")]
2727
async fn setup_and_use_passphrase() -> Result<(), Error> {
2828
let app = TestApp::get().await;
2929
let id = &app.create_identity(None);
@@ -41,7 +41,7 @@ async fn setup_and_use_passphrase() -> Result<(), Error> {
4141
tanker.stop().await
4242
}
4343

44-
#[tokio::test(threaded_scheduler)]
44+
#[tokio::test(flavor = "multi_thread")]
4545
async fn unlock_with_updated_passphrase() -> Result<(), Error> {
4646
let app = TestApp::get().await;
4747
let id = &app.create_identity(None);
@@ -61,7 +61,7 @@ async fn unlock_with_updated_passphrase() -> Result<(), Error> {
6161
tanker.stop().await
6262
}
6363

64-
#[tokio::test(threaded_scheduler)]
64+
#[tokio::test(flavor = "multi_thread")]
6565
async fn check_passphrase_is_setup() -> Result<(), Error> {
6666
let app = TestApp::get().await;
6767
let id = &app.create_identity(None);
@@ -77,7 +77,7 @@ async fn check_passphrase_is_setup() -> Result<(), Error> {
7777
Ok(())
7878
}
7979

80-
#[tokio::test(threaded_scheduler)]
80+
#[tokio::test(flavor = "multi_thread")]
8181
async fn check_email_verif_is_setup() -> Result<(), Error> {
8282
let app = TestApp::get().await;
8383
let id = &app.create_identity(None);
@@ -97,7 +97,7 @@ async fn check_email_verif_is_setup() -> Result<(), Error> {
9797
Ok(())
9898
}
9999

100-
#[tokio::test(threaded_scheduler)]
100+
#[tokio::test(flavor = "multi_thread")]
101101
async fn unlock_with_verif_code() -> Result<(), Error> {
102102
let app = TestApp::get().await;
103103
let id = &app.create_identity(None);
@@ -123,7 +123,7 @@ async fn unlock_with_verif_code() -> Result<(), Error> {
123123
tanker.stop().await
124124
}
125125

126-
#[tokio::test(threaded_scheduler)]
126+
#[tokio::test(flavor = "multi_thread")]
127127
async fn unlock_with_oidc_id_token() -> Result<(), Box<dyn std::error::Error>> {
128128
let app = TestApp::get().await;
129129
let oidc = app.get_oidc_config();

0 commit comments

Comments
 (0)