-
Notifications
You must be signed in to change notification settings - Fork 70
fix tests for mongodb 3.4 #188
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ fn read_first_non_monitor_line(file: &mut BufReader<&File>, line: &mut String) { | |
|
||
#[test] | ||
fn logging() { | ||
let _ = fs::remove_file("test_apm_log.txt"); | ||
let _ = fs::remove_file("test_log.txt"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason the old name of this file didn't match the name I put in the .gitignore way back when this test was created, so I fixed that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That might have been my fault -- i changed a lot of stringy fields to be more specific when I was parallelizing all of the tests. |
||
|
||
// Reset State | ||
let reset_client = Client::connect("localhost", 27017) | ||
|
@@ -63,8 +63,11 @@ fn logging() { | |
let reset_coll = reset_db.collection("logging"); | ||
reset_coll.drop().unwrap(); | ||
|
||
let db_version = reset_db.version().unwrap(); | ||
let v3_3 = db_version.major <= 3 && db_version.minor <= 3; | ||
|
||
// Start logging | ||
let client_options = ClientOptions::with_log_file("test_apm_log.txt"); | ||
let client_options = ClientOptions::with_log_file("test_log.txt"); | ||
let client = Client::connect_with_options("localhost", 27017, client_options).unwrap(); | ||
|
||
let db = client.db("test-apm-mod"); | ||
|
@@ -86,7 +89,7 @@ fn logging() { | |
|
||
coll.find(Some(filter), None).unwrap(); | ||
|
||
let f = File::open("test_apm_log.txt").unwrap(); | ||
let f = File::open("test_log.txt").unwrap(); | ||
let mut file = BufReader::new(&f); | ||
let mut line = String::new(); | ||
|
||
|
@@ -121,10 +124,17 @@ fn logging() { | |
_id: 1 }] }\n", | ||
&line); | ||
|
||
|
||
let insert_one_line_start = if v3_3 { | ||
"COMMAND.insert_one 127.0.0.1:27017 COMPLETED: { ok: 1, n: 1 } (" | ||
} else { | ||
"COMMAND.insert_one 127.0.0.1:27017 COMPLETED: { n: 1, ok: 1 } (" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. argh, drives me crazy. this is the expected apm behavior for drivers, yeah? to print it out as ordered by the server, rather than always be lexicographic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll double check, but I'd guess that the spec doesn't even mention it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, makes sense as long as we're supposed to print document fields in insert order (most likely) and read server responses in insert order (probably doesn't even mention this in any of the documentation, but we wouldn't want to do any extra work here to alphabetize anyways). |
||
}; | ||
|
||
// First insert completed | ||
line.clear(); | ||
read_first_non_monitor_line(&mut file, &mut line); | ||
assert!(line.starts_with("COMMAND.insert_one 127.0.0.1:27017 COMPLETED: { ok: 1, n: 1 } (")); | ||
assert!(line.starts_with(insert_one_line_start)); | ||
assert!(line.ends_with(" ns)\n")); | ||
|
||
// Second insert started | ||
|
@@ -137,7 +147,7 @@ fn logging() { | |
// Second insert completed | ||
line.clear(); | ||
read_first_non_monitor_line(&mut file, &mut line); | ||
assert!(line.starts_with("COMMAND.insert_one 127.0.0.1:27017 COMPLETED: { ok: 1, n: 1 } (")); | ||
assert!(line.starts_with(insert_one_line_start)); | ||
assert!(line.ends_with(" ns)\n")); | ||
|
||
// Third insert started | ||
|
@@ -150,7 +160,7 @@ fn logging() { | |
// Third insert completed | ||
line.clear(); | ||
read_first_non_monitor_line(&mut file, &mut line); | ||
assert!(line.starts_with("COMMAND.insert_one 127.0.0.1:27017 COMPLETED: { ok: 1, n: 1 } (")); | ||
assert!(line.starts_with(insert_one_line_start)); | ||
assert!(line.ends_with(" ns)\n")); | ||
|
||
// Find command started | ||
|
@@ -170,5 +180,5 @@ fn logging() { | |
|
||
coll.drop().unwrap(); | ||
|
||
fs::remove_file("test_apm_log.txt").unwrap(); | ||
fs::remove_file("test_log.txt").unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've noticed/started to get annoyed that the test file doesn't get cleaned up when the tests fail above this line, so I'm thinking we should change the tests so this file doesn't clutter things up. Given that the file should only be about a dozen lines, I think reading the whole thing into a string and then iterating over the lines should be fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to me for now. In an ideal future we would allow the client to take in a generic Write-implementing object and pass in a string-like IO object for testing purposes; if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good idea; it would be much more idiomatic that way. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ fn create_collection() { | |
|
||
let db1 = if v3_1 { "test1" } else { "test2" }; | ||
let db2 = if v3_1 { "test2" } else { "test1" }; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See, rustfmt does actually help sometimes; empty lines shouldn't have extra whitespace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a rare win, but still on thin ice. i'm watching you, rustfmt |
||
match results[result_size - 2].get("name") { | ||
Some(&Bson::String(ref name)) => assert_eq!(db1, name), | ||
_ => panic!("Expected BSON string!"), | ||
|
@@ -82,7 +82,7 @@ fn list_collections() { | |
|
||
let db1 = if v3_1 { "test" } else { "test2" }; | ||
let db2 = if v3_1 { "test2" } else { "test" }; | ||
|
||
match results[result_size - 2].get("name") { | ||
Some(&Bson::String(ref name)) => assert_eq!(db1, name), | ||
_ => panic!("Expected BSON string!"), | ||
|
@@ -101,6 +101,17 @@ fn create_and_get_users() { | |
db.drop_database().unwrap(); | ||
db.drop_all_users(None).unwrap(); | ||
|
||
let kevin_options = CreateUserOptions { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that versions below 3.4 return the users in the order they're created and 3.4 returns them in lexicographical order, the easiest fix for this is to just create the users in the order where all versions expect the same thing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice. |
||
custom_data: None, | ||
roles: vec![Role::All(AllDatabaseRole::Read)], | ||
write_concern: None, | ||
}; | ||
|
||
db.create_user("kevin", | ||
"ihavenosenseofhumorandthereforeihatepuns!", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha, I had forgotten about that until I made this change, but I'm not even slightly surprised that did this |
||
Some(kevin_options)) | ||
.unwrap(); | ||
|
||
let saghm_options = CreateUserOptions { | ||
custom_data: Some(doc! { "foo" => "bar" }), | ||
roles: vec![Role::Single { | ||
|
@@ -113,16 +124,6 @@ fn create_and_get_users() { | |
|
||
db.create_user("saghm", "ilikepuns!", Some(saghm_options)).unwrap(); | ||
|
||
let kevin_options = CreateUserOptions { | ||
custom_data: None, | ||
roles: vec![Role::All(AllDatabaseRole::Read)], | ||
write_concern: None, | ||
}; | ||
|
||
db.create_user("kevin", | ||
"ihavenosenseofhumorandthereforeihatepuns!", | ||
Some(kevin_options)) | ||
.unwrap(); | ||
db.create_user("val", "ilikeangularjs!", None).unwrap(); | ||
|
||
let user = db.get_user("saghm", None).unwrap(); | ||
|
@@ -163,13 +164,13 @@ fn create_and_get_users() { | |
assert_eq!(users.len(), 3); | ||
|
||
match users[0].get("user") { | ||
Some(&Bson::String(ref s)) => assert_eq!("saghm", s), | ||
_ => panic!("User isn't named 'saghm' but should be"), | ||
Some(&Bson::String(ref s)) => assert_eq!("kevin", s), | ||
_ => panic!("User isn't named 'kevin' but should be"), | ||
}; | ||
|
||
match users[1].get("user") { | ||
Some(&Bson::String(ref s)) => assert_eq!("kevin", s), | ||
_ => panic!("User isn't named 'kevin' but should be"), | ||
Some(&Bson::String(ref s)) => assert_eq!("saghm", s), | ||
_ => panic!("User isn't named 'saghm' but should be"), | ||
}; | ||
|
||
match users[2].get("user") { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is starting to get a bit messy; we should try to look into using mongo orchestration or some other method of managing testing against the different server versions, ideally before 3.6 comes out and we have to add that as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a tracking issue for Morc (this is a thing now. i'm making this name happen)