-
Notifications
You must be signed in to change notification settings - Fork 10
Conversation
|
@kirillt
|
@funnyVOLT thank you for the test case. I'll look into it deeper soon. It's great that you've discovered corner cases I've missed! Could you create small isolated test cases reproducing these 2 problems?
|
@kirillt , I've pushed test case codes. |
src/index.rs
Outdated
// create | ||
1 => { | ||
let mut file_name_new = String::from(cur_file_name); | ||
file_name_new.push_str("_new.txt"); |
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.
Would be better to provide new random unique name, automatically.
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.
Would be better to provide new random unique name, automatically.
I added const variable CREATE, UPDATE, DELETE, MOVE .
src/index.rs
Outdated
let mut folder_1 = root_path.clone(); | ||
let mut folder_2 = root_path.clone(); | ||
folder_1.push(FILE_DIR_1); | ||
folder_2.push(FILE_DIR_2); |
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.
Do we really need 2 folders?
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.
Do we really need 2 folders?
It is necessary for file movement function.
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.
We can also just move to new random filename. This way we can apply move operation multiple times, no need to track in which of the two the file resides.
src/index.rs
Outdated
const FILE_NAME: &str = "test_"; | ||
const FILE_COUNT: i32 = 10; | ||
const FILE_COUNT: i32 = 3; |
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.
Isn't 3
too few for proper testing?
src/index.rs
Outdated
@@ -1320,7 +1319,7 @@ mod tests { | |||
.update_all() | |||
.expect("Should update index correctly"); | |||
|
|||
assert_eq!(index_track_addition, index_update_all); | |||
assert_ne!(index_track_addition, index_update_all); |
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.
Must be equal, isn't it?
.update_all() | ||
.expect("Should update index correctly"); | ||
|
||
assert_ne!( |
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.
After this assertion we should sleep
for 1ms, perform update_all
again and assert_eq
new index.
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.
regarding this test,
Why should the result from track_addition
and update_all
be different?
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.
Great job!
Left some comments.
I think we can also add simple doc comments on the methods implemented for ResourceIndex
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.
some more comments but we are getting there
crc32: CRC32_2, | ||
} | ||
} | ||
|
||
fn run_test_and_clean_up( |
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.
I am not sure we need this function
we can use TempDir::new
to achieve the same output
tempdir
crate automatically cleans up the temporary directories when they go out of scope
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.
I will leave this one for a follow up PR
match update_state.try_into() { | ||
Ok(FileAction::CREATE) => { | ||
let _ = index1.track_addition(&new_file_path); | ||
} | ||
Ok(FileAction::UPDATE) => { | ||
let _ = index1.track_update(&file_path, old_id); | ||
} | ||
Ok(FileAction::DELETE) => { | ||
let _ = index1.track_deletion(old_id); | ||
} | ||
Ok(FileAction::MOVE) => { | ||
let _ = index1.track_deletion(old_id); | ||
let _ = index1.track_addition(&new_file_path); | ||
} | ||
Err(_) => println!("rnd_num error"), | ||
} |
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.
Are we intentionally ignoring errors here for testing purposes?
If not, we should panic with errors
match update_state.try_into() { | |
Ok(FileAction::CREATE) => { | |
let _ = index1.track_addition(&new_file_path); | |
} | |
Ok(FileAction::UPDATE) => { | |
let _ = index1.track_update(&file_path, old_id); | |
} | |
Ok(FileAction::DELETE) => { | |
let _ = index1.track_deletion(old_id); | |
} | |
Ok(FileAction::MOVE) => { | |
let _ = index1.track_deletion(old_id); | |
let _ = index1.track_addition(&new_file_path); | |
} | |
Err(_) => println!("rnd_num error"), | |
} | |
match update_state.try_into() { | |
Ok(FileAction::CREATE) => { | |
index1 | |
.track_addition(&new_file_path) | |
.expect("Should track addition correctly"); | |
} | |
Ok(FileAction::UPDATE) => { | |
index1 | |
.track_update(&file_path, old_id) | |
.expect("Should track update correctly"); | |
} | |
Ok(FileAction::DELETE) => { | |
index1 | |
.track_deletion(old_id) | |
.expect("Should track deletion correctly"); | |
} | |
Ok(FileAction::MOVE) => { | |
index1 | |
.track_deletion(old_id) | |
.expect("Should track deletion correctly"); | |
index1 | |
.track_addition(&new_file_path) | |
.expect("Should track addition correctly"); | |
} | |
Err(_) => println!("rnd_num error"), | |
} |
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.
@tareknaser yes, we must panic and not ignore the errors. But maybe simple unwrapping would be fine in test code?
|
||
let mut added_file_path = path.clone(); | ||
added_file_path.push(FILE_NAME_2); | ||
let _ = index_track_addition.track_addition(&added_file_path); |
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.
Here as well
Signed-off-by: Tarek <tareknaser360@gmail.com>
b3205f2
to
76b3389
Compare
The scope of this PR was split and reworked in new repo: |
Here are couple more tests.
update_one
was handling absent paths incorrectly, fixed here.Closing:
update_all
andupdate_one
are consistent #41