Skip to content
This repository was archived by the owner on Oct 18, 2021. It is now read-only.

Commit 6c079f9

Browse files
authored
Parallelize test suite (#173)
1 parent 5ca5a2e commit 6c079f9

File tree

10 files changed

+165
-143
lines changed

10 files changed

+165
-143
lines changed

.travis.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@ before_install:
1010
- tar xvf mongodb-linux-x86_64-3.2.10.tgz
1111
- mv mongodb-linux-x86_64-3.2.10 3.2.10
1212

13-
env:
14-
- RUST_TEST_THREADS=1
15-
1613
script:
17-
- mkdir -p ./data/db ./data/test ./data/db2 ./data/test2
14+
- mkdir -p ./data/db ./data/db2
1815
- 3.0.12/bin/mongod --fork --nopreallocj --dbpath ./data/db --syslog --port 27017
19-
- 3.0.12/bin/mongod --fork --nopreallocj --dbpath ./data/test --syslog --port 27018
2016
- cargo build --verbose
2117
- cargo test --verbose
2218
- killall mongod
2319
- 3.2.10/bin/mongod --fork --nopreallocj --dbpath ./data/db2 --syslog --port 27017
24-
- 3.2.10/bin/mongod --fork --nopreallocj --dbpath ./data/test2 --syslog --port 27018
2520
- cargo test --verbose

tests/apm/mod.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ fn timed_query(_client: Client, command_result: &CommandResult) {
2727
#[test]
2828
fn command_duration() {
2929
let mut client = Client::connect("localhost", 27017).expect("damn it!");
30-
let db = client.db("test");
31-
let coll = db.collection("event_hooks");
30+
let db = client.db("test-apm-mod");
31+
let coll = db.collection("command_duration");
3232
coll.drop().unwrap();
3333

3434
let docs = (1..4).map(|i| doc! { "_id" => i, "x" => (rand::random::<u8>() as u32) }).collect();
@@ -54,16 +54,23 @@ fn read_first_non_monitor_line(file: &mut BufReader<&File>, line: &mut String) {
5454

5555
#[test]
5656
fn logging() {
57-
let _ = fs::remove_file("test_log.txt");
57+
let _ = fs::remove_file("test_apm_log.txt");
5858

59-
let client_options = ClientOptions::with_log_file("test_log.txt");
59+
// Reset State
60+
let reset_client = Client::connect("localhost", 27017).expect("Failed to connect to localhost:27017");
61+
let reset_db = reset_client.db("test-apm-mod");
62+
let reset_coll = reset_db.collection("logging");
63+
reset_coll.drop().unwrap();
64+
65+
// Start logging
66+
let client_options = ClientOptions::with_log_file("test_apm_log.txt");
6067
let client = Client::connect_with_options("localhost", 27017, client_options).unwrap();
6168

62-
let db = client.db("test");
63-
db.create_collection("logging", None).unwrap();
69+
let db = client.db("test-apm-mod");
6470
let coll = db.collection("logging");
71+
db.create_collection("logging", None).unwrap();
6572
coll.drop().unwrap();
66-
73+
6774
let doc1 = doc! { "_id" => 1 };
6875
let doc2 = doc! { "_id" => 2 };
6976
let doc3 = doc! { "_id" => 3 };
@@ -78,7 +85,7 @@ fn logging() {
7885

7986
coll.find(Some(filter), None).unwrap();
8087

81-
let f = File::open("test_log.txt").unwrap();
88+
let f = File::open("test_apm_log.txt").unwrap();
8289
let mut file = BufReader::new(&f);
8390
let mut line = String::new();
8491

@@ -88,7 +95,7 @@ fn logging() {
8895
capped: false, auto_index_id: true, flags: 1 }\n",
8996
&line);
9097

91-
// Create Collection completed
98+
// Create collection completed
9299
line.clear();
93100
read_first_non_monitor_line(&mut file, &mut line);
94101
assert!(line.starts_with("COMMAND.create_collection 127.0.0.1:27017 COMPLETED: { ok: 1 } ("));
@@ -104,7 +111,7 @@ fn logging() {
104111
line.clear();
105112
read_first_non_monitor_line(&mut file, &mut line);
106113
assert!(line.starts_with("COMMAND.drop_collection 127.0.0.1:27017 COMPLETED: { ns: \
107-
\"test.logging\", nIndexesWas: 1, ok: 1 } ("));
114+
\"test-apm-mod.logging\", nIndexesWas: 1, ok: 1 } ("));
108115
assert!(line.ends_with(" ns)\n"));
109116

110117
// First insert started
@@ -157,11 +164,11 @@ fn logging() {
157164
line.clear();
158165
read_first_non_monitor_line(&mut file, &mut line);
159166
assert!(line.starts_with("COMMAND.find 127.0.0.1:27017 COMPLETED: { cursor: { id: 0, ns: \
160-
\"test.logging\", firstBatch: [{ _id: 2 }, { _id: 3 }] }, ok: 1 } \
167+
\"test-apm-mod.logging\", firstBatch: [{ _id: 2 }, { _id: 3 }] }, ok: 1 } \
161168
("));
162169
assert!(line.ends_with(" ns)\n"));
163170

164171
coll.drop().unwrap();
165172

166-
fs::remove_file("test_log.txt").unwrap();
173+
fs::remove_file("test_apm_log.txt").unwrap();
167174
}

tests/auth/mod.rs

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@ use mongodb::{CommandType, Client, ThreadedClient};
33
use mongodb::db::ThreadedDatabase;
44
use mongodb::error::Error::OperationError;
55

6+
fn doc_vec_find(vec: &Vec<Bson>, key: &str, val: &str) -> Option<Bson> {
7+
vec.iter()
8+
.cloned()
9+
.find(|ref bdoc| match bdoc {
10+
&&Bson::Document(ref doc) => match doc.get(key) {
11+
Some(&Bson::String(ref s)) => s == val,
12+
_ => false
13+
},
14+
_ => false,
15+
})
16+
.map(|ref bson| bson.to_owned())
17+
}
18+
619
#[test]
720
fn invalid_user() {
821
let client = Client::connect("localhost", 27017).unwrap();
9-
let db = client.db("auth");
10-
let _ = db.drop_all_users(None).unwrap();
22+
let db = client.db("test-auth-mod-invalid_user");
23+
let _ = db.drop_user("test-auth-mod-invalid_user-saghm", None);
1124
let doc = doc! { "connectionStatus" => 1};
1225
let before = db.command(doc.clone(), CommandType::Suppressed, None).unwrap();
1326

@@ -17,11 +30,11 @@ fn invalid_user() {
1730
};
1831

1932
match info.get("authenticatedUsers") {
20-
Some(&Bson::Array(ref vec)) => assert!(vec.is_empty()),
33+
Some(&Bson::Array(ref vec)) => assert!(doc_vec_find(&vec, "user", "test-auth-mod-invalid_user-saghm").is_none()),
2134
_ => panic!("Invalid array of authenticatedUsers for initial connectionStatus command"),
2235
};
2336

24-
match db.auth("invalid_user", "some_password") {
37+
match db.auth("test-auth-mod-invalid_user-saghm", "some_password") {
2538
Err(OperationError(_)) => (),
2639
Err(_) => {
2740
panic!("Expected OperationError for invalid authentication, but got some other error \
@@ -36,19 +49,18 @@ fn invalid_user() {
3649
Some(&Bson::Document(ref doc)) => doc.clone(),
3750
_ => panic!("Invalid response for subsequent connectionStatus command"),
3851
};
39-
52+
4053
match info.get("authenticatedUsers") {
41-
Some(&Bson::Array(ref vec)) => assert!(vec.is_empty()),
42-
_ => panic!("Invalid array of authenticatedUsers for subsequent connectionStatus command"),
54+
Some(&Bson::Array(ref vec)) => assert!(doc_vec_find(&vec, "user", "test-auth-mod-invalid_user-saghm").is_none()),
55+
_ => panic!("Invalid array of authenticatedUsers for initial connectionStatus command"),
4356
};
4457
}
4558

46-
4759
#[test]
4860
fn invalid_password() {
4961
let client = Client::connect("localhost", 27017).unwrap();
50-
let db = client.db("auth");
51-
let _ = db.drop_all_users(None).unwrap();
62+
let db = client.db("test-auth-mod-invalid_password");
63+
let _ = db.drop_user("test-auth-mod-invalid_password-saghm", None);
5264
let doc = doc! { "connectionStatus" => 1};
5365
let before = db.command(doc.clone(), CommandType::Suppressed, None).unwrap();
5466

@@ -58,13 +70,13 @@ fn invalid_password() {
5870
};
5971

6072
match info.get("authenticatedUsers") {
61-
Some(&Bson::Array(ref vec)) => assert!(vec.is_empty()),
73+
Some(&Bson::Array(ref vec)) => assert!(doc_vec_find(&vec, "user", "test-auth-mod-invalid_password-saghm").is_none()),
6274
_ => panic!("Invalid array of authenticatedUsers for initial connectionStatus command"),
6375
};
6476

65-
db.create_user("saghm", "such_secure_password", None).unwrap();
77+
db.create_user("test-auth-mod-invalid_password-saghm", "such_secure_password", None).unwrap();
6678

67-
match db.auth("saghm", "wrong_password") {
79+
match db.auth("test-auth-mod-invalid_password-saghm", "wrong_password") {
6880
Err(OperationError(_)) => (),
6981
Err(_) => {
7082
panic!("Expected OperationError for invalid authentication, but got some other error \
@@ -81,16 +93,16 @@ fn invalid_password() {
8193
};
8294

8395
match info.get("authenticatedUsers") {
84-
Some(&Bson::Array(ref vec)) => assert!(vec.is_empty()),
96+
Some(&Bson::Array(ref vec)) => assert!(doc_vec_find(&vec, "user", "test-auth-mod-invalid_password-saghm").is_none()),
8597
_ => panic!("Invalid array of authenticatedUsers for subsequent connectionStatus command"),
8698
};
8799
}
88100

89101
#[test]
90102
fn successful_login() {
91103
let client = Client::connect("localhost", 27017).unwrap();
92-
let db = client.db("auth");
93-
let _ = db.drop_all_users(None).unwrap();
104+
let db = client.db("test-auth-mod-successful_login");
105+
let _ = db.drop_user("test-auth-mod-successful_login-saghm", None);
94106
let doc = doc! { "connectionStatus" => 1};
95107
let before = db.command(doc.clone(), CommandType::Suppressed, None).unwrap();
96108

@@ -100,12 +112,12 @@ fn successful_login() {
100112
};
101113

102114
match info.get("authenticatedUsers") {
103-
Some(&Bson::Array(ref vec)) => assert!(vec.is_empty()),
115+
Some(&Bson::Array(ref vec)) => assert!(doc_vec_find(&vec, "user", "test-auth-mod-successful_login-saghm").is_none()),
104116
_ => panic!("Invalid array of authenticatedUsers for initial connectionStatus command"),
105117
};
106118

107-
db.create_user("saghm", "such_secure_password", None).unwrap();
108-
db.auth("saghm", "such_secure_password").unwrap();
119+
db.create_user("test-auth-mod-successful_login-saghm", "such_secure_password", None).unwrap();
120+
db.auth("test-auth-mod-successful_login-saghm", "such_secure_password").unwrap();
109121

110122
let after = db.command(doc, CommandType::Suppressed, None).unwrap();
111123

@@ -119,20 +131,20 @@ fn successful_login() {
119131
_ => panic!("Invalid array of authenticatedUsers for subsequent connectionStatus command"),
120132
};
121133

122-
assert_eq!(authed_users.len(), 1);
134+
let bson_user = doc_vec_find(&authed_users, "user", "test-auth-mod-successful_login-saghm").unwrap();
123135

124-
let user = match authed_users[0] {
136+
let user = match bson_user {
125137
Bson::Document(ref doc) => doc.clone(),
126138
_ => panic!("Invalid auth'd user in subsequent connectionStatus response"),
127139
};
128140

129141
match user.get("user") {
130-
Some(&Bson::String(ref s)) => assert_eq!(s, "saghm"),
142+
Some(&Bson::String(ref s)) => assert_eq!(s, "test-auth-mod-successful_login-saghm"),
131143
_ => panic!("Invalid `user` field of auth'd user"),
132144
};
133145

134146
match user.get("db") {
135-
Some(&Bson::String(ref s)) => assert_eq!(s, "auth"),
147+
Some(&Bson::String(ref s)) => assert_eq!(s, "test-auth-mod-successful_login"),
136148
_ => panic!("Invalid `db` field of auth'd user"),
137149
};
138150
}

tests/client/bulk.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use mongodb::db::ThreadedDatabase;
66
#[test]
77
fn bulk_ordered_insert_only() {
88
let client = Client::connect("localhost", 27017).unwrap();
9-
let db = client.db("test");
9+
let db = client.db("test-client-bulk");
1010
let coll = db.collection("bulk_ordered_insert_only");
11-
1211
coll.drop().unwrap();
1312

1413
let models = (1..5)
@@ -47,7 +46,7 @@ fn bulk_ordered_insert_only() {
4746
#[test]
4847
fn bulk_unordered_insert_only() {
4948
let client = Client::connect("localhost", 27017).unwrap();
50-
let db = client.db("test");
49+
let db = client.db("test-client-bulk");
5150
let coll = db.collection("bulk_unordered_insert_only");
5251

5352
coll.drop().unwrap();
@@ -148,9 +147,8 @@ fn bulk_ordered_mix() {
148147
];
149148

150149
let client = Client::connect("localhost", 27017).unwrap();
151-
let db = client.db("test");
150+
let db = client.db("test-client-bulk");
152151
let coll = db.collection("bulk_ordered_mix");
153-
154152
coll.drop().unwrap();
155153

156154
let result = coll.bulk_write(models, true);

0 commit comments

Comments
 (0)